11#[ cfg( feature = "rustls-native-certs" ) ]
22use std:: io;
3- #[ cfg( feature = "rustls-platform-verifier" ) ]
4- use std:: sync:: Arc ;
53
64#[ cfg( any(
75 feature = "rustls-platform-verifier" ,
@@ -12,6 +10,8 @@ use rustls::client::WantsClientCert;
1210use rustls:: { ClientConfig , ConfigBuilder , WantsVerifier } ;
1311#[ cfg( feature = "rustls-native-certs" ) ]
1412use rustls_native_certs:: CertificateResult ;
13+ #[ cfg( feature = "rustls-platform-verifier" ) ]
14+ use rustls_platform_verifier:: BuilderVerifierExt ;
1515
1616/// Methods for configuring roots
1717///
@@ -23,10 +23,26 @@ pub trait ConfigBuilderExt: Sealed {
2323 ///
2424 /// See the documentation for [rustls-platform-verifier] for more details.
2525 ///
26+ /// # Panics
27+ ///
28+ /// Since 0.27.7, this method will panic if the platform verifier cannot be initialized.
29+ /// Use `try_with_platform_verifier()` instead to handle errors gracefully.
30+ ///
2631 /// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
32+ #[ deprecated( since = "0.27.7" , note = "use `try_with_platform_verifier` instead" ) ]
2733 #[ cfg( feature = "rustls-platform-verifier" ) ]
2834 fn with_platform_verifier ( self ) -> ConfigBuilder < ClientConfig , WantsClientCert > ;
2935
36+ /// Use the platform's native verifier to verify server certificates.
37+ ///
38+ /// See the documentation for [rustls-platform-verifier] for more details.
39+ ///
40+ /// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
41+ #[ cfg( feature = "rustls-platform-verifier" ) ]
42+ fn try_with_platform_verifier (
43+ self ,
44+ ) -> Result < ConfigBuilder < ClientConfig , WantsClientCert > , rustls:: Error > ;
45+
3046 /// This configures the platform's trusted certs, as implemented by
3147 /// rustls-native-certs
3248 ///
@@ -44,11 +60,15 @@ pub trait ConfigBuilderExt: Sealed {
4460impl ConfigBuilderExt for ConfigBuilder < ClientConfig , WantsVerifier > {
4561 #[ cfg( feature = "rustls-platform-verifier" ) ]
4662 fn with_platform_verifier ( self ) -> ConfigBuilder < ClientConfig , WantsClientCert > {
47- let provider = self . crypto_provider ( ) . clone ( ) ;
48- self . dangerous ( )
49- . with_custom_certificate_verifier ( Arc :: new (
50- rustls_platform_verifier:: Verifier :: new ( ) . with_provider ( provider) ,
51- ) )
63+ self . try_with_platform_verifier ( )
64+ . expect ( "failure to initialize platform verifier" )
65+ }
66+
67+ #[ cfg( feature = "rustls-platform-verifier" ) ]
68+ fn try_with_platform_verifier (
69+ self ,
70+ ) -> Result < ConfigBuilder < ClientConfig , WantsClientCert > , rustls:: Error > {
71+ BuilderVerifierExt :: with_platform_verifier ( self )
5272 }
5373
5474 #[ cfg( feature = "rustls-native-certs" ) ]
0 commit comments