Skip to content

Commit

Permalink
Provide an iterator for CertificateChain (#672)
Browse files Browse the repository at this point in the history
* Provide an iterator for CertificateChain

* Iterators over the (rustls) certificates in a CertificateChain

* IntoIterator on reference, too
  • Loading branch information
kim authored Mar 12, 2020
1 parent f514595 commit e077066
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions quinn-proto/src/crypto/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl CertificateChain {
pub fn from_certs(certs: impl IntoIterator<Item = Certificate>) -> Self {
certs.into_iter().collect()
}

/// An iterator over the certificates in the chain
pub fn iter(&self) -> impl Iterator<Item = &rustls::Certificate> {
self.certs.iter()
}
}

impl std::iter::FromIterator<Certificate> for CertificateChain {
Expand All @@ -71,6 +76,24 @@ impl From<Vec<rustls::Certificate>> for CertificateChain {
}
}

impl IntoIterator for CertificateChain {
type Item = rustls::Certificate;
type IntoIter = std::vec::IntoIter<rustls::Certificate>;

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 {
Expand Down

0 comments on commit e077066

Please sign in to comment.