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///
@@ -22,10 +22,26 @@ pub trait ConfigBuilderExt: sealed::Sealed {
2222 ///
2323 /// See the documentation for [rustls-platform-verifier] for more details.
2424 ///
25+ /// # Panics
26+ ///
27+ /// Since 0.27.7, this method will panic if the platform verifier cannot be initialized.
28+ /// Use `try_with_platform_verifier()` instead to handle errors gracefully.
29+ ///
2530 /// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
31+ #[ deprecated( since = "0.27.7" , note = "use `try_with_platform_verifier` instead" ) ]
2632 #[ cfg( feature = "rustls-platform-verifier" ) ]
2733 fn with_platform_verifier ( self ) -> ConfigBuilder < ClientConfig , WantsClientCert > ;
2834
35+ /// Use the platform's native verifier to verify server certificates.
36+ ///
37+ /// See the documentation for [rustls-platform-verifier] for more details.
38+ ///
39+ /// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
40+ #[ cfg( feature = "rustls-platform-verifier" ) ]
41+ fn try_with_platform_verifier (
42+ self ,
43+ ) -> Result < ConfigBuilder < ClientConfig , WantsClientCert > , rustls:: Error > ;
44+
2945 /// This configures the platform's trusted certs, as implemented by
3046 /// rustls-native-certs
3147 ///
@@ -43,11 +59,15 @@ pub trait ConfigBuilderExt: sealed::Sealed {
4359impl ConfigBuilderExt for ConfigBuilder < ClientConfig , WantsVerifier > {
4460 #[ cfg( feature = "rustls-platform-verifier" ) ]
4561 fn with_platform_verifier ( self ) -> ConfigBuilder < ClientConfig , WantsClientCert > {
46- let provider = self . crypto_provider ( ) . clone ( ) ;
47- self . dangerous ( )
48- . with_custom_certificate_verifier ( Arc :: new (
49- rustls_platform_verifier:: Verifier :: new ( ) . with_provider ( provider) ,
50- ) )
62+ self . try_with_platform_verifier ( )
63+ . expect ( "failure to initialize platform verifier" )
64+ }
65+
66+ #[ cfg( feature = "rustls-platform-verifier" ) ]
67+ fn try_with_platform_verifier (
68+ self ,
69+ ) -> Result < ConfigBuilder < ClientConfig , WantsClientCert > , rustls:: Error > {
70+ BuilderVerifierExt :: with_platform_verifier ( self )
5171 }
5272
5373 #[ cfg( feature = "rustls-native-certs" ) ]
0 commit comments