From b5604bdcc737edb9674a0e69e0d56073379d0626 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 20 Jan 2020 15:03:11 +0100 Subject: openpgp: Remove Cert::direct_signatures() and friends. --- openpgp/src/autocrypt.rs | 5 +++-- openpgp/src/cert/mod.rs | 51 ++++++++++--------------------------------- openpgp/src/serialize/cert.rs | 45 +++++++++++++++++++++----------------- tool/src/commands/inspect.rs | 5 +++-- 4 files changed, 42 insertions(+), 64 deletions(-) diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs index 9a6348df..06cdb5b4 100644 --- a/openpgp/src/autocrypt.rs +++ b/openpgp/src/autocrypt.rs @@ -106,8 +106,9 @@ impl AutocryptHeader { let mut acc = Vec::new(); // The primary key and the most recent selfsig. - acc.push(cert.primary().clone().into()); - cert.direct_signatures().iter().take(1) + let primary = cert.keys().primary_key(); + acc.push(primary.key().clone().into()); + primary.self_signatures().iter().take(1) .for_each(|s| acc.push(s.clone().into())); // The subkeys and the most recent selfsig. diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 6debdcf4..8c1e408f 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -278,11 +278,12 @@ type UnknownBindings = ComponentBindings; /// let mut acc = Vec::new(); /// /// // Primary key and related signatures. -/// acc.push(cert.primary().clone().into()); -/// for s in cert.direct_signatures() { acc.push(s.clone().into()) } -/// for s in cert.certifications() { acc.push(s.clone().into()) } -/// for s in cert.self_revocations() { acc.push(s.clone().into()) } -/// for s in cert.other_revocations() { acc.push(s.clone().into()) } +/// let c = cert.keys().primary_key(); +/// acc.push(c.key().clone().into()); +/// for s in c.self_signatures() { acc.push(s.clone().into()) } +/// for s in c.certifications() { acc.push(s.clone().into()) } +/// for s in c.self_revocations() { acc.push(s.clone().into()) } +/// for s in c.other_revocations() { acc.push(s.clone().into()) } /// /// // UserIDs and related signatures. /// for c in cert.userids().bindings() { @@ -481,38 +482,6 @@ impl Cert { } } - /// The direct signatures. - /// - /// The signatures are validated, and they are reverse sorted by - /// their creation time (newest first). - pub fn direct_signatures(&self) -> &[Signature] { - &self.primary.self_signatures() - } - - /// Third-party certifications. - /// - /// The signatures are *not* validated. They are reverse sorted by - /// their creation time (newest first). - pub fn certifications(&self) -> &[Signature] { - &self.primary.certifications() - } - - /// Revocations issued by the key itself. - /// - /// The revocations are validated, and they are reverse sorted by - /// their creation time (newest first). - pub fn self_revocations(&self) -> &[Signature] { - &self.primary.self_revocations() - } - - /// Revocations issued by other keys. - /// - /// The revocations are *not* validated. They are reverse sorted - /// by their creation time (newest first). - pub fn other_revocations(&self) -> &[Signature] { - &self.primary.other_revocations() - } - /// Returns the Cert's revocation status at time `t`. /// /// A Cert is revoked at time `t` if: @@ -2831,15 +2800,17 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= cert = cert.merge_packets(vec![ binding ]).unwrap(); // A time that matches multiple signatures. + let direct_signatures = + cert.keys().primary_key().self_signatures(); assert_eq!(cert.primary_key_signature(*t), - cert.direct_signatures().get(*offset)); + direct_signatures.get(*offset)); // A time that doesn't match any signature. assert_eq!(cert.primary_key_signature(*t + a_sec), - cert.direct_signatures().get(*offset)); + direct_signatures.get(*offset)); // The current time, which should use the first signature. assert_eq!(cert.primary_key_signature(None), - cert.direct_signatures().get(0)); + direct_signatures.get(0)); // The beginning of time, which should return no // binding signatures. diff --git a/openpgp/src/serialize/cert.rs b/openpgp/src/serialize/cert.rs index 52a0386b..c21b8046 100644 --- a/openpgp/src/serialize/cert.rs +++ b/openpgp/src/serialize/cert.rs @@ -25,7 +25,8 @@ impl Cert { fn serialize_common(&self, o: &mut dyn std::io::Write, export: bool) -> Result<()> { - PacketRef::PublicKey(self.primary()).serialize(o)?; + let primary = self.keys().primary_key(); + PacketRef::PublicKey(primary.key()).serialize(o)?; // Writes a signature if it is exportable or `! export`. let serialize_sig = @@ -41,16 +42,16 @@ impl Cert { Ok(()) }; - for s in self.direct_signatures() { + for s in primary.self_signatures() { serialize_sig(o, s)?; } - for s in self.self_revocations() { + for s in primary.self_revocations() { serialize_sig(o, s)?; } - for s in self.other_revocations() { + for s in primary.other_revocations() { serialize_sig(o, s)?; } - for s in self.certifications() { + for s in primary.certifications() { serialize_sig(o, s)?; } @@ -158,18 +159,19 @@ impl Cert { impl SerializeInto for Cert { fn serialized_len(&self) -> usize { let mut l = 0; - l += PacketRef::PublicKey(self.primary()).serialized_len(); + let primary = self.keys().primary_key(); + l += PacketRef::PublicKey(primary.key()).serialized_len(); - for s in self.direct_signatures() { + for s in primary.self_signatures() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.self_revocations() { + for s in primary.self_revocations() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.other_revocations() { + for s in primary.other_revocations() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.certifications() { + for s in primary.certifications() { l += PacketRef::Signature(s).serialized_len(); } @@ -384,19 +386,21 @@ impl<'a> TSK<'a> { _ => unreachable!(), } }; - serialize_key(o, self.cert.primary().into(), + + let primary = self.cert.keys().primary_key(); + serialize_key(o, primary.key().into(), Tag::PublicKey, Tag::SecretKey)?; - for s in self.cert.direct_signatures() { + for s in primary.self_signatures() { serialize_sig(o, s)?; } - for s in self.cert.self_revocations() { + for s in primary.self_revocations() { serialize_sig(o, s)?; } - for s in self.cert.certifications() { + for s in primary.certifications() { serialize_sig(o, s)?; } - for s in self.cert.other_revocations() { + for s in primary.other_revocations() { serialize_sig(o, s)?; } @@ -537,19 +541,20 @@ impl<'a> SerializeInto for TSK<'a> { packet.serialized_len() }; - l += serialized_len_key(self.cert.primary().into(), + let primary = self.cert.keys().primary_key(); + l += serialized_len_key(primary.key().into(), Tag::PublicKey, Tag::SecretKey); - for s in self.cert.direct_signatures() { + for s in primary.self_signatures() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.cert.self_revocations() { + for s in primary.self_revocations() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.cert.other_revocations() { + for s in primary.other_revocations() { l += PacketRef::Signature(s).serialized_len(); } - for s in self.cert.certifications() { + for s in primary.certifications() { l += PacketRef::Signature(s).serialized_len(); } diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index fa16be32..43ba1acc 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -133,8 +133,9 @@ fn inspect_cert(output: &mut dyn io::Write, cert: &openpgp::Cert, writeln!(output)?; writeln!(output, " Fingerprint: {}", cert.fingerprint())?; inspect_revocation(output, "", cert.revoked(None))?; - inspect_key(output, "", cert.primary(), cert.primary_key_signature(None), - cert.certifications(), + let primary = cert.keys().primary_key(); + inspect_key(output, "", primary.key(), cert.primary_key_signature(None), + primary.certifications(), print_keygrips, print_certifications)?; writeln!(output)?; -- cgit v1.2.3