diff --git a/src/connector/builder.rs b/src/connector/builder.rs index e0f06d0..76b0998 100644 --- a/src/connector/builder.rs +++ b/src/connector/builder.rs @@ -1,12 +1,13 @@ +#[cfg(feature = "tokio-runtime")] +use hyper::client::HttpConnector; +#[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))] +use rustls::crypto::CryptoProvider; use rustls::ClientConfig; use super::HttpsConnector; #[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))] use crate::config::ConfigBuilderExt; -#[cfg(feature = "tokio-runtime")] -use hyper::client::HttpConnector; - /// A builder for an [`HttpsConnector`] /// /// This makes configuration flexible and explicit and ensures connector @@ -57,8 +58,11 @@ impl ConnectorBuilder { /// See [`ConfigBuilderExt::with_native_roots`] /// /// [with_safe_defaults]: rustls::ConfigBuilder::with_safe_defaults - #[cfg(feature = "rustls-native-certs")] - #[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))] + #[cfg(all(feature = "ring", feature = "rustls-native-certs"))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "ring", feature = "rustls-native-certs"))) + )] pub fn with_native_roots(self) -> std::io::Result> { Ok(self.with_tls_config( ClientConfig::builder() @@ -68,14 +72,34 @@ impl ConnectorBuilder { )) } + /// Shorthand for using rustls' [safe defaults][with_safe_defaults] + /// with a custom [`CryptoProvider`] and native roots + /// + /// See [`ConfigBuilderExt::with_native_roots`] + /// + /// [with_safe_defaults]: rustls::ConfigBuilder::with_safe_defaults + #[cfg(feature = "rustls-native-certs")] + #[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))] + pub fn with_provider_and_native_roots( + self, + provider: &'static dyn CryptoProvider, + ) -> std::io::Result> { + Ok(self.with_tls_config( + ClientConfig::builder_with_provider(provider) + .with_safe_defaults() + .with_native_roots()? + .with_no_client_auth(), + )) + } + /// Shorthand for using rustls' [safe defaults][with_safe_defaults] /// and Mozilla roots /// /// See [`ConfigBuilderExt::with_webpki_roots`] /// /// [with_safe_defaults]: rustls::ConfigBuilder::with_safe_defaults - #[cfg(feature = "webpki-roots")] - #[cfg_attr(docsrs, doc(cfg(feature = "webpki-roots")))] + #[cfg(all(feature = "ring", feature = "webpki-roots"))] + #[cfg_attr(docsrs, doc(cfg(all(feature = "ring", feature = "webpki-roots"))))] pub fn with_webpki_roots(self) -> ConnectorBuilder { self.with_tls_config( ClientConfig::builder() @@ -84,6 +108,26 @@ impl ConnectorBuilder { .with_no_client_auth(), ) } + + /// Shorthand for using rustls' [safe defaults][with_safe_defaults] + /// with a custom [`CryptoProvider`] and Mozilla roots + /// + /// See [`ConfigBuilderExt::with_webpki_roots`] + /// + /// [with_safe_defaults]: rustls::ConfigBuilder::with_safe_defaults + #[cfg(feature = "webpki-roots")] + #[cfg_attr(docsrs, doc(cfg(feature = "webpki-roots")))] + pub fn with_provider_and_webpki_roots( + self, + provider: &'static dyn CryptoProvider, + ) -> ConnectorBuilder { + self.with_tls_config( + ClientConfig::builder_with_provider(provider) + .with_safe_defaults() + .with_webpki_roots() + .with_no_client_auth(), + ) + } } impl Default for ConnectorBuilder {