mirror of https://github.com/ctz/rustls
Implement FromIterator for RootCertStore (#1708)
Co-authored-by: Daniel McCarney <daniel@binaryparadox.net>
This commit is contained in:
parent
0cd488dff6
commit
309a5d5051
|
@ -8,8 +8,7 @@ use std::net::TcpStream;
|
|||
use std::sync::Arc;
|
||||
|
||||
fn main() {
|
||||
let mut root_store = rustls::RootCertStore::empty();
|
||||
root_store.extend(
|
||||
let root_store = rustls::RootCertStore::from_iter(
|
||||
webpki_roots::TLS_SERVER_ROOTS
|
||||
.iter()
|
||||
.cloned(),
|
||||
|
|
|
@ -66,8 +66,7 @@ fn start_connection(config: &Arc<rustls::ClientConfig>, domain_name: &str) {
|
|||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let mut root_store = RootCertStore::empty();
|
||||
root_store.extend(
|
||||
let root_store = RootCertStore::from_iter(
|
||||
webpki_roots::TLS_SERVER_ROOTS
|
||||
.iter()
|
||||
.cloned(),
|
||||
|
|
|
@ -15,8 +15,7 @@ use std::sync::Arc;
|
|||
use rustls::RootCertStore;
|
||||
|
||||
fn main() {
|
||||
let mut root_store = RootCertStore::empty();
|
||||
root_store.extend(
|
||||
let root_store = RootCertStore::from_iter(
|
||||
webpki_roots::TLS_SERVER_ROOTS
|
||||
.iter()
|
||||
.cloned(),
|
||||
|
|
|
@ -5,8 +5,7 @@ use std::sync::Arc;
|
|||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let mut root_store = rustls::RootCertStore::empty();
|
||||
root_store.extend(
|
||||
let root_store = rustls::RootCertStore::from_iter(
|
||||
webpki_roots::TLS_SERVER_ROOTS
|
||||
.iter()
|
||||
.cloned(),
|
||||
|
|
|
@ -116,11 +116,10 @@
|
|||
//!
|
||||
//! ```rust,no_run
|
||||
//! # #[cfg(feature = "ring")] {
|
||||
//! let mut root_store = rustls::RootCertStore::empty();
|
||||
//! root_store.extend(
|
||||
//! let root_store = rustls::RootCertStore::from_iter(
|
||||
//! webpki_roots::TLS_SERVER_ROOTS
|
||||
//! .iter()
|
||||
//! .cloned()
|
||||
//! .cloned(),
|
||||
//! );
|
||||
//! # }
|
||||
//! ```
|
||||
|
@ -147,11 +146,10 @@
|
|||
//! # use rustls;
|
||||
//! # use webpki;
|
||||
//! # use std::sync::Arc;
|
||||
//! # let mut root_store = rustls::RootCertStore::empty();
|
||||
//! # root_store.extend(
|
||||
//! # let root_store = rustls::RootCertStore::from_iter(
|
||||
//! # webpki_roots::TLS_SERVER_ROOTS
|
||||
//! # .iter()
|
||||
//! # .cloned()
|
||||
//! # .cloned(),
|
||||
//! # );
|
||||
//! # let config = rustls::ClientConfig::builder()
|
||||
//! # .with_root_certificates(root_store)
|
||||
|
|
|
@ -103,6 +103,14 @@ impl RootCertStore {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromIterator<TrustAnchor<'static>> for RootCertStore {
|
||||
fn from_iter<T: IntoIterator<Item = TrustAnchor<'static>>>(iter: T) -> Self {
|
||||
Self {
|
||||
roots: iter.into_iter().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Extend<TrustAnchor<'static>> for RootCertStore {
|
||||
fn extend<T: IntoIterator<Item = TrustAnchor<'static>>>(&mut self, iter: T) {
|
||||
self.roots.extend(iter);
|
||||
|
@ -122,13 +130,12 @@ fn root_cert_store_debug() {
|
|||
use core::iter;
|
||||
use pki_types::Der;
|
||||
|
||||
let mut store = RootCertStore::empty();
|
||||
let ta = TrustAnchor {
|
||||
subject: Der::from_slice(&[]),
|
||||
subject_public_key_info: Der::from_slice(&[]),
|
||||
name_constraints: None,
|
||||
};
|
||||
store.extend(iter::repeat(ta).take(138));
|
||||
let store = RootCertStore::from_iter(iter::repeat(ta).take(138));
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", store),
|
||||
|
|
Loading…
Reference in New Issue