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)
| Flag | Notes |
|---|---|
platform-verifier (default) | Platform trust store via rustls-platform-verifier |
native-certs | Native root certificates via rustls-native-certs |
webpki-root-certs | Bundled Mozilla root certificate set |
§Rustls crypto provider (at least one must be enabled)
| Flag | Notes |
|---|---|
rustls--aws_lc_rs (default) | Uses aws-lc-rs |
rustls--ring | Uses ring (more portable) |
Enabling both providers (which cargo feature unification can do behind your
back) leaves rustls unable to pick one on its own. In that case install a
process-level default with
CryptoProvider::install_default
before building a connector, otherwise every constructor below panics.
§Miscellaneous
| Flag | Notes |
|---|---|
futures | Async connect via futures-rustls |
logging | Enable 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§
- MidHandshake
TlsStream - A TLS stream which has been interrupted during the handshake
- Rustls
Connector - A rustls TLS connector ready to perform TLS handshakes.
- Rustls
Connector Config - Configuration helper for
RustlsConnector
Enums§
- Handshake
Error - An error returned while performing the handshake
Type Aliases§
- Async
TlsStream - 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.