Skip to content

Commit 8befd1d

Browse files
stormshield-gtdjc
authored andcommitted
relax new_with_extra_roots API
1 parent 1466a62 commit 8befd1d

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

rustls-platform-verifier/src/tests/verification_mock/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,9 @@ pub(super) fn verification_without_mock_root() {
111111
// runner fails to find any roots with openssl-probe we need to provide webpki-root-certs here
112112
// or the test will fail with the `OtherError` instead of the expected `CertificateError`.
113113
#[cfg(target_os = "freebsd")]
114-
let verifier = Verifier::new_with_extra_roots(
115-
webpki_root_certs::TLS_SERVER_ROOT_CERTS
116-
.iter()
117-
.cloned()
118-
.collect(),
119-
)
120-
.unwrap();
114+
let verifier =
115+
Verifier::new_with_extra_roots(webpki_root_certs::TLS_SERVER_ROOT_CERTS.iter().cloned())
116+
.unwrap();
121117

122118
#[cfg(not(target_os = "freebsd"))]
123119
let verifier = Verifier::new();
@@ -338,7 +334,7 @@ fn test_with_mock_root<E: std::error::Error + PartialEq + 'static>(
338334
let verifier = match root_src {
339335
Roots::OnlyExtra => Verifier::new_with_fake_root(ROOT1), // TODO: time
340336
#[cfg(not(target_os = "android"))]
341-
Roots::ExtraAndPlatform => Verifier::new_with_extra_roots(vec![ROOT1.into()]).unwrap(),
337+
Roots::ExtraAndPlatform => Verifier::new_with_extra_roots([ROOT1.into()]).unwrap(),
342338
};
343339
let mut chain = test_case
344340
.chain

rustls-platform-verifier/src/tests/verification_real_world/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,9 @@ fn real_world_test<E: std::error::Error>(test_case: &TestCase<E>) {
128128
// On BSD systems openssl-probe fails to find the system CA bundle,
129129
// so we must provide extra roots from webpki-root-cert.
130130
#[cfg(target_os = "freebsd")]
131-
let verifier = Verifier::new_with_extra_roots(
132-
webpki_root_certs::TLS_SERVER_ROOT_CERTS
133-
.iter()
134-
.cloned()
135-
.collect(),
136-
)
137-
.unwrap();
131+
let verifier =
132+
Verifier::new_with_extra_roots(webpki_root_certs::TLS_SERVER_ROOT_CERTS.iter().cloned())
133+
.unwrap();
138134

139135
#[cfg(not(target_os = "freebsd"))]
140136
let verifier = Verifier::new();

rustls-platform-verifier/src/verification/apple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Verifier {
7373
///
7474
/// See [Verifier::new] for the external requirements the verifier needs.
7575
pub fn new_with_extra_roots(
76-
roots: Vec<pki_types::CertificateDer<'static>>,
76+
roots: impl IntoIterator<Item = pki_types::CertificateDer<'static>>,
7777
) -> Result<Self, TlsError> {
7878
let extra_roots = roots
7979
.into_iter()

rustls-platform-verifier/src/verification/others.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Verifier {
5454
/// WebPKI, using root certificates provided by the platform and augmented by
5555
/// the provided extra root certificates.
5656
pub fn new_with_extra_roots(
57-
roots: Vec<pki_types::CertificateDer<'static>>,
57+
roots: impl IntoIterator<Item = pki_types::CertificateDer<'static>>,
5858
) -> Result<Self, TlsError> {
5959
Ok(Self {
6060
inner: OnceCell::new(),

rustls-platform-verifier/src/verification/windows.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ struct CertEngine {
219219

220220
impl CertEngine {
221221
fn new_with_extra_roots(
222-
roots: &[pki_types::CertificateDer<'static>],
222+
roots: impl IntoIterator<Item = pki_types::CertificateDer<'static>>,
223223
) -> Result<Self, TlsError> {
224224
let mut exclusive_store = CertificateStore::new()?;
225225
for root in roots {
226-
exclusive_store.add_cert(root)?;
226+
exclusive_store.add_cert(&root)?;
227227
}
228228

229229
let mut config = CERT_CHAIN_ENGINE_CONFIG::zeroed_with_size();
@@ -516,9 +516,9 @@ impl Verifier {
516516
/// [`set_provider`][Verifier::set_provider]/[`with_provider`][Verifier::with_provider] or
517517
/// [`CryptoProvider::install_default`] before the verifier can be used.
518518
pub fn new_with_extra_roots(
519-
roots: Vec<pki_types::CertificateDer<'static>>,
519+
roots: impl IntoIterator<Item = pki_types::CertificateDer<'static>>,
520520
) -> Result<Self, TlsError> {
521-
let cert_engine = CertEngine::new_with_extra_roots(&roots)?;
521+
let cert_engine = CertEngine::new_with_extra_roots(roots)?;
522522
Ok(Self {
523523
#[cfg(any(test, feature = "ffi-testing", feature = "dbg"))]
524524
test_only_root_ca_override: None,

0 commit comments

Comments
 (0)