Skip to content

Commit 3304d87

Browse files
committed
feat: add rustls_platform_verifier::tls_config_with_provider
1 parent 4063a23 commit 3304d87

File tree

1 file changed

+18
-0
lines changed
  • rustls-platform-verifier/src

1 file changed

+18
-0
lines changed

rustls-platform-verifier/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ pub fn tls_config() -> ClientConfig {
6565
.with_no_client_auth()
6666
}
6767

68+
/// Attempts to construct a `rustls` configuration that verifies TLS certificates in the best way
69+
/// for the underlying OS platform, using the provided
70+
/// [`CryptoProvider`][rustls:crypto::CryptoProvider].
71+
///
72+
/// # Errors
73+
///
74+
/// Propagates any error returned by [`rustls::ConfigBuilder::with_safe_default_protocol_versions`]
75+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android", windows))]
76+
pub fn tls_config_with_provider(
77+
provider: Arc<rustls::crypto::CryptoProvider>,
78+
) -> Result<ClientConfig, rustls::Error> {
79+
Ok(ClientConfig::builder_with_provider(provider.clone())
80+
.with_safe_default_protocol_versions()?
81+
.dangerous()
82+
.with_custom_certificate_verifier(Arc::new(Verifier::new().with_provider(provider)))
83+
.with_no_client_auth())
84+
}
85+
6886
/// Exposed for debugging certificate issues with standalone tools.
6987
///
7088
/// This is not intended for production use, you should use [tls_config] instead.

0 commit comments

Comments
 (0)