OxL Справочник OxL
РусскийEnglish

data TlsStream

A TLS session over a connected TCP socket. @must_close: end it with close() (use defer).

Example:

oxl✓ проверяется в CI
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 TlsStream

Потокобезопасность. like `TcpStream`: one reading and one writing task at a time.

С версии. 1.0.0-beta

Поля

pub(api) local: SocketAddr

Address of this end.

pub(api) peer: SocketAddr

Address of the other end.

Методы

connect(addr: SocketAddr, cfg: TlsConfig, timeout: Duration?) -> TlsStream | NetError net
Connects to addr and runs the client handshake.
connectHost(host: str, port: u16, cfg: TlsConfig, timeout: Duration?) -> TlsStream | NetError net
Resolves host (a name or numeric address), connects and runs the client handshake; cfg.serverName defaults to host.
read(max: usize, timeout: Duration?) -> bytes | NetError net
Up to max bytes of application data.
readText(max: usize, timeout: Duration?) -> str | NetError net
Like read, for UTF-8 text; bytes that are not valid UTF-8 give ProtocolError.
write(buf: bytes, timeout: Duration?) -> () | NetError net
Writes all of data.
writeText(text: str, timeout: Duration?) -> () | NetError net
Writes the UTF-8 bytes of text.
shutdownWrite(timeout: Duration?) -> () | NetError net
Sends close_notify (the peer reads end of stream) and keeps receiving.
alpn() -> str
The negotiated ALPN protocol ("h2", "http/1.1"), or "" when none was negotiated.
version() -> str
"TLSv1.3" or "TLSv1.2".
cipher() -> str
The name of the negotiated cipher suite.
peerSubject() -> str
RFC 2253 subject of the peer's leaf certificate ("" when it sent none, e.g.
serverName() -> str
Server side: the server name the client asked for (SNI), "" if none.
peerCertSha256() -> str
Lowercase hex SHA-256 of the peer's leaf certificate (DER), usable as TlsConfig.pin; "" without a certificate.
setNoDelay(on: bool) -> () | NetError net
Turns TCP_NODELAY on or off for the underlying socket.
close() -> () | NetError net
Sends close_notify (one non-blocking attempt, it never waits or fails the cancelled task) and closes the socket.

Определено в: std/net/tls.oxl:181

См. также