@@ -113,6 +113,10 @@ struct Config {
113
113
root_certs : Vec < Certificate > ,
114
114
#[ cfg( feature = "__tls" ) ]
115
115
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 ,
116
120
#[ cfg( feature = "__tls" ) ]
117
121
min_tls_version : Option < tls:: Version > ,
118
122
#[ cfg( feature = "__tls" ) ]
@@ -205,6 +209,10 @@ impl ClientBuilder {
205
209
root_certs : Vec :: new ( ) ,
206
210
#[ cfg( feature = "__tls" ) ]
207
211
tls_built_in_root_certs : true ,
212
+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
213
+ tls_built_in_certs_webpki : true ,
214
+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
215
+ tls_built_in_certs_native : true ,
208
216
#[ cfg( any( feature = "native-tls" , feature = "__rustls" ) ) ]
209
217
identity : None ,
210
218
#[ cfg( feature = "__tls" ) ]
@@ -499,12 +507,12 @@ impl ClientBuilder {
499
507
}
500
508
501
509
#[ cfg( feature = "rustls-tls-webpki-roots" ) ]
502
- if config. tls_built_in_root_certs {
510
+ if config. tls_built_in_certs_webpki {
503
511
root_cert_store. extend ( webpki_roots:: TLS_SERVER_ROOTS . iter ( ) . cloned ( ) ) ;
504
512
}
505
513
506
514
#[ cfg( feature = "rustls-tls-native-roots" ) ]
507
- if config. tls_built_in_root_certs {
515
+ if config. tls_built_in_certs_native {
508
516
let mut valid_count = 0 ;
509
517
let mut invalid_count = 0 ;
510
518
for cert in rustls_native_certs:: load_native_certs ( )
@@ -1333,6 +1341,15 @@ impl ClientBuilder {
1333
1341
///
1334
1342
/// Defaults to `true` -- built-in system certs will be used.
1335
1343
///
1344
+ /// # Bulk Option
1345
+ ///
1346
+ /// If this value is `true`, _all_ enabled system certs configured with Cargo
1347
+ /// features will be loaded.
1348
+ ///
1349
+ /// You can set this to `false`, and enable only a specific source with
1350
+ /// individual methods. Do that will prevent other sources from being loaded
1351
+ /// even if their feature Cargo feature is enabled.
1352
+ ///
1336
1353
/// # Optional
1337
1354
///
1338
1355
/// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)`
@@ -1348,6 +1365,37 @@ impl ClientBuilder {
1348
1365
) ]
1349
1366
pub fn tls_built_in_root_certs ( mut self , tls_built_in_root_certs : bool ) -> ClientBuilder {
1350
1367
self . config . tls_built_in_root_certs = tls_built_in_root_certs;
1368
+
1369
+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
1370
+ {
1371
+ self . config . tls_built_in_certs_webpki = tls_built_in_root_certs;
1372
+ }
1373
+
1374
+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
1375
+ {
1376
+ self . config . tls_built_in_certs_native = tls_built_in_root_certs;
1377
+ }
1378
+
1379
+ self
1380
+ }
1381
+
1382
+ /// Sets whether to load webpki root certs with rustls.
1383
+ ///
1384
+ /// If the feature is enabled, this value is `true` by default.
1385
+ #[ cfg( feature = "rustls-tls-webpki-roots" ) ]
1386
+ #[ cfg_attr( docsrs, doc( cfg( feature = "rustls-tls-webpki-roots" ) ) ) ]
1387
+ pub fn tls_built_in_webpki_certs ( mut self , enabled : bool ) -> ClientBuilder {
1388
+ self . config . tls_built_in_certs_webpki = enabled;
1389
+ self
1390
+ }
1391
+
1392
+ /// Sets whether to load native root certs with rustls.
1393
+ ///
1394
+ /// If the feature is enabled, this value is `true` by default.
1395
+ #[ cfg( feature = "rustls-tls-native-roots" ) ]
1396
+ #[ cfg_attr( docsrs, doc( cfg( feature = "rustls-tls-native-roots" ) ) ) ]
1397
+ pub fn tls_built_in_native_certs ( mut self , enabled : bool ) -> ClientBuilder {
1398
+ self . config . tls_built_in_certs_native = enabled;
1351
1399
self
1352
1400
}
1353
1401
0 commit comments