std::net::tlsTLS client connections.
Provides encrypted TCP connections using TLS with system root certificates. Suitable for HTTPS clients, secure API calls, and any protocol that runs over TLS.
import std::net::tls;
fn main() {
let stream = tls.connect("example.com", 443);
let request = "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
match tls.try_write(stream, hew_string_to_bytes(request)) {
Ok(_) => {},
Err(err) => panic(fs.io_error_message(err)),
}
let response = match tls.read(stream, 4096) {
Ok(data) => data,
Err(err) => panic(fs.io_error_message(err)),
};
tls.close(stream);
}
connectOpen a TLS connection to a remote host.
Uses system root certificates to verify the server. Returns a
TlsStream on success or a zero-value on failure.
let stream = tls.connect("example.com", 443);
last_errorReturn the last TLS client error observed on this thread.
Failed connect() calls update this string. Successful connects clear it.
writeWrite raw bytes to a TLS stream.
Returns the number of bytes written, or −1 on error.
try_writeWrite raw bytes to a TLS stream.
Returns the number of bytes written, or Err(fs.IoError) on failure.
readRead up to size bytes from a TLS stream.
Returns Ok(bytes) on success or orderly EOF, or Err(fs.IoError) on
retryable/TLS/I-O failures. Call last_error() for the precise detail.
TlsStreamAn established TLS connection to a remote host.
Created by tls.connect(host, port). Must be released with close().
TlsStreamMethodsMethods available on a TlsStream.
Write raw bytes to the TLS stream.
Returns the number of bytes written, or −1 on error.
Write raw bytes to the TLS stream.
Returns the number of bytes written, or Err(fs.IoError) on failure.
Read up to size bytes from the TLS stream.
Returns Ok(bytes) on success or orderly EOF, or Err(fs.IoError) on
retryable/TLS/I-O failures. Use last_error() for the precise class.
Close the TLS connection and release resources.