Skip to content

Commit

Permalink
Add ConnectorBuilder::with_provider_and_platform_verifier
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
  • Loading branch information
Gelbpunkt authored and djc committed Aug 29, 2024
1 parent d07f3f5 commit b4f5132
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/connector/builder.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -61,7 +65,8 @@ impl ConnectorBuilder<WantsTlsConfig> {
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(
Expand All @@ -76,6 +81,23 @@ impl ConnectorBuilder<WantsTlsConfig> {
)
}

/// 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: CryptoProvider,
) -> std::io::Result<ConnectorBuilder<WantsSchemes>> {
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.
///
Expand Down

0 comments on commit b4f5132

Please sign in to comment.