summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-01-12 10:04:55 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-01-12 10:08:22 +0100
commit7949364d690e6c93f7f6c23555e5ee395187d10e (patch)
tree8404f89040ad42513c9fd4b63cff7469b4555d54
parent8357b788013c89addafbe310305d4657c6f05a2a (diff)
openpgp: Add an accessor for all component signatures.
-rw-r--r--openpgp/src/cert/amalgamation.rs18
-rw-r--r--openpgp/src/cert/bundle.rs38
2 files changed, 56 insertions, 0 deletions
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<Item=&'a Signature> + Send + Sync {
self.bundle().other_revocations().iter()
}
+
+ /// Returns all of the component's signatures.
+ pub fn signatures(&self)
+ -> impl Iterator<Item = &'a Signature> + 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<Item = &Signature> + 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<C> ComponentBundle<C> {
&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<Item = &Signature> + 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: