rustls/
lib.rs

1//! # Rustls - a modern TLS library
2//!
3//! Rustls is a TLS library that aims to provide a good level of cryptographic security,
4//! requires no configuration to achieve that security, and provides no unsafe features or
5//! obsolete cryptography by default.
6//!
7//! Rustls implements TLS1.2 and TLS1.3 for both clients and servers. See [the full
8//! list of protocol features](manual::_04_features).
9//!
10//! ### Platform support
11//!
12//! While Rustls itself is platform independent, by default it uses [`aws-lc-rs`] for implementing
13//! the cryptography in TLS.  See [the aws-lc-rs FAQ][aws-lc-rs-platforms-faq] for more details of the
14//! platform/architecture support constraints in aws-lc-rs.
15//!
16//! [`ring`] is also available via the `ring` crate feature: see
17//! [the supported `ring` target platforms][ring-target-platforms].
18//!
19//! By providing a custom instance of the [`crypto::CryptoProvider`] struct, you
20//! can replace all cryptography dependencies of rustls.  This is a route to being portable
21//! to a wider set of architectures and environments, or compliance requirements.  See the
22//! [`crypto::CryptoProvider`] documentation for more details.
23//!
24//! Specifying `default-features = false` when depending on rustls will remove the
25//! dependency on aws-lc-rs.
26//!
27//! Rustls requires Rust 1.63 or later. It has an optional dependency on zlib-rs which requires 1.75 or later.
28//!
29//! [ring-target-platforms]: https://github.com/briansmith/ring/blob/2e8363b433fa3b3962c877d9ed2e9145612f3160/include/ring-core/target.h#L18-L64
30//! [`crypto::CryptoProvider`]: crate::crypto::CryptoProvider
31//! [`ring`]: https://crates.io/crates/ring
32//! [aws-lc-rs-platforms-faq]: https://aws.github.io/aws-lc-rs/faq.html#can-i-run-aws-lc-rs-on-x-platform-or-architecture
33//! [`aws-lc-rs`]: https://crates.io/crates/aws-lc-rs
34//!
35//! ### Cryptography providers
36//!
37//! Since Rustls 0.22 it has been possible to choose the provider of the cryptographic primitives
38//! that Rustls uses. This may be appealing if you have specific platform, compliance or feature
39//! requirements that aren't met by the default provider, [`aws-lc-rs`].
40//!
41//! Users that wish to customize the provider in use can do so when constructing `ClientConfig`
42//! and `ServerConfig` instances using the `with_crypto_provider` method on the respective config
43//! builder types. See the [`crypto::CryptoProvider`] documentation for more details.
44//!
45//! #### Built-in providers
46//!
47//! Rustls ships with two built-in providers controlled with associated feature flags:
48//!
49//!   * [`aws-lc-rs`] - enabled by default, available with the `aws_lc_rs` feature flag enabled.
50//!   * [`ring`] - available with the `ring` feature flag enabled.
51//!
52//! See the documentation for [`crypto::CryptoProvider`] for details on how providers are
53//! selected.
54//!
55//! #### Third-party providers
56//!
57//! The community has also started developing third-party providers for Rustls:
58//!
59//!   * [`rustls-mbedtls-provider`] - a provider that uses [`mbedtls`] for cryptography.
60//!   * [`boring-rustls-provider`] - a work-in-progress provider that uses [`boringssl`] for
61//!     cryptography.
62//!   * [`rustls-rustcrypto`] - an experimental provider that uses the crypto primitives
63//!     from [`RustCrypto`] for cryptography.
64//!   * [`rustls-post-quantum`]: an experimental provider that adds support for post-quantum
65//!     key exchange to the default aws-lc-rs provider.
66//!   * [`rustls-wolfcrypt-provider`] - a work-in-progress provider that uses [`wolfCrypt`] for cryptography.
67//!
68//! [`rustls-mbedtls-provider`]: https://github.com/fortanix/rustls-mbedtls-provider
69//! [`mbedtls`]: https://github.com/Mbed-TLS/mbedtls
70//! [`boring-rustls-provider`]: https://github.com/janrueth/boring-rustls-provider
71//! [`boringssl`]: https://github.com/google/boringssl
72//! [`rustls-rustcrypto`]: https://github.com/RustCrypto/rustls-rustcrypto
73//! [`RustCrypto`]: https://github.com/RustCrypto
74//! [`rustls-post-quantum`]: https://crates.io/crates/rustls-post-quantum
75//! [`rustls-wolfcrypt-provider`]: https://github.com/wolfSSL/rustls-wolfcrypt-provider
76//! [`wolfCrypt`]: https://www.wolfssl.com/products/wolfcrypt
77//!
78//! #### Custom provider
79//!
80//! We also provide a simple example of writing your own provider in the [`custom-provider`]
81//! example. This example implements a minimal provider using parts of the [`RustCrypto`]
82//! ecosystem.
83//!
84//! See the [Making a custom CryptoProvider] section of the documentation for more information
85//! on this topic.
86//!
87//! [`custom-provider`]: https://github.com/rustls/rustls/tree/main/provider-example/
88//! [`RustCrypto`]: https://github.com/RustCrypto
89//! [Making a custom CryptoProvider]: https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#making-a-custom-cryptoprovider
90//!
91//! ## Design overview
92//!
93//! Rustls is a low-level library. If your goal is to make HTTPS connections you may prefer
94//! to use a library built on top of Rustls like [hyper] or [ureq].
95//!
96//! [hyper]: https://crates.io/crates/hyper
97//! [ureq]: https://crates.io/crates/ureq
98//!
99//! ### Rustls does not take care of network IO
100//! It doesn't make or accept TCP connections, or do DNS, or read or write files.
101//!
102//! Our [examples] directory contains demos that show how to handle I/O using the
103//! [`stream::Stream`] helper, as well as more complex asynchronous I/O using [`mio`].
104//! If you're already using Tokio for an async runtime you may prefer to use [`tokio-rustls`] instead
105//! of interacting with rustls directly.
106//!
107//! [examples]: https://github.com/rustls/rustls/tree/main/examples
108//! [`tokio-rustls`]: https://github.com/rustls/tokio-rustls
109//!
110//! ### Rustls provides encrypted pipes
111//! These are the [`ServerConnection`] and [`ClientConnection`] types.  You supply raw TLS traffic
112//! on the left (via the [`read_tls()`] and [`write_tls()`] methods) and then read/write the
113//! plaintext on the right:
114//!
115//! [`read_tls()`]: Connection::read_tls
116//! [`write_tls()`]: Connection::read_tls
117//!
118//! ```text
119//!          TLS                                   Plaintext
120//!          ===                                   =========
121//!     read_tls()      +-----------------------+      reader() as io::Read
122//!                     |                       |
123//!           +--------->   ClientConnection    +--------->
124//!                     |          or           |
125//!           <---------+   ServerConnection    <---------+
126//!                     |                       |
127//!     write_tls()     +-----------------------+      writer() as io::Write
128//! ```
129//!
130//! ### Rustls takes care of server certificate verification
131//! You do not need to provide anything other than a set of root certificates to trust.
132//! Certificate verification cannot be turned off or disabled in the main API.
133//!
134//! ## Getting started
135//! This is the minimum you need to do to make a TLS client connection.
136//!
137//! First we load some root certificates.  These are used to authenticate the server.
138//! The simplest way is to depend on the [`webpki_roots`] crate which contains
139//! the Mozilla set of root certificates.
140//!
141//! ```rust,no_run
142//! # #[cfg(feature = "aws-lc-rs")] {
143//! let root_store = rustls::RootCertStore::from_iter(
144//!     webpki_roots::TLS_SERVER_ROOTS
145//!         .iter()
146//!         .cloned(),
147//! );
148//! # }
149//! ```
150//!
151//! [`webpki_roots`]: https://crates.io/crates/webpki-roots
152//!
153//! Next, we make a `ClientConfig`.  You're likely to make one of these per process,
154//! and use it for all connections made by that process.
155//!
156//! ```rust,no_run
157//! # #[cfg(feature = "aws_lc_rs")] {
158//! # let root_store: rustls::RootCertStore = panic!();
159//! let config = rustls::ClientConfig::builder()
160//!     .with_root_certificates(root_store)
161//!     .with_no_client_auth();
162//! # }
163//! ```
164//!
165//! Now we can make a connection.  You need to provide the server's hostname so we
166//! know what to expect to find in the server's certificate.
167//!
168//! ```rust
169//! # #[cfg(feature = "aws_lc_rs")] {
170//! # use rustls;
171//! # use webpki;
172//! # use std::sync::Arc;
173//! # rustls::crypto::aws_lc_rs::default_provider().install_default();
174//! # let root_store = rustls::RootCertStore::from_iter(
175//! #  webpki_roots::TLS_SERVER_ROOTS
176//! #      .iter()
177//! #      .cloned(),
178//! # );
179//! # let config = rustls::ClientConfig::builder()
180//! #     .with_root_certificates(root_store)
181//! #     .with_no_client_auth();
182//! let rc_config = Arc::new(config);
183//! let example_com = "example.com".try_into().unwrap();
184//! let mut client = rustls::ClientConnection::new(rc_config, example_com);
185//! # }
186//! ```
187//!
188//! Now you should do appropriate IO for the `client` object.  If `client.wants_read()` yields
189//! true, you should call `client.read_tls()` when the underlying connection has data.
190//! Likewise, if `client.wants_write()` yields true, you should call `client.write_tls()`
191//! when the underlying connection is able to send data.  You should continue doing this
192//! as long as the connection is valid.
193//!
194//! The return types of `read_tls()` and `write_tls()` only tell you if the IO worked.  No
195//! parsing or processing of the TLS messages is done.  After each `read_tls()` you should
196//! therefore call `client.process_new_packets()` which parses and processes the messages.
197//! Any error returned from `process_new_packets` is fatal to the connection, and will tell you
198//! why.  For example, if the server's certificate is expired `process_new_packets` will
199//! return `Err(InvalidCertificate(Expired))`.  From this point on,
200//! `process_new_packets` will not do any new work and will return that error continually.
201//!
202//! You can extract newly received data by calling `client.reader()` (which implements the
203//! `io::Read` trait).  You can send data to the peer by calling `client.writer()` (which
204//! implements `io::Write` trait).  Note that `client.writer().write()` buffers data you
205//! send if the TLS connection is not yet established: this is useful for writing (say) a
206//! HTTP request, but this is buffered so avoid large amounts of data.
207//!
208//! The following code uses a fictional socket IO API for illustration, and does not handle
209//! errors.
210//!
211//! ```rust,no_run
212//! # #[cfg(feature = "aws_lc_rs")] {
213//! # let mut client = rustls::ClientConnection::new(panic!(), panic!()).unwrap();
214//! # struct Socket { }
215//! # impl Socket {
216//! #   fn ready_for_write(&self) -> bool { false }
217//! #   fn ready_for_read(&self) -> bool { false }
218//! #   fn wait_for_something_to_happen(&self) { }
219//! # }
220//! #
221//! # use std::io::{Read, Write, Result};
222//! # impl Read for Socket {
223//! #   fn read(&mut self, buf: &mut [u8]) -> Result<usize> { panic!() }
224//! # }
225//! # impl Write for Socket {
226//! #   fn write(&mut self, buf: &[u8]) -> Result<usize> { panic!() }
227//! #   fn flush(&mut self) -> Result<()> { panic!() }
228//! # }
229//! #
230//! # fn connect(_address: &str, _port: u16) -> Socket {
231//! #   panic!();
232//! # }
233//! use std::io;
234//! use rustls::Connection;
235//!
236//! client.writer().write(b"GET / HTTP/1.0\r\n\r\n").unwrap();
237//! let mut socket = connect("example.com", 443);
238//! loop {
239//!   if client.wants_read() && socket.ready_for_read() {
240//!     client.read_tls(&mut socket).unwrap();
241//!     client.process_new_packets().unwrap();
242//!
243//!     let mut plaintext = Vec::new();
244//!     client.reader().read_to_end(&mut plaintext).unwrap();
245//!     io::stdout().write(&plaintext).unwrap();
246//!   }
247//!
248//!   if client.wants_write() && socket.ready_for_write() {
249//!     client.write_tls(&mut socket).unwrap();
250//!   }
251//!
252//!   socket.wait_for_something_to_happen();
253//! }
254//! # }
255//! ```
256//!
257//! # Examples
258//!
259//! You can find several client and server examples of varying complexity in the [examples]
260//! directory, including [`tlsserver-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsserver-mio.rs)
261//! and [`tlsclient-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsclient-mio.rs)
262//! \- full worked examples using [`mio`].
263//!
264//! [`mio`]: https://docs.rs/mio/latest/mio/
265//!
266//! # Crate features
267//! Here's a list of what features are exposed by the rustls crate and what
268//! they mean.
269//!
270//! - `aws_lc_rs` (enabled by default): makes the rustls crate depend on the [`aws-lc-rs`] crate.
271//!   Use `rustls::crypto::aws_lc_rs::default_provider().install_default()` to
272//!   use it as the default `CryptoProvider`, or provide it explicitly
273//!   when making a `ClientConfig` or `ServerConfig`.
274//!
275//!   Note that aws-lc-rs has additional build-time dependencies like cmake.
276//!   See [the documentation](https://aws.github.io/aws-lc-rs/requirements/index.html) for details.
277//!
278//! - `ring`: makes the rustls crate depend on the *ring* crate for cryptography.
279//!   Use `rustls::crypto::ring::default_provider().install_default()` to
280//!   use it as the default `CryptoProvider`, or provide it explicitly
281//!   when making a `ClientConfig` or `ServerConfig`.
282//!
283//! - `fips`: enable support for FIPS140-3-approved cryptography, via the aws-lc-rs crate.
284//!   This feature enables the `aws_lc_rs` feature, which makes the rustls crate depend
285//!   on [aws-lc-rs](https://github.com/aws/aws-lc-rs).  It also changes the default
286//!   for [`ServerConfig::require_ems`] and [`ClientConfig::require_ems`].
287//!
288//!   See [manual::_06_fips] for more details.
289//!
290//! - `custom-provider`: disables implicit use of built-in providers (`aws-lc-rs` or `ring`). This forces
291//!    applications to manually install one, for instance, when using a custom `CryptoProvider`.
292//!
293//! - `tls12` (enabled by default): enable support for TLS version 1.2. Note that, due to the
294//!   additive nature of Cargo features and because it is enabled by default, other crates
295//!   in your dependency graph could re-enable it for your application. If you want to disable
296//!   TLS 1.2 for security reasons, consider explicitly enabling TLS 1.3 only in the config
297//!   builder API.
298//!
299//! - `logging` (enabled by default): make the rustls crate depend on the `log` crate.
300//!   rustls outputs interesting protocol-level messages at `trace!` and `debug!` level,
301//!   and protocol-level errors at `warn!` and `error!` level.  The log messages do not
302//!   contain secret key data, and so are safe to archive without affecting session security.
303//!
304//! - `read_buf`: when building with Rust Nightly, adds support for the unstable
305//!   `std::io::ReadBuf` and related APIs. This reduces costs from initializing
306//!   buffers. Will do nothing on non-Nightly releases.
307//!
308//! - `brotli`: uses the `brotli` crate for RFC8879 certificate compression support.
309//!
310//! - `zlib`: uses the `zlib-rs` crate for RFC8879 certificate compression support.
311//!
312
313// Require docs for public APIs, deny unsafe code, etc.
314#![forbid(unsafe_code, unused_must_use)]
315#![cfg_attr(not(any(read_buf, bench)), forbid(unstable_features))]
316#![warn(
317    clippy::alloc_instead_of_core,
318    clippy::clone_on_ref_ptr,
319    clippy::std_instead_of_core,
320    clippy::use_self,
321    clippy::upper_case_acronyms,
322    elided_lifetimes_in_paths,
323    missing_docs,
324    trivial_casts,
325    trivial_numeric_casts,
326    unreachable_pub,
327    unused_import_braces,
328    unused_extern_crates,
329    unused_qualifications
330)]
331// Relax these clippy lints:
332// - ptr_arg: this triggers on references to type aliases that are Vec
333//   underneath.
334// - too_many_arguments: some things just need a lot of state, wrapping it
335//   doesn't necessarily make it easier to follow what's going on
336// - new_ret_no_self: we sometimes return `Arc<Self>`, which seems fine
337// - single_component_path_imports: our top-level `use log` import causes
338//   a false positive, https://github.com/rust-lang/rust-clippy/issues/5210
339// - new_without_default: for internal constructors, the indirection is not
340//   helpful
341#![allow(
342    clippy::too_many_arguments,
343    clippy::new_ret_no_self,
344    clippy::ptr_arg,
345    clippy::single_component_path_imports,
346    clippy::new_without_default
347)]
348// Enable documentation for all features on docs.rs
349#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
350// XXX: Because of https://github.com/rust-lang/rust/issues/54726, we cannot
351// write `#![rustversion::attr(nightly, feature(read_buf))]` here. Instead,
352// build.rs set `read_buf` for (only) Rust Nightly to get the same effect.
353//
354// All the other conditional logic in the crate could use
355// `#[rustversion::nightly]` instead of `#[cfg(read_buf)]`; `#[cfg(read_buf)]`
356// is used to avoid needing `rustversion` to be compiled twice during
357// cross-compiling.
358#![cfg_attr(read_buf, feature(read_buf))]
359#![cfg_attr(read_buf, feature(core_io_borrowed_buf))]
360#![cfg_attr(bench, feature(test))]
361#![no_std]
362
363extern crate alloc;
364// This `extern crate` plus the `#![no_std]` attribute changes the default prelude from
365// `std::prelude` to `core::prelude`. That forces one to _explicitly_ import (`use`) everything that
366// is in `std::prelude` but not in `core::prelude`. This helps maintain no-std support as even
367// developers that are not interested in, or aware of, no-std support and / or that never run
368// `cargo build --no-default-features` locally will get errors when they rely on `std::prelude` API.
369#[cfg(any(feature = "std", test))]
370extern crate std;
371
372#[cfg(doc)]
373use crate::crypto::CryptoProvider;
374
375// Import `test` sysroot crate for `Bencher` definitions.
376#[cfg(bench)]
377#[allow(unused_extern_crates)]
378extern crate test;
379
380// log for logging (optional).
381#[cfg(feature = "logging")]
382use log;
383
384#[cfg(not(feature = "logging"))]
385mod log {
386    macro_rules! trace    ( ($($tt:tt)*) => {{}} );
387    macro_rules! debug    ( ($($tt:tt)*) => {{}} );
388    macro_rules! error    ( ($($tt:tt)*) => {{}} );
389    macro_rules! _warn    ( ($($tt:tt)*) => {{}} );
390    pub(crate) use {_warn as warn, debug, error, trace};
391}
392
393#[macro_use]
394mod test_macros;
395
396#[macro_use]
397mod msgs;
398mod common_state;
399pub mod compress;
400mod conn;
401/// Crypto provider interface.
402pub mod crypto;
403mod error;
404mod hash_hs;
405#[cfg(any(feature = "std", feature = "hashbrown"))]
406mod limited_cache;
407mod rand;
408mod record_layer;
409#[cfg(feature = "std")]
410mod stream;
411#[cfg(feature = "tls12")]
412mod tls12;
413mod tls13;
414mod vecbuf;
415mod verify;
416#[cfg(test)]
417mod verifybench;
418mod x509;
419#[macro_use]
420mod check;
421#[cfg(feature = "logging")]
422mod bs_debug;
423mod builder;
424mod enums;
425mod key_log;
426#[cfg(feature = "std")]
427mod key_log_file;
428mod suites;
429mod versions;
430mod webpki;
431
432/// Internal classes that are used in integration tests.
433/// The contents of this section DO NOT form part of the stable interface.
434#[allow(missing_docs)]
435#[doc(hidden)]
436pub mod internal {
437    /// Low-level TLS message parsing and encoding functions.
438    pub mod msgs {
439        pub mod base {
440            pub use crate::msgs::base::{Payload, PayloadU16};
441        }
442        pub mod codec {
443            pub use crate::msgs::codec::{Codec, Reader};
444        }
445        pub mod enums {
446            pub use crate::msgs::enums::{
447                AlertLevel, Compression, EchVersion, HpkeAead, HpkeKdf, HpkeKem, NamedGroup,
448            };
449        }
450        pub mod fragmenter {
451            pub use crate::msgs::fragmenter::MessageFragmenter;
452        }
453        pub mod handshake {
454            pub use crate::msgs::handshake::{
455                CertificateChain, ClientExtension, ClientHelloPayload, DistinguishedName,
456                EchConfigContents, EchConfigPayload, HandshakeMessagePayload, HandshakePayload,
457                HpkeKeyConfig, HpkeSymmetricCipherSuite, KeyShareEntry, Random, ServerName,
458                SessionId,
459            };
460        }
461        pub mod message {
462            pub use crate::msgs::message::{
463                Message, MessagePayload, OutboundOpaqueMessage, PlainMessage,
464            };
465        }
466        pub mod persist {
467            pub use crate::msgs::persist::ServerSessionValue;
468        }
469    }
470
471    pub mod fuzzing {
472        pub use crate::msgs::deframer::fuzz_deframer;
473    }
474}
475
476/// Unbuffered connection API
477///
478/// This is an alternative to the [`crate::ConnectionCommon`] API that does not internally buffer
479/// TLS nor plaintext data. Instead those buffers are managed by the API user so they have
480/// control over when and how to allocate, resize and dispose of them.
481///
482/// This API is lower level than the `ConnectionCommon` API and is built around a state machine
483/// interface where the API user must handle each state to advance and complete the
484/// handshake process.
485///
486/// Like the `ConnectionCommon` API, no IO happens internally so all IO must be handled by the API
487/// user. Unlike the `ConnectionCommon` API, this API does not make use of the [`std::io::Read`] and
488/// [`std::io::Write`] traits so it's usable in no-std context.
489///
490/// The entry points into this API are [`crate::client::UnbufferedClientConnection::new`],
491/// [`crate::server::UnbufferedServerConnection::new`] and
492/// [`unbuffered::UnbufferedConnectionCommon::process_tls_records`]. The state machine API is
493/// documented in [`unbuffered::ConnectionState`].
494///
495/// # Examples
496///
497/// [`unbuffered-client`] and [`unbuffered-server`] are examples that fully exercise the API in
498/// std, non-async context.
499///
500/// [`unbuffered-client`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffererd-client.rs
501/// [`unbuffered-server`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffererd-server.rs
502pub mod unbuffered {
503    pub use crate::conn::unbuffered::{
504        AppDataRecord, ConnectionState, EncodeError, EncodeTlsData, EncryptError,
505        InsufficientSizeError, ReadEarlyData, ReadTraffic, TransmitTlsData, UnbufferedStatus,
506        WriteTraffic,
507    };
508    pub use crate::conn::UnbufferedConnectionCommon;
509}
510
511// The public interface is:
512pub use crate::builder::{ConfigBuilder, ConfigSide, WantsVerifier, WantsVersions};
513pub use crate::common_state::{CommonState, HandshakeKind, IoState, Side};
514#[cfg(feature = "std")]
515pub use crate::conn::{Connection, Reader, Writer};
516pub use crate::conn::{ConnectionCommon, SideData};
517pub use crate::enums::{
518    AlertDescription, CertificateCompressionAlgorithm, CipherSuite, ContentType, HandshakeType,
519    ProtocolVersion, SignatureAlgorithm, SignatureScheme,
520};
521pub use crate::error::{
522    CertRevocationListError, CertificateError, EncryptedClientHelloError, Error, InconsistentKeys,
523    InvalidMessage, OtherError, PeerIncompatible, PeerMisbehaved,
524};
525pub use crate::key_log::{KeyLog, NoKeyLog};
526#[cfg(feature = "std")]
527pub use crate::key_log_file::KeyLogFile;
528pub use crate::msgs::enums::NamedGroup;
529pub use crate::msgs::ffdhe_groups;
530pub use crate::msgs::handshake::DistinguishedName;
531#[cfg(feature = "std")]
532pub use crate::stream::{Stream, StreamOwned};
533pub use crate::suites::{
534    CipherSuiteCommon, ConnectionTrafficSecrets, ExtractedSecrets, SupportedCipherSuite,
535};
536#[cfg(any(feature = "std", feature = "hashbrown"))]
537pub use crate::ticketer::TicketSwitcher;
538#[cfg(feature = "tls12")]
539pub use crate::tls12::Tls12CipherSuite;
540pub use crate::tls13::Tls13CipherSuite;
541pub use crate::verify::DigitallySignedStruct;
542pub use crate::versions::{SupportedProtocolVersion, ALL_VERSIONS, DEFAULT_VERSIONS};
543pub use crate::webpki::RootCertStore;
544
545/// Items for use in a client.
546pub mod client {
547    pub(super) mod builder;
548    mod client_conn;
549    mod common;
550    mod ech;
551    pub(super) mod handy;
552    mod hs;
553    #[cfg(feature = "tls12")]
554    mod tls12;
555    mod tls13;
556
557    pub use builder::WantsClientCert;
558    pub use client_conn::{
559        ClientConfig, ClientConnectionData, ClientSessionStore, EarlyDataError, ResolvesClientCert,
560        Resumption, Tls12Resumption, UnbufferedClientConnection,
561    };
562    #[cfg(feature = "std")]
563    pub use client_conn::{ClientConnection, WriteEarlyData};
564    pub use ech::{EchConfig, EchGreaseConfig, EchMode, EchStatus};
565    #[cfg(any(feature = "std", feature = "hashbrown"))]
566    pub use handy::ClientSessionMemoryCache;
567
568    /// Dangerous configuration that should be audited and used with extreme care.
569    pub mod danger {
570        pub use super::builder::danger::DangerousClientConfigBuilder;
571        pub use super::client_conn::danger::DangerousClientConfig;
572        pub use crate::verify::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
573    }
574
575    pub use crate::msgs::persist::{Tls12ClientSessionValue, Tls13ClientSessionValue};
576    pub use crate::webpki::{
577        verify_server_cert_signed_by_trust_anchor, verify_server_name, ServerCertVerifierBuilder,
578        VerifierBuilderError, WebPkiServerVerifier,
579    };
580}
581
582pub use client::ClientConfig;
583#[cfg(feature = "std")]
584pub use client::ClientConnection;
585
586/// Items for use in a server.
587pub mod server {
588    pub(crate) mod builder;
589    mod common;
590    pub(crate) mod handy;
591    mod hs;
592    mod server_conn;
593    #[cfg(feature = "tls12")]
594    mod tls12;
595    mod tls13;
596
597    pub use builder::WantsServerCert;
598    pub use handy::NoServerSessionStorage;
599    #[cfg(any(feature = "std", feature = "hashbrown"))]
600    pub use handy::ResolvesServerCertUsingSni;
601    #[cfg(any(feature = "std", feature = "hashbrown"))]
602    pub use handy::ServerSessionMemoryCache;
603    pub use server_conn::{
604        Accepted, ClientHello, ProducesTickets, ResolvesServerCert, ServerConfig,
605        ServerConnectionData, StoresServerSessions, UnbufferedServerConnection,
606    };
607    #[cfg(feature = "std")]
608    pub use server_conn::{AcceptedAlert, Acceptor, ReadEarlyData, ServerConnection};
609
610    pub use crate::verify::NoClientAuth;
611    pub use crate::webpki::{
612        ClientCertVerifierBuilder, ParsedCertificate, VerifierBuilderError, WebPkiClientVerifier,
613    };
614
615    /// Dangerous configuration that should be audited and used with extreme care.
616    pub mod danger {
617        pub use crate::verify::{ClientCertVerified, ClientCertVerifier};
618    }
619}
620
621pub use server::ServerConfig;
622#[cfg(feature = "std")]
623pub use server::ServerConnection;
624
625/// All defined protocol versions appear in this module.
626///
627/// ALL_VERSIONS is a provided as an array of all of these values.
628pub mod version {
629    #[cfg(feature = "tls12")]
630    pub use crate::versions::TLS12;
631    pub use crate::versions::TLS13;
632}
633
634/// Re-exports the contents of the [rustls-pki-types](https://docs.rs/rustls-pki-types) crate for easy access
635pub mod pki_types {
636    pub use pki_types::*;
637}
638
639/// Message signing interfaces.
640pub mod sign {
641    pub use crate::crypto::signer::{CertifiedKey, Signer, SigningKey};
642}
643
644/// APIs for implementing QUIC TLS
645pub mod quic;
646
647#[cfg(any(feature = "std", feature = "hashbrown"))]
648/// APIs for implementing TLS tickets
649pub mod ticketer;
650
651/// This is the rustls manual.
652pub mod manual;
653
654pub mod time_provider;
655
656/// APIs abstracting over locking primitives.
657pub mod lock;
658
659/// Polyfills for features that are not yet stabilized or available with current MSRV.
660pub(crate) mod polyfill;
661
662#[cfg(any(feature = "std", feature = "hashbrown"))]
663mod hash_map {
664    #[cfg(feature = "std")]
665    pub(crate) use std::collections::hash_map::Entry;
666    #[cfg(feature = "std")]
667    pub(crate) use std::collections::HashMap;
668
669    #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
670    pub(crate) use hashbrown::hash_map::Entry;
671    #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
672    pub(crate) use hashbrown::HashMap;
673}