Skip to content

Commit

Permalink
Update/improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Dec 13, 2021
1 parent f5b6e5b commit 59da0ca
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
//! rustls-native-certs allows rustls to use the platform's native certificate
//! store when operating as a TLS client.
//!
//! It provides the following functions:
//! * A higher level function [load_native_certs](fn.build_native_certs.html)
//! which returns a `rustls::RootCertStore` pre-filled from the native
//! certificate store. It is only available if the `rustls` feature is
//! enabled.
//! * A lower level function [build_native_certs](fn.build_native_certs.html)
//! that lets callers pass their own certificate parsing logic. It is
//! available to all users.
//! It provides a single function [`load_native_certs()`], which returns a
//! collection of certificates found by reading the platform-native
//! certificate store. [`Certificate`] here is just a marker newtype
//! that denotes a DER-encoded X.509 certificate encoded as a `Vec<u8>`.
//!
//! If you want to load these certificates into a `rustls::RootCertStore`,
//! you'll likely want to do something like this:
//!
//! ```no_run
//! let mut roots = rustls::RootCertStore::empty();
//! for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") {
//! roots
//! .add(&rustls::Certificate(cert.0))
//! .unwrap();
//! }
//! ```
#[cfg(all(unix, not(target_os = "macos")))]
mod unix;
Expand Down Expand Up @@ -43,6 +51,7 @@ pub fn load_native_certs() -> Result<Vec<Certificate>, Error> {
load_certs_from_env().unwrap_or_else(platform::load_native_certs)
}

/// A newtype representing a single DER-encoded X.509 certificate encoded as a `Vec<u8>`.
pub struct Certificate(pub Vec<u8>);

const ENV_CERT_FILE: &str = "SSL_CERT_FILE";
Expand Down

0 comments on commit 59da0ca

Please sign in to comment.