diff --git a/src/connector/builder.rs b/src/connector/builder.rs index b2858b9..2e47df8 100644 --- a/src/connector/builder.rs +++ b/src/connector/builder.rs @@ -1,7 +1,11 @@ use std::sync::Arc; use hyper_util::client::legacy::connect::HttpConnector; -#[cfg(any(feature = "rustls-native-certs", feature = "webpki-roots"))] +#[cfg(any( + feature = "rustls-native-certs", + feature = "rustls-platform-verifier", + feature = "webpki-roots" +))] use rustls::crypto::CryptoProvider; use rustls::ClientConfig; @@ -61,7 +65,8 @@ impl ConnectorBuilder { ConnectorBuilder(WantsSchemes { tls_config: config }) } - /// Use rustls' default crypto provider and other defaults, and the platform verifier + /// Shorthand for using rustls' default crypto provider and other defaults, and + /// the platform verifier. /// /// See [`ConfigBuilderExt::with_platform_verifier()`]. #[cfg(all( @@ -76,6 +81,23 @@ impl ConnectorBuilder { ) } + /// Shorthand for using a custom [`CryptoProvider`] and the platform verifier. + /// + /// See [`ConfigBuilderExt::with_platform_verifier()`]. + #[cfg(feature = "rustls-platform-verifier")] + pub fn with_provider_and_platform_verifier( + self, + provider: impl Into>, + ) -> std::io::Result> { + Ok(self.with_tls_config( + ClientConfig::builder_with_provider(provider.into()) + .with_safe_default_protocol_versions() + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))? + .with_platform_verifier() + .with_no_client_auth(), + )) + } + /// Shorthand for using rustls' default crypto provider and safe defaults, with /// native roots. /// @@ -98,7 +120,7 @@ impl ConnectorBuilder { #[cfg(feature = "rustls-native-certs")] pub fn with_provider_and_native_roots( self, - provider: CryptoProvider, + provider: impl Into>, ) -> std::io::Result> { Ok(self.with_tls_config( ClientConfig::builder_with_provider(provider.into()) @@ -129,7 +151,7 @@ impl ConnectorBuilder { #[cfg(feature = "webpki-roots")] pub fn with_provider_and_webpki_roots( self, - provider: CryptoProvider, + provider: impl Into>, ) -> Result, rustls::Error> { Ok(self.with_tls_config( ClientConfig::builder_with_provider(provider.into())