@@ -113,6 +113,10 @@ struct Config {
113113 root_certs : Vec < Certificate > ,
114114 #[ cfg( feature = "__tls" ) ]
115115 tls_built_in_root_certs : bool ,
116+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
117+ tls_built_in_certs_webpki : bool ,
118+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
119+ tls_built_in_certs_native : bool ,
116120 #[ cfg( feature = "__tls" ) ]
117121 min_tls_version : Option < tls:: Version > ,
118122 #[ cfg( feature = "__tls" ) ]
@@ -206,6 +210,10 @@ impl ClientBuilder {
206210 root_certs : Vec :: new ( ) ,
207211 #[ cfg( feature = "__tls" ) ]
208212 tls_built_in_root_certs : true ,
213+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
214+ tls_built_in_certs_webpki : true ,
215+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
216+ tls_built_in_certs_native : true ,
209217 #[ cfg( any( feature = "native-tls" , feature = "__rustls" ) ) ]
210218 identity : None ,
211219 #[ cfg( feature = "__tls" ) ]
@@ -501,12 +509,12 @@ impl ClientBuilder {
501509 }
502510
503511 #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
504- if config. tls_built_in_root_certs {
512+ if config. tls_built_in_certs_webpki {
505513 root_cert_store. extend ( webpki_roots:: TLS_SERVER_ROOTS . iter ( ) . cloned ( ) ) ;
506514 }
507515
508516 #[ cfg( feature = "rustls-tls-native-roots" ) ]
509- if config. tls_built_in_root_certs {
517+ if config. tls_built_in_certs_native {
510518 let mut valid_count = 0 ;
511519 let mut invalid_count = 0 ;
512520 for cert in rustls_native_certs:: load_native_certs ( )
@@ -1343,6 +1351,15 @@ impl ClientBuilder {
13431351 ///
13441352 /// Defaults to `true` -- built-in system certs will be used.
13451353 ///
1354+ /// # Bulk Option
1355+ ///
1356+ /// If this value is `true`, _all_ enabled system certs configured with Cargo
1357+ /// features will be loaded.
1358+ ///
1359+ /// You can set this to `false`, and enable only a specific source with
1360+ /// individual methods. Do that will prevent other sources from being loaded
1361+ /// even if their feature Cargo feature is enabled.
1362+ ///
13461363 /// # Optional
13471364 ///
13481365 /// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)`
@@ -1358,6 +1375,37 @@ impl ClientBuilder {
13581375 ) ]
13591376 pub fn tls_built_in_root_certs ( mut self , tls_built_in_root_certs : bool ) -> ClientBuilder {
13601377 self . config . tls_built_in_root_certs = tls_built_in_root_certs;
1378+
1379+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
1380+ {
1381+ self . config . tls_built_in_certs_webpki = tls_built_in_root_certs;
1382+ }
1383+
1384+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
1385+ {
1386+ self . config . tls_built_in_certs_native = tls_built_in_root_certs;
1387+ }
1388+
1389+ self
1390+ }
1391+
1392+ /// Sets whether to load webpki root certs with rustls.
1393+ ///
1394+ /// If the feature is enabled, this value is `true` by default.
1395+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
1396+ #[ cfg_attr( docsrs, doc( cfg( feature = "rustls-tls-webpki-roots" ) ) ) ]
1397+ pub fn tls_built_in_webpki_certs ( mut self , enabled : bool ) -> ClientBuilder {
1398+ self . config . tls_built_in_certs_webpki = enabled;
1399+ self
1400+ }
1401+
1402+ /// Sets whether to load native root certs with rustls.
1403+ ///
1404+ /// If the feature is enabled, this value is `true` by default.
1405+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
1406+ #[ cfg_attr( docsrs, doc( cfg( feature = "rustls-tls-native-roots" ) ) ) ]
1407+ pub fn tls_built_in_native_certs ( mut self , enabled : bool ) -> ClientBuilder {
1408+ self . config . tls_built_in_certs_native = enabled;
13611409 self
13621410 }
13631411
0 commit comments