summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2024-04-17 13:12:09 +0200
committerJustus Winter <justus@sequoia-pgp.org>2024-04-23 11:58:35 +0200
commit419a314743a63d857845dd67879ae49c74a0dee3 (patch)
tree59ec2c176ccf5772b8c8f0fb18e595734eda0ee7
parentdfc750255202108100ef0caf7e4a38cb71153749 (diff)
openpgp: Add iteration interface for signatures in bundles.
- See #638.
-rw-r--r--openpgp/NEWS9
-rw-r--r--openpgp/src/cert.rs9
-rw-r--r--openpgp/src/cert/amalgamation.rs8
-rw-r--r--openpgp/src/cert/builder.rs2
-rw-r--r--openpgp/src/cert/bundle.rs52
5 files changed, 62 insertions, 18 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS
index f40537a3..ed87296c 100644
--- a/openpgp/NEWS
+++ b/openpgp/NEWS
@@ -6,6 +6,10 @@
* Changes in 1.21.0
** New functionality
+ - ComponentBundle::certifications2
+ - ComponentBundle::other_revocations2
+ - ComponentBundle::self_revocations2
+ - ComponentBundle::self_signatures2
- Key::<PublicParts, _>::steal_secret
- Key::<UnknownParts, _>::steal_secret
- Key4::<PublicParts, _>::steal_secret
@@ -14,6 +18,11 @@
curve P-384.
- The RustCrypto backend now supports ECDH and ECDSA over the NIST
curve P-521.
+** Deprecated functionality
+ - ComponentBundle::certifications
+ - ComponentBundle::other_revocations
+ - ComponentBundle::self_revocations
+ - ComponentBundle::self_signatures
* Changes in 1.20.0
** New functionality
- S2K::Implicit
diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs
index 8106bf7b..a1b62462 100644
--- a/openpgp/src/cert.rs
+++ b/openpgp/src/cert.rs
@@ -6166,19 +6166,20 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g=
cert = cert.insert_packets(binding).unwrap();
// A time that matches multiple signatures.
let direct_signatures =
- cert.primary_key().bundle().self_signatures();
+ cert.primary_key().bundle().self_signatures2()
+ .collect::<Vec<_>>();
assert_eq!(cert.primary_key().with_policy(p, *t).unwrap()
.direct_key_signature().ok(),
- direct_signatures.get(*offset));
+ direct_signatures.get(*offset).cloned());
// A time that doesn't match any signature.
assert_eq!(cert.primary_key().with_policy(p, *t + a_sec).unwrap()
.direct_key_signature().ok(),
- direct_signatures.get(*offset));
+ direct_signatures.get(*offset).cloned());
// The current time, which should use the first signature.
assert_eq!(cert.primary_key().with_policy(p, None).unwrap()
.direct_key_signature().ok(),
- direct_signatures.get(0));
+ direct_signatures.get(0).cloned());
// The beginning of time, which should return no
// binding signatures.
diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs
index bfb2b589..f65c588c 100644
--- a/openpgp/src/cert/amalgamation.rs
+++ b/openpgp/src/cert/amalgamation.rs
@@ -844,12 +844,12 @@ impl<'a, C> ComponentAmalgamation<'a, C> {
/// The component's self-signatures.
pub fn self_signatures(&self) -> impl Iterator<Item=&'a Signature> + Send + Sync {
- self.bundle().self_signatures().iter()
+ self.bundle().self_signatures2()
}
/// The component's third-party certifications.
pub fn certifications(&self) -> impl Iterator<Item=&'a Signature> + Send + Sync {
- self.bundle().certifications().iter()
+ self.bundle().certifications2()
}
/// Returns third-party certifications that appear to issued by
@@ -884,13 +884,13 @@ impl<'a, C> ComponentAmalgamation<'a, C> {
/// The component's revocations that were issued by the
/// certificate holder.
pub fn self_revocations(&self) -> impl Iterator<Item=&'a Signature> + Send + Sync {
- self.bundle().self_revocations().iter()
+ self.bundle().self_revocations2()
}
/// The component's revocations that were issued by other
/// certificates.
pub fn other_revocations(&self) -> impl Iterator<Item=&'a Signature> + Send + Sync {
- self.bundle().other_revocations().iter()
+ self.bundle().other_revocations2()
}
/// Returns all of the component's signatures.
diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs
index 0d9f77b1..8dbe9c80 100644
--- a/openpgp/src/cert/builder.rs
+++ b/openpgp/src/cert/builder.rs
@@ -1793,7 +1793,7 @@ mod tests {
.generate().unwrap();
let key = cert.primary_key().key();
- let sig = &cert.primary_key().bundle().self_signatures()[0];
+ let sig = &cert.primary_key().bundle().self_signatures2().next().unwrap();
assert!(sig.key_alive(key, now).is_ok());
assert!(sig.key_alive(key, now + 590 * s).is_ok());
assert!(! sig.key_alive(key, now + 610 * s).is_ok());
diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs
index c5d7ab5b..e11b1066 100644
--- a/openpgp/src/cert/bundle.rs
+++ b/openpgp/src/cert/bundle.rs
@@ -436,10 +436,18 @@ impl<C> ComponentBundle<C> {
/// for (i, ka) in cert.keys().enumerate() {
/// eprintln!("Key #{} ({}) has {:?} self signatures",
/// i, ka.fingerprint(),
- /// ka.bundle().self_signatures().len());
+ /// ka.bundle().self_signatures2().count());
/// }
/// # Ok(()) }
/// ```
+ // XXXv2: Rename this function.
+ pub fn self_signatures2(&self)
+ -> impl Iterator<Item=&Signature> + Send + Sync {
+ self.self_signatures.iter()
+ }
+
+ /// Returns the component's self-signatures.
+ #[deprecated(note = "Use self_signatures2 instead.")]
pub fn self_signatures(&self) -> &[Signature] {
&self.self_signatures
}
@@ -465,10 +473,18 @@ impl<C> ComponentBundle<C> {
/// for ua in cert.userids() {
/// eprintln!("User ID {} has {:?} unverified, third-party certifications",
/// String::from_utf8_lossy(ua.userid().value()),
- /// ua.bundle().certifications().len());
+ /// ua.bundle().certifications2().count());
/// }
/// # Ok(()) }
/// ```
+ // XXXv2: Rename this function.
+ pub fn certifications2(&self)
+ -> impl Iterator<Item=&Signature> + Send + Sync {
+ self.certifications.iter()
+ }
+
+ /// Returns the component's third-party certifications.
+ #[deprecated(note = "Use certifications2 instead.")]
pub fn certifications(&self) -> &[Signature] {
&self.certifications
}
@@ -495,10 +511,19 @@ impl<C> ComponentBundle<C> {
/// for u in cert.userids() {
/// eprintln!("User ID {} has {:?} revocation certificates.",
/// String::from_utf8_lossy(u.userid().value()),
- /// u.bundle().self_revocations().len());
+ /// u.bundle().self_revocations2().count());
/// }
/// # Ok(()) }
/// ```
+ // XXXv2: Rename this function.
+ pub fn self_revocations2(&self)
+ -> impl Iterator<Item=&Signature> + Send + Sync {
+ self.self_revocations.iter()
+ }
+
+ /// Returns the component's revocations that were issued by the
+ /// certificate holder.
+ #[deprecated(note = "Use self_revocations2 instead.")]
pub fn self_revocations(&self) -> &[Signature] {
&self.self_revocations
}
@@ -525,10 +550,19 @@ impl<C> ComponentBundle<C> {
/// for u in cert.userids() {
/// eprintln!("User ID {} has {:?} unverified, third-party revocation certificates.",
/// String::from_utf8_lossy(u.userid().value()),
- /// u.bundle().other_revocations().len());
+ /// u.bundle().other_revocations2().count());
/// }
/// # Ok(()) }
/// ```
+ // XXXv2: Rename this function.
+ pub fn other_revocations2(&self)
+ -> impl Iterator<Item=&Signature> + Send + Sync {
+ self.other_revocations.iter()
+ }
+
+ /// Returns the component's revocations that were issued by other
+ /// certificates.
+ #[deprecated(note = "Use other_revocations2 instead.")]
pub fn other_revocations(&self) -> &[Signature] {
&self.other_revocations
}
@@ -605,11 +639,11 @@ impl<C> ComponentBundle<C> {
pub fn signatures(&self)
-> impl Iterator<Item = &Signature> + Send + Sync
{
- self.self_revocations.iter()
- .chain(self.self_signatures.iter())
- .chain(self.attestations.iter())
- .chain(self.certifications.iter())
- .chain(self.other_revocations.iter())
+ self.self_revocations2()
+ .chain(self.self_signatures2())
+ .chain(self.attestations())
+ .chain(self.certifications2())
+ .chain(self.other_revocations2())
}
/// Returns the component's revocation status at time `t`.