From ab68414e6b87c96fbfa70aaa559c4a24e929c13c Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Tue, 10 Mar 2020 12:52:37 +0100 Subject: [PATCH 1/3] Provide an iterator for CertificateChain --- quinn-proto/src/crypto/types.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/quinn-proto/src/crypto/types.rs b/quinn-proto/src/crypto/types.rs index 36c049767..b83a80047 100644 --- a/quinn-proto/src/crypto/types.rs +++ b/quinn-proto/src/crypto/types.rs @@ -52,6 +52,14 @@ impl CertificateChain { pub fn from_certs(certs: impl IntoIterator) -> Self { certs.into_iter().collect() } + + /// Iterate over the certificates + pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + self.certs + .iter() + .cloned() + .map(|cert| Certificate { inner: cert }) + } } impl std::iter::FromIterator for CertificateChain { From 8cf8b5a16a3928ef18fc840d93363962b408a60c Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Wed, 11 Mar 2020 21:31:08 +0100 Subject: [PATCH 2/3] Iterators over the (rustls) certificates in a CertificateChain --- quinn-proto/src/crypto/types.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/quinn-proto/src/crypto/types.rs b/quinn-proto/src/crypto/types.rs index b83a80047..3c3765e2a 100644 --- a/quinn-proto/src/crypto/types.rs +++ b/quinn-proto/src/crypto/types.rs @@ -53,12 +53,9 @@ impl CertificateChain { certs.into_iter().collect() } - /// Iterate over the certificates - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { - self.certs - .iter() - .cloned() - .map(|cert| Certificate { inner: cert }) + /// An iterator over the certificates in the chain + pub fn iter(&self) -> impl Iterator { + self.certs.iter() } } @@ -79,6 +76,15 @@ impl From> for CertificateChain { } } +impl IntoIterator for CertificateChain { + type Item = rustls::Certificate; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.certs.into_iter() + } +} + /// The private key of a TLS certificate to be used by a server #[derive(Debug, Clone)] pub struct PrivateKey { From 0166304ecd849ba4224031a930ecc663973c13b4 Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Wed, 11 Mar 2020 23:26:43 +0100 Subject: [PATCH 3/3] IntoIterator on reference, too --- quinn-proto/src/crypto/types.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/quinn-proto/src/crypto/types.rs b/quinn-proto/src/crypto/types.rs index 3c3765e2a..4382b6ce9 100644 --- a/quinn-proto/src/crypto/types.rs +++ b/quinn-proto/src/crypto/types.rs @@ -85,6 +85,15 @@ impl IntoIterator for CertificateChain { } } +impl<'a> IntoIterator for &'a CertificateChain { + type Item = &'a rustls::Certificate; + type IntoIter = std::slice::Iter<'a, rustls::Certificate>; + + fn into_iter(self) -> Self::IntoIter { + self.certs.iter() + } +} + /// The private key of a TLS certificate to be used by a server #[derive(Debug, Clone)] pub struct PrivateKey {