1- #[ cfg( any( feature = "rustls" , feature = "native-tls" ) ) ]
21use std:: sync:: Arc ;
32
4- #[ cfg( all ( feature = "native-tls" , not( feature = "rustls" ) ) ) ]
3+ #[ cfg( not( feature = "rustls" ) ) ]
54use native_tls:: { Certificate , TlsConnector , TlsConnectorBuilder } ;
65#[ cfg( feature = "rustls" ) ]
76use rustls:: RootCertStore ;
8- #[ cfg( all ( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls ") ) ]
7+ #[ cfg( not( feature = "rustls" ) ) ]
98use tokio_native_tls:: TlsConnector as AsyncTlsConnector ;
109#[ cfg( feature = "rustls-webpki" ) ]
1110use webpki_roots:: TLS_SERVER_ROOTS ;
1211
1312use crate :: Error ;
1413
15- #[ cfg( all ( feature = "rustls" , feature = "tokio-rustls" ) ) ]
14+ #[ cfg( feature = "rustls" ) ]
1615pub ( crate ) struct CertificatesBuilder {
1716 pub ( crate ) inner : RootCertStore ,
1817 pub ( crate ) disable_default : bool ,
1918}
2019
21- #[ cfg( all ( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls ") ) ]
20+ #[ cfg( not( feature = "rustls" ) ) ]
2221pub ( crate ) struct CertificatesBuilder {
2322 pub ( crate ) inner : TlsConnectorBuilder ,
2423}
2524
25+ #[ cfg( feature = "rustls" ) ]
2626impl CertificatesBuilder {
27- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
2827 pub ( crate ) fn new ( cert_der : Option < Vec < u8 > > ) -> Result < Self , Error > {
2928 let mut certificates = Self { inner : RootCertStore :: empty ( ) , disable_default : false } ;
3029
@@ -35,42 +34,12 @@ impl CertificatesBuilder {
3534 Ok ( certificates)
3635 }
3736
38- #[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls" ) ) ]
39- pub ( crate ) fn new ( cert_der : Option < Vec < u8 > > ) -> Result < Self , Error > {
40- let builder = TlsConnector :: builder ( ) ;
41- let mut certificates = Self { inner : builder } ;
42-
43- if let Some ( cert_der) = cert_der {
44- certificates. append_certificate ( cert_der) ?;
45- }
46-
47- Ok ( certificates)
48- }
49-
50- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
5137 pub ( crate ) fn append_certificate ( & mut self , cert_der : Vec < u8 > ) -> Result < & mut Self , Error > {
5238 self . inner . add ( & rustls:: Certificate ( cert_der) ) . map_err ( Error :: RustlsAppendCert ) ?;
5339
5440 Ok ( self )
5541 }
5642
57- #[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls" ) ) ]
58- pub ( crate ) fn append_certificate ( & mut self , cert_der : Vec < u8 > ) -> Result < & mut Self , Error > {
59- let certificate = Certificate :: from_der ( & cert_der) ?;
60- self . inner . add_root_certificate ( certificate) ;
61-
62- Ok ( self )
63- }
64-
65- #[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls" ) ) ]
66- pub ( crate ) fn build ( self ) -> Result < Certificates , Error > {
67- let connector = self . inner . build ( ) ?;
68- let async_connector = AsyncTlsConnector :: from ( connector) ;
69-
70- Ok ( Certificates ( Arc :: new ( async_connector) ) )
71- }
72-
73- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
7443 pub ( crate ) fn build ( mut self ) -> Result < Certificates , Error > {
7544 if !self . disable_default {
7645 self . with_root_certificates ( ) ;
@@ -79,7 +48,6 @@ impl CertificatesBuilder {
7948 Ok ( Certificates ( Arc :: new ( self . inner ) ) )
8049 }
8150
82- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
8351 fn with_root_certificates ( & mut self ) -> & mut Self {
8452 // Try to load native certs
8553 #[ cfg( feature = "https-rustls-probe" ) ]
@@ -106,23 +74,49 @@ impl CertificatesBuilder {
10674 self
10775 }
10876
109- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
11077 pub ( crate ) fn disable_default ( & mut self ) -> Result < & mut Self , Error > {
11178 self . disable_default = true ;
11279 Ok ( self )
11380 }
81+ }
82+
83+ #[ cfg( not( feature = "rustls" ) ) ]
84+ impl CertificatesBuilder {
85+ pub ( crate ) fn new ( cert_der : Option < Vec < u8 > > ) -> Result < Self , Error > {
86+ let builder = TlsConnector :: builder ( ) ;
87+ let mut certificates = Self { inner : builder } ;
88+
89+ if let Some ( cert_der) = cert_der {
90+ certificates. append_certificate ( cert_der) ?;
91+ }
92+
93+ Ok ( certificates)
94+ }
95+
96+ pub ( crate ) fn append_certificate ( & mut self , cert_der : Vec < u8 > ) -> Result < & mut Self , Error > {
97+ let certificate = Certificate :: from_der ( & cert_der) ?;
98+ self . inner . add_root_certificate ( certificate) ;
99+
100+ Ok ( self )
101+ }
102+
103+ pub ( crate ) fn build ( self ) -> Result < Certificates , Error > {
104+ let connector = self . inner . build ( ) ?;
105+ let async_connector = AsyncTlsConnector :: from ( connector) ;
106+
107+ Ok ( Certificates ( Arc :: new ( async_connector) ) )
108+ }
114109
115- #[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls" ) ) ]
116110 pub ( crate ) fn disable_default ( & mut self ) -> Result < & mut Self , Error > {
117111 self . inner . disable_built_in_roots ( true ) ;
118112 Ok ( self )
119113 }
120114}
121115
122116#[ derive( Clone ) ]
123- #[ cfg( all ( feature = "rustls" , feature = "tokio-rustls" ) ) ]
117+ #[ cfg( feature = "rustls" ) ]
124118pub ( crate ) struct Certificates ( pub ( crate ) Arc < RootCertStore > ) ;
125119
126120#[ derive( Clone ) ]
127- #[ cfg( all ( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls ") ) ]
121+ #[ cfg( not( feature = "rustls" ) ) ]
128122pub ( crate ) struct Certificates ( pub ( crate ) Arc < AsyncTlsConnector > ) ;
0 commit comments