| author | |
| committer | |
| log | 8d86194b6e31788263d2cbdd03e2a8cde4134c37 |
| tree | 87c0066328b68b1bf597c95063d0dda544cc2dd9 |
| parent | afb26f4e6b39431001eff75cc8ce19144cb5301a |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 80 insertions(+), 4 deletions(-)
lib/std/crypto/tls/Client.zig+49-1| ... | ... | @@ -88,11 +88,59 @@ pub const StreamInterface = struct { |
| 88 | 88 | } |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | pub fn InitError(comptime Stream: type) type { | |
| 92 | return std.mem.Allocator.Error || Stream.WriteError || Stream.ReadError || error { | |
| 93 | InsufficientEntropy, | |
| 94 | DiskQuota, | |
| 95 | LockViolation, | |
| 96 | NotOpenForWriting, | |
| 97 | TlsAlert, | |
| 98 | TlsUnexpectedMessage, | |
| 99 | TlsIllegalParameter, | |
| 100 | TlsDecryptFailure, | |
| 101 | TlsRecordOverflow, | |
| 102 | TlsBadRecordMac, | |
| 103 | CertificateFieldHasInvalidLength, | |
| 104 | CertificateHostMismatch, | |
| 105 | CertificatePublicKeyInvalid, | |
| 106 | CertificateExpired, | |
| 107 | CertificateFieldHasWrongDataType, | |
| 108 | CertificateIssuerMismatch, | |
| 109 | CertificateNotYetValid, | |
| 110 | CertificateSignatureAlgorithmMismatch, | |
| 111 | CertificateSignatureAlgorithmUnsupported, | |
| 112 | CertificateSignatureInvalid, | |
| 113 | CertificateSignatureInvalidLength, | |
| 114 | CertificateSignatureNamedCurveUnsupported, | |
| 115 | CertificateSignatureUnsupportedBitCount, | |
| 116 | TlsCertificateNotVerified, | |
| 117 | TlsBadSignatureScheme, | |
| 118 | TlsBadRsaSignatureBitCount, | |
| 119 | InvalidEncoding, | |
| 120 | IdentityElement, | |
| 121 | SignatureVerificationFailed, | |
| 122 | TlsDecryptError, | |
| 123 | TlsConnectionTruncated, | |
| 124 | TlsDecodeError, | |
| 125 | UnsupportedCertificateVersion, | |
| 126 | CertificateTimeInvalid, | |
| 127 | CertificateHasUnrecognizedObjectId, | |
| 128 | CertificateHasInvalidBitString, | |
| 129 | MessageTooLong, | |
| 130 | NegativeIntoUnsigned, | |
| 131 | TargetTooSmall, | |
| 132 | BufferTooSmall, | |
| 133 | InvalidSignature, | |
| 134 | NotSquare, | |
| 135 | NonCanonical, | |
| 136 | }; | |
| 137 | } | |
| 138 | ||
| 91 | 139 | /// Initiates a TLS handshake and establishes a TLSv1.3 session with `stream`, which |
| 92 | 140 | /// must conform to `StreamInterface`. |
| 93 | 141 | /// |
| 94 | 142 | /// `host` is only borrowed during this function call. |
| 95 | pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) !Client { | |
| 143 | pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) InitError(@TypeOf(stream))!Client { | |
| 96 | 144 | const host_len = @intCast(u16, host.len); |
| 97 | 145 | |
| 98 | 146 | var random_buffer: [128]u8 = undefined; |
lib/std/net.zig+31-3| ... | ... | @@ -702,8 +702,10 @@ pub const AddressList = struct { |
| 702 | 702 | } |
| 703 | 703 | }; |
| 704 | 704 | |
| 705 | pub const TcpConnectToHostError = GetAddressListError || TcpConnectToAddressError; | |
| 706 | ||
| 705 | 707 | /// All memory allocated with `allocator` will be freed before this function returns. |
| 706 | pub fn tcpConnectToHost(allocator: mem.Allocator, name: []const u8, port: u16) !Stream { | |
| 708 | pub fn tcpConnectToHost(allocator: mem.Allocator, name: []const u8, port: u16) TcpConnectToHostError!Stream { | |
| 707 | 709 | const list = try getAddressList(allocator, name, port); |
| 708 | 710 | defer list.deinit(); |
| 709 | 711 | |
| ... | ... | @@ -720,7 +722,9 @@ pub fn tcpConnectToHost(allocator: mem.Allocator, name: []const u8, port: u16) ! |
| 720 | 722 | return std.os.ConnectError.ConnectionRefused; |
| 721 | 723 | } |
| 722 | 724 | |
| 723 | pub fn tcpConnectToAddress(address: Address) !Stream { | |
| 725 | pub const TcpConnectToAddressError = std.os.SocketError || std.os.ConnectError; | |
| 726 | ||
| 727 | pub fn tcpConnectToAddress(address: Address) TcpConnectToAddressError!Stream { | |
| 724 | 728 | const nonblock = if (std.io.is_async) os.SOCK.NONBLOCK else 0; |
| 725 | 729 | const sock_flags = os.SOCK.STREAM | nonblock | |
| 726 | 730 | (if (builtin.target.os.tag == .windows) 0 else os.SOCK.CLOEXEC); |
| ... | ... | @@ -737,8 +741,32 @@ pub fn tcpConnectToAddress(address: Address) !Stream { |
| 737 | 741 | return Stream{ .handle = sockfd }; |
| 738 | 742 | } |
| 739 | 743 | |
| 744 | const GetAddressListError = std.mem.Allocator.Error || std.fs.File.OpenError || std.fs.File.ReadError || std.os.SocketError || std.os.BindError || error { | |
| 745 | // TODO: break this up into error sets from the various underlying functions | |
| 746 | ||
| 747 | TemporaryNameServerFailure, | |
| 748 | NameServerFailure, | |
| 749 | AddressFamilyNotSupported, | |
| 750 | UnknownHostName, | |
| 751 | ServiceUnavailable, | |
| 752 | Unexpected, | |
| 753 | ||
| 754 | HostLacksNetworkAddresses, | |
| 755 | ||
| 756 | InvalidCharacter, | |
| 757 | InvalidEnd, | |
| 758 | NonCanonical, | |
| 759 | Overflow, | |
| 760 | Incomplete, | |
| 761 | InvalidIpv4Mapping, | |
| 762 | InvalidIPAddressFormat, | |
| 763 | ||
| 764 | InterfaceNotFound, | |
| 765 | FileSystem, | |
| 766 | }; | |
| 767 | ||
| 740 | 768 | /// Call `AddressList.deinit` on the result. |
| 741 | pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) !*AddressList { | |
| 769 | pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) GetAddressListError!*AddressList { | |
| 742 | 770 | const result = blk: { |
| 743 | 771 | var arena = std.heap.ArenaAllocator.init(allocator); |
| 744 | 772 | errdefer arena.deinit(); |