1
1
#[ cfg( feature = "rustls-native-certs" ) ]
2
2
use std:: io;
3
- #[ cfg( feature = "rustls-platform-verifier" ) ]
4
- use std:: sync:: Arc ;
5
3
6
4
#[ cfg( any(
7
5
feature = "rustls-platform-verifier" ,
@@ -12,6 +10,8 @@ use rustls::client::WantsClientCert;
12
10
use rustls:: { ClientConfig , ConfigBuilder , WantsVerifier } ;
13
11
#[ cfg( feature = "rustls-native-certs" ) ]
14
12
use rustls_native_certs:: CertificateResult ;
13
+ #[ cfg( feature = "rustls-platform-verifier" ) ]
14
+ use rustls_platform_verifier:: BuilderVerifierExt ;
15
15
16
16
/// Methods for configuring roots
17
17
///
@@ -22,10 +22,26 @@ pub trait ConfigBuilderExt {
22
22
///
23
23
/// See the documentation for [rustls-platform-verifier] for more details.
24
24
///
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
+ ///
25
30
/// [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier
31
+ #[ deprecated( since = "0.27.7" , note = "use `try_with_platform_verifier` instead" ) ]
26
32
#[ cfg( feature = "rustls-platform-verifier" ) ]
27
33
fn with_platform_verifier ( self ) -> ConfigBuilder < ClientConfig , WantsClientCert > ;
28
34
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
+
29
45
/// This configures the platform's trusted certs, as implemented by
30
46
/// rustls-native-certs
31
47
///
@@ -43,11 +59,15 @@ pub trait ConfigBuilderExt {
43
59
impl ConfigBuilderExt for ConfigBuilder < ClientConfig , WantsVerifier > {
44
60
#[ cfg( feature = "rustls-platform-verifier" ) ]
45
61
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 )
51
71
}
52
72
53
73
#[ cfg( feature = "rustls-native-certs" ) ]
0 commit comments