Skip to main content

Crate rustls_connector

Crate rustls_connector 

Source
Expand description

A TLS connector for rustls modelled after the openssl and native-tls APIs.

Wraps rustls with a high-level RustlsConnector type that mirrors the ergonomics of native_tls::TlsConnector, making it straightforward to swap TLS backends in existing code.

§Feature flags

§Certificate store (pick at least one)

FlagNotes
platform-verifier (default)Platform trust store via rustls-platform-verifier
native-certsNative root certificates via rustls-native-certs
webpki-root-certsBundled Mozilla root certificate set

§Rustls crypto provider (at least one must be enabled)

FlagNotes
rustls--aws_lc_rs (default)Uses aws-lc-rs
rustls--ringUses ring (more portable)

§Miscellaneous

FlagNotes
futuresAsync connect via futures-rustls
loggingEnable rustls TLS logging

§Example

use rustls_connector::RustlsConnector;

use std::{
    io::{Read, Write},
    net::TcpStream,
};

let connector = RustlsConnector::new_with_platform_verifier().unwrap();
let stream = TcpStream::connect("google.com:443").unwrap();
let mut stream = connector.connect("google.com", stream).unwrap();

stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
let mut res = vec![];
stream.read_to_end(&mut res).unwrap();
println!("{}", String::from_utf8_lossy(&res));

Re-exports§

pub use rustls;
pub use rustls_native_certs;
pub use rustls_pki_types;
pub use rustls_platform_verifier;
pub use webpki;
pub use webpki_root_certs;

Structs§

MidHandshakeTlsStream
A TLS stream which has been interrupted during the handshake
RustlsConnector
A rustls TLS connector ready to perform TLS handshakes.
RustlsConnectorConfig
Configuration helper for RustlsConnector

Enums§

HandshakeError
An error returned while performing the handshake

Type Aliases§

AsyncTlsStream
A rustls client TLS stream wrapping an underlying async I/O stream S.
TlsStream
A rustls client TLS stream wrapping an underlying synchronous I/O stream S.