From e077066fa3a63e28f07296f609c5be3b84a2745a Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Thu, 12 Mar 2020 09:03:58 +0100 Subject: [PATCH] Provide an iterator for CertificateChain (#672) * Provide an iterator for CertificateChain * Iterators over the (rustls) certificates in a CertificateChain * IntoIterator on reference, too --- quinn-proto/src/crypto/types.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/quinn-proto/src/crypto/types.rs b/quinn-proto/src/crypto/types.rs index 36c049767..4382b6ce9 100644 --- a/quinn-proto/src/crypto/types.rs +++ b/quinn-proto/src/crypto/types.rs @@ -52,6 +52,11 @@ impl CertificateChain { pub fn from_certs(certs: impl IntoIterator) -> Self { certs.into_iter().collect() } + + /// An iterator over the certificates in the chain + pub fn iter(&self) -> impl Iterator { + self.certs.iter() + } } impl std::iter::FromIterator for CertificateChain { @@ -71,6 +76,24 @@ 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() + } +} + +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 {