From 7949364d690e6c93f7f6c23555e5ee395187d10e Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 12 Jan 2021 10:04:55 +0100 Subject: openpgp: Add an accessor for all component signatures. --- openpgp/src/cert/amalgamation.rs | 18 ++++++++++++++++++ openpgp/src/cert/bundle.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index edb86851..3d291353 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -820,6 +820,12 @@ impl<'a, C> ComponentAmalgamation<'a, C> { pub fn other_revocations(&self) -> impl Iterator + Send + Sync { self.bundle().other_revocations().iter() } + + /// Returns all of the component's signatures. + pub fn signatures(&self) + -> impl Iterator + Send + Sync { + self.bundle().signatures() + } } macro_rules! impl_with_policy { @@ -1187,6 +1193,18 @@ impl<'a, C> ValidComponentAmalgamation<'a, C> .filter(move |sig| self.cert.policy().signature(sig, HashAlgoSecurity::CollisionResistance).is_ok()) } + + + /// Returns all of the component's signatures. + /// + /// This method only returns signatures that are valid under the + /// current policy. + pub fn signatures(&self) + -> impl Iterator + Send + Sync { + std::ops::Deref::deref(self).signatures() + .filter(move |sig| self.cert.policy().signature(sig, + HashAlgoSecurity::CollisionResistance).is_ok()) + } } impl<'a, C> seal::Sealed for ValidComponentAmalgamation<'a, C> {} diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index c8a01656..0ebbdc3c 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -494,6 +494,44 @@ impl ComponentBundle { &self.other_revocations } + /// Returns all of the component's signatures. + /// + /// Only the self-signatures are validated. The signatures are + /// sorted first by type, then by creation time. The self + /// revocations come first, then the self signatures, + /// certifications, and third-party revocations coming last. This + /// function may return additional types of signatures that could + /// be associated to this component. + /// + /// # Examples + /// + /// ``` + /// # use sequoia_openpgp as openpgp; + /// # use openpgp::cert::prelude::*; + /// use openpgp::policy::StandardPolicy; + /// # + /// # fn main() -> openpgp::Result<()> { + /// let p = &StandardPolicy::new(); + /// + /// # let (cert, _) = + /// # CertBuilder::general_purpose(None, Some("alice@example.org")) + /// # .generate()?; + /// for (i, ka) in cert.keys().enumerate() { + /// eprintln!("Key #{} ({}) has {:?} signatures", + /// i, ka.fingerprint(), + /// ka.signatures().count()); + /// } + /// # Ok(()) } + /// ``` + pub fn signatures(&self) + -> impl Iterator + Send + Sync + { + self.self_revocations.iter() + .chain(self.self_signatures.iter()) + .chain(self.certifications.iter()) + .chain(self.other_revocations.iter()) + } + /// Returns the component's revocation status at time `t`. /// /// A component is considered to be revoked at time `t` if: -- cgit v1.2.3