data TlsStream
A TLS session over a connected TCP socket. @must_close: end it with close() (use defer).
Example:
use std.net { TlsStream }
fn fetch() -> str | NetError io, net {
let s = TlsStream.connectHost("example.org", 443, timeout: 5s)?
defer s.close()?
s.writeText("GET / HTTP/1.0\r\nHost: example.org\r\n\r\n")?
s.readText(4096)?
}@must_close
pub(api) data TlsStreamThread safety. like `TcpStream`: one reading and one writing task at a time.
Since. 1.0.0-beta
Fields
pub(api) local: SocketAddr | Address of this end. |
pub(api) peer: SocketAddr | Address of the other end. |
Methods
connect | (addr: SocketAddr, cfg: TlsConfig, timeout: Duration?) -> TlsStream | NetError netConnects to addr and runs the client handshake. |
connectHost | (host: str, port: u16, cfg: TlsConfig, timeout: Duration?) -> TlsStream | NetError netResolves host (a name or numeric address), connects and runs the client handshake; cfg.serverName defaults to host. |
read | (max: usize, timeout: Duration?) -> bytes | NetError netUp to max bytes of application data. |
readText | (max: usize, timeout: Duration?) -> str | NetError netLike read, for UTF-8 text; bytes that are not valid UTF-8 give ProtocolError. |
write | (buf: bytes, timeout: Duration?) -> () | NetError netWrites all of data. |
writeText | (text: str, timeout: Duration?) -> () | NetError netWrites the UTF-8 bytes of text. |
shutdownWrite | (timeout: Duration?) -> () | NetError netSends close_notify (the peer reads end of stream) and keeps receiving. |
alpn | () -> strThe negotiated ALPN protocol ("h2", "http/1.1"), or "" when none was negotiated. |
version | () -> str"TLSv1.3" or "TLSv1.2". |
cipher | () -> strThe name of the negotiated cipher suite. |
peerSubject | () -> strRFC 2253 subject of the peer's leaf certificate ("" when it sent none, e.g. |
serverName | () -> strServer side: the server name the client asked for (SNI), "" if none. |
peerCertSha256 | () -> strLowercase hex SHA-256 of the peer's leaf certificate (DER), usable as TlsConfig.pin; "" without a certificate. |
setNoDelay | (on: bool) -> () | NetError netTurns TCP_NODELAY on or off for the underlying socket. |
close | () -> () | NetError netSends close_notify (one non-blocking attempt, it never waits or fails the cancelled task) and closes the socket. |
Defined in: std/net/tls.oxl:181