diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-02-26 22:59:49 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-02-26 23:09:19 +0100 |
commit | 86309e9c4971bd2e4ba80bf4a655aab091cd89b9 (patch) | |
tree | 6898365f04b99c48fb6af97b25df427fa1d1978d | |
parent | ceab08e222fadc68c3330dbfe2b47db34bf7141f (diff) |
openpgp: Don't unnecessarily use ComponentAmalgamation::bundle.
- A `ComponentAmalgamation` derefs to a `ComponentBundle`. Don't
use `ComponentAmalgamation::bundle` if it is unnecessary and
doesn't improve legibility.
-rw-r--r-- | autocrypt/src/lib.rs | 9 | ||||
-rw-r--r-- | net/src/wkd.rs | 4 | ||||
-rw-r--r-- | openpgp/examples/web-of-trust.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/bindings.rs | 4 | ||||
-rw-r--r-- | openpgp/src/cert/component_iter.rs | 3 | ||||
-rw-r--r-- | openpgp/src/cert/mod.rs | 18 | ||||
-rw-r--r-- | openpgp/src/cert/parser/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/hash.rs | 10 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 7 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 16 | ||||
-rw-r--r-- | openpgp/src/serialize/cert.rs | 24 | ||||
-rw-r--r-- | openpgp/src/serialize/cert_armored.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/inspect.rs | 8 |
13 files changed, 54 insertions, 55 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs index d8e9d119..e2b8ef55 100644 --- a/autocrypt/src/lib.rs +++ b/autocrypt/src/lib.rs @@ -111,8 +111,9 @@ impl AutocryptHeader { let mut acc = Vec::new(); // The primary key and the most recent selfsig. - acc.push(cert.primary_key().key().clone().into()); - cert.primary_key().bundle().self_signatures().iter().take(1) + let primary = cert.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. @@ -1101,9 +1102,9 @@ In the light of the Efail vulnerability I am asking myself if it's .expect("Failed to parse key material."); assert_eq!(&cert.fingerprint().to_string(), "3E88 77C8 7727 4692 9751 89F5 D03F 6F86 5226 FE8B"); - assert_eq!(cert.userids().bundles().len(), 1); + assert_eq!(cert.userids().len(), 1); assert_eq!(cert.keys().subkeys().count(), 1); - assert_eq!(cert.userids().bundles().next().unwrap().userid().value(), + assert_eq!(cert.userids().next().unwrap().userid().value(), &b"Testy McTestface <testy@example.org>"[..]); } } diff --git a/net/src/wkd.rs b/net/src/wkd.rs index 542689bb..fe7976a5 100644 --- a/net/src/wkd.rs +++ b/net/src/wkd.rs @@ -235,7 +235,7 @@ fn parse_body<S: AsRef<str>>(body: &[u8], email_address: S) let valid_certs: Vec<Cert> = certs.iter() // XXX: This filter could become a Cert method, but it adds other API // method to maintain - .filter(|cert| {cert.userids().bundles() + .filter(|cert| {cert.userids() .any(|uidb| if let Ok(Some(a)) = uidb.userid().email() { a == email_address @@ -344,7 +344,7 @@ pub fn insert<P, S, V>(base_path: P, domain: S, variant: V, let variant = variant.into().unwrap_or_default(); // First, check which UserIDs are in `domain`. - let addresses = cert.userids().bundles().filter_map(|uidb| { + let addresses = cert.userids().filter_map(|uidb| { uidb.userid().email().unwrap_or(None).and_then(|addr| { if EmailAddress::from(&addr).ok().map(|e| e.domain == domain) .unwrap_or(false) diff --git a/openpgp/examples/web-of-trust.rs b/openpgp/examples/web-of-trust.rs index ac0ef3db..5f9cbb1a 100644 --- a/openpgp/examples/web-of-trust.rs +++ b/openpgp/examples/web-of-trust.rs @@ -38,7 +38,7 @@ fn main() { match cert { Ok(cert) => { let keyid = cert.keyid(); - for uidb in cert.userids().bundles() { + for uidb in cert.userids() { for tps in uidb.certifications() { for issuer in tps.get_issuers() { println!("{}, {:?}, {}", diff --git a/openpgp/src/cert/bindings.rs b/openpgp/src/cert/bindings.rs index 8c08b622..a11a578a 100644 --- a/openpgp/src/cert/bindings.rs +++ b/openpgp/src/cert/bindings.rs @@ -173,7 +173,7 @@ impl UserID { /// let bob = bob.merge_packets(vec![certificate.into()])?; /// /// // Check that we have a certification on the userid. - /// assert_eq!(bob.userids().bundles().nth(0).unwrap() + /// assert_eq!(bob.userids().nth(0).unwrap() /// .certifications().len(), 1); /// # Ok(()) } pub fn certify<S, H, T>(&self, signer: &mut dyn Signer, cert: &Cert, @@ -315,7 +315,7 @@ impl UserAttribute { /// let bob = bob.merge_packets(vec![certificate.into()])?; /// /// // Check that we have a certification on the userid. - /// assert_eq!(bob.user_attributes().bundles().nth(0).unwrap() + /// assert_eq!(bob.user_attributes().nth(0).unwrap() /// .certifications().len(), /// 1); /// # Ok(()) } diff --git a/openpgp/src/cert/component_iter.rs b/openpgp/src/cert/component_iter.rs index 25a8db9f..ca1eafb6 100644 --- a/openpgp/src/cert/component_iter.rs +++ b/openpgp/src/cert/component_iter.rs @@ -116,7 +116,7 @@ impl<'a, C> Iterator for ValidComponentIter<'a, C> loop { let ca = ComponentAmalgamation::new(self.cert, self.iter.next()?); - t!("Considering component: {:?}", ca.bundle()); + t!("Considering component: {:?}", ca.component()); let vca = match ca.with_policy(self.policy, self.time) { Ok(vca) => vca, @@ -204,7 +204,6 @@ impl<'a, C> ValidComponentIter<'a, C> { /// true, /// } /// }) - /// .map(|ca| ca.bundle()) /// .collect::<Vec<_>>(); /// # Ok(()) /// # } diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 246ee744..23033ff9 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -341,7 +341,7 @@ use super::*; /// let mut acc = Vec::new(); /// /// // Primary key and related signatures. -/// let c = cert.primary_key().bundle(); +/// let c = cert.primary_key(); /// acc.push(c.key().clone().mark_role_primary().into()); /// for s in c.self_signatures() { acc.push(s.clone().into()) } /// for s in c.certifications() { acc.push(s.clone().into()) } @@ -349,7 +349,7 @@ use super::*; /// for s in c.other_revocations() { acc.push(s.clone().into()) } /// /// // UserIDs and related signatures. -/// for c in cert.userids().bundles() { +/// for c in cert.userids() { /// acc.push(c.userid().clone().into()); /// for s in c.self_signatures() { acc.push(s.clone().into()) } /// for s in c.certifications() { acc.push(s.clone().into()) } @@ -358,7 +358,7 @@ use super::*; /// } /// /// // UserAttributes and related signatures. -/// for c in cert.user_attributes().bundles() { +/// for c in cert.user_attributes() { /// acc.push(c.user_attribute().clone().into()); /// for s in c.self_signatures() { acc.push(s.clone().into()) } /// for s in c.certifications() { acc.push(s.clone().into()) } @@ -413,8 +413,8 @@ use super::*; /// match Cert::from_packet_parser(ppr) { /// Ok(cert) => { /// println!("Key: {}", cert.fingerprint()); -/// for binding in cert.userids().bundles() { -/// println!("User ID: {}", binding.userid()); +/// for uid in cert.userids() { +/// println!("User ID: {}", uid.userid()); /// } /// } /// Err(err) => { @@ -2616,7 +2616,7 @@ mod test { = cert.revoked(p, None)); assert_eq!(cert.user_attributes().count(), 1); - let ua = cert.user_attributes().bundles().nth(0).unwrap(); + let ua = cert.user_attributes().nth(0).unwrap(); if revoked { assert_match!(RevocationStatus::Revoked(_) = ua.revoked(p, t)); @@ -2845,7 +2845,7 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= // than one signature. let mut cmps = 0; - for uid in neal.userids().bundles() { + for uid in neal.userids() { for sigs in [ uid.self_signatures(), uid.certifications(), @@ -3147,7 +3147,7 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= .generate().unwrap(); assert_eq!(bob.userids().len(), 1); - let bob_userid_binding = bob.userids().bundles().nth(0).unwrap(); + let bob_userid_binding = bob.userids().nth(0).unwrap(); assert_eq!(bob_userid_binding.userid().value(), b"bob@bar.com"); let sig_template @@ -3170,7 +3170,7 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= // Make sure the certification is merged, and put in the right // place. assert_eq!(bob.userids().len(), 1); - let bob_userid_binding = bob.userids().bundles().nth(0).unwrap(); + let bob_userid_binding = bob.userids().nth(0).unwrap(); assert_eq!(bob_userid_binding.userid().value(), b"bob@bar.com"); // Canonicalizing Bob's cert without having Alice's key diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index f7e24d55..2666ccf7 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -522,7 +522,7 @@ impl<'a, I: Iterator<Item=Packet>> CertParser<'a, I> { /// # let some_keyid = KeyID::from_hex("C2B819056C652598").unwrap(); /// for certr in CertParser::from_packet_parser(ppr) /// .unvalidated_cert_filter(|cert, _| { - /// for component in cert.keys().bundles() { + /// for component in cert.keys() { /// if component.key().keyid() == some_keyid { /// return true; /// } diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index 5150eb29..d0ff1c3d 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -497,7 +497,7 @@ mod test { fn hash_verification() { fn check(cert: Cert) -> (usize, usize, usize) { let mut userid_sigs = 0; - for (i, binding) in cert.userids().bundles().enumerate() { + for (i, binding) in cert.userids().enumerate() { for selfsig in binding.self_signatures() { let h = Signature::hash_userid_binding( selfsig, @@ -513,16 +513,16 @@ mod test { } } let mut ua_sigs = 0; - for (i, binding) in cert.user_attributes().bundles().enumerate() + for (i, a) in cert.user_attributes().enumerate() { - for selfsig in binding.self_signatures() { + for selfsig in a.self_signatures() { let h = Signature::hash_user_attribute_binding( selfsig, cert.primary_key().key(), - binding.user_attribute()).unwrap(); + a.user_attribute()).unwrap(); if &h[..2] != selfsig.digest_prefix() { eprintln!("{:?}: {:?} / {:?}", - i, binding.user_attribute(), selfsig); + i, a.user_attribute(), selfsig); eprintln!(" Hash: {:?}", h); } assert_eq!(&h[..2], selfsig.digest_prefix()); diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 814e1557..bd8889f2 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1401,13 +1401,12 @@ mod test { .unwrap(); let test2 = Cert::from_bytes( crate::tests::key("test2-signed-by-test1.pgp")).unwrap(); - let uid_binding = - test2.userids().with_policy(p, None).nth(0).unwrap().bundle(); - let cert = &uid_binding.certifications()[0]; + let uid = test2.userids().with_policy(p, None).nth(0).unwrap(); + let cert = &uid.certifications()[0]; cert.verify_userid_binding(cert_key1, test2.primary_key().key(), - uid_binding.userid()).unwrap(); + uid.userid()).unwrap(); } #[test] diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index 76019236..cc056d5f 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -1344,7 +1344,7 @@ mod test { .add_userid("Alice") .generate()?; - let algo = cert.primary_key().bundle() + let algo = cert.primary_key() .binding_signature(&DEFAULT, None).unwrap().hash_algo(); eprintln!("{:?}", algo); @@ -1369,7 +1369,7 @@ mod test { // Reject the hash algorithm unconditionally. let mut reject : StandardPolicy = StandardPolicy::new(); reject.reject_hash(algo); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_none()); assert_match!(RevocationStatus::NotAsFarAsWeKnow = cert_revoked.revoked(&reject, None)); @@ -1380,7 +1380,7 @@ mod test { algo, SystemTime::now() + Duration::from_secs(SECS_IN_YEAR), SystemTime::now() + Duration::from_secs(SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_some()); assert_match!(RevocationStatus::Revoked(_) = cert_revoked.revoked(&reject, None)); @@ -1391,7 +1391,7 @@ mod test { algo, SystemTime::now() - Duration::from_secs(SECS_IN_YEAR), SystemTime::now() - Duration::from_secs(SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_none()); assert_match!(RevocationStatus::NotAsFarAsWeKnow = cert_revoked.revoked(&reject, None)); @@ -1403,7 +1403,7 @@ mod test { algo, SystemTime::now() - Duration::from_secs(SECS_IN_YEAR), SystemTime::now() + Duration::from_secs(SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_none()); assert_match!(RevocationStatus::Revoked(_) = cert_revoked.revoked(&reject, None)); @@ -1420,7 +1420,7 @@ mod test { (algo_u8 + 1).into(), SystemTime::now() - Duration::from_secs(SECS_IN_YEAR), SystemTime::now() - Duration::from_secs(SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_some()); assert_match!(RevocationStatus::Revoked(_) = cert_revoked.revoked(&reject, None)); @@ -1433,7 +1433,7 @@ mod test { algo, SystemTime::UNIX_EPOCH - Duration::from_secs(SECS_IN_YEAR), SystemTime::UNIX_EPOCH - Duration::from_secs(SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_none()); assert_match!(RevocationStatus::NotAsFarAsWeKnow = cert_revoked.revoked(&reject, None)); @@ -1446,7 +1446,7 @@ mod test { algo, SystemTime::UNIX_EPOCH + Duration::from_secs(500 * SECS_IN_YEAR), SystemTime::UNIX_EPOCH + Duration::from_secs(500 * SECS_IN_YEAR)); - assert!(cert.primary_key().bundle() + assert!(cert.primary_key() .binding_signature(&reject, None).is_some()); assert_match!(RevocationStatus::Revoked(_) = cert_revoked.revoked(&reject, None)); diff --git a/openpgp/src/serialize/cert.rs b/openpgp/src/serialize/cert.rs index f973c1c8..1cb606dd 100644 --- a/openpgp/src/serialize/cert.rs +++ b/openpgp/src/serialize/cert.rs @@ -38,7 +38,7 @@ impl Cert { fn serialize_common(&self, o: &mut dyn std::io::Write, export: bool) -> Result<()> { - let primary = self.primary_key().bundle(); + let primary = self.primary_key(); PacketRef::PublicKey(primary.key().mark_role_primary_ref()) .serialize(o)?; @@ -69,7 +69,7 @@ impl Cert { serialize_sig(o, s)?; } - for u in self.userids().bundles() { + for u in self.userids() { if export && ! u.self_signatures().iter().chain(u.self_revocations()).any( |s| s.exportable().is_ok()) { @@ -92,7 +92,7 @@ impl Cert { } } - for u in self.user_attributes().bundles() { + for u in self.user_attributes() { if export && ! u.self_signatures().iter().chain(u.self_revocations()).any( |s| s.exportable().is_ok()) { @@ -173,7 +173,7 @@ impl Cert { impl SerializeInto for Cert { fn serialized_len(&self) -> usize { let mut l = 0; - let primary = self.primary_key().bundle(); + let primary = self.primary_key(); l += PacketRef::PublicKey(primary.key().mark_role_primary_ref()) .serialized_len(); @@ -190,7 +190,7 @@ impl SerializeInto for Cert { l += PacketRef::Signature(s).serialized_len(); } - for u in self.userids().bundles() { + for u in self.userids() { l += PacketRef::UserID(u.userid()).serialized_len(); for s in u.self_revocations() { @@ -207,7 +207,7 @@ impl SerializeInto for Cert { } } - for u in self.user_attributes().bundles() { + for u in self.user_attributes() { l += PacketRef::UserAttribute(u.user_attribute()).serialized_len(); for s in u.self_revocations() { @@ -403,7 +403,7 @@ impl<'a> TSK<'a> { } }; - let primary = self.cert.primary_key().bundle(); + let primary = self.cert.primary_key(); serialize_key(o, primary.key().mark_role_primary_ref().into(), Tag::PublicKey, Tag::SecretKey)?; @@ -420,7 +420,7 @@ impl<'a> TSK<'a> { serialize_sig(o, s)?; } - for u in self.cert.userids().bundles() { + for u in self.cert.userids() { if export && ! u.self_signatures().iter().chain(u.self_revocations()).any( |s| s.exportable().is_ok()) { @@ -443,7 +443,7 @@ impl<'a> TSK<'a> { } } - for u in self.cert.user_attributes().bundles() { + for u in self.cert.user_attributes() { if export && ! u.self_signatures().iter().chain(u.self_revocations()).any( |s| s.exportable().is_ok()) { @@ -558,7 +558,7 @@ impl<'a> SerializeInto for TSK<'a> { packet.serialized_len() }; - let primary = self.cert.primary_key().bundle(); + let primary = self.cert.primary_key(); l += serialized_len_key(primary.key().mark_role_primary_ref().into(), Tag::PublicKey, Tag::SecretKey); @@ -575,7 +575,7 @@ impl<'a> SerializeInto for TSK<'a> { l += PacketRef::Signature(s).serialized_len(); } - for u in self.cert.userids().bundles() { + for u in self.cert.userids() { l += PacketRef::UserID(u.userid()).serialized_len(); for s in u.self_revocations() { @@ -592,7 +592,7 @@ impl<'a> SerializeInto for TSK<'a> { } } - for u in self.cert.user_attributes().bundles() { + for u in self.cert.user_attributes() { l += PacketRef::UserAttribute(u.user_attribute()).serialized_len(); for s in u.self_revocations() { diff --git a/openpgp/src/serialize/cert_armored.rs b/openpgp/src/serialize/cert_armored.rs index 5ac09bfb..47093dfb 100644 --- a/openpgp/src/serialize/cert_armored.rs +++ b/openpgp/src/serialize/cert_armored.rs @@ -32,7 +32,7 @@ impl Cert { let length_value = armor::LINE_LENGTH - "Comment: ".len(); // Create a header per userid. - let mut headers: Vec<String> = self.userids().bundles() + let mut headers: Vec<String> = self.userids() // Ignore revoked userids. .filter_map(|uidb| { if let RevocationStatus::Revoked(_) = uidb.revoked(&p, None) { diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index 3f499fa9..7684539c 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -150,7 +150,7 @@ fn inspect_cert(policy: &dyn Policy, writeln!(output)?; } - for uidb in cert.userids().bundles() { + for uidb in cert.userids() { writeln!(output, " UserID: {}", uidb.userid())?; inspect_revocation(output, "", uidb.revoked(policy, None))?; if let Some(sig) = uidb.binding_signature(policy, None) { @@ -166,7 +166,7 @@ fn inspect_cert(policy: &dyn Policy, writeln!(output)?; } - for uab in cert.user_attributes().bundles() { + for uab in cert.user_attributes() { writeln!(output, " UserID: {:?}", uab.user_attribute())?; inspect_revocation(output, "", uab.revoked(policy, None))?; if let Some(sig) = uab.binding_signature(policy, None) { @@ -213,7 +213,7 @@ fn inspect_key(policy: &dyn Policy, -> Result<()> { let key = ka.key(); - let binding = ka.bundle(); + let bundle = ka.bundle(); let vka = match ka.with_policy(policy, None) { Ok(vka) => { if let Err(e) = vka.alive() { @@ -250,7 +250,7 @@ fn inspect_key(policy: &dyn Policy, writeln!(output, "{} Key flags: {}", indent, flags)?; } } - inspect_certifications(output, binding.certifications(), + inspect_certifications(output, bundle.certifications(), print_certifications)?; Ok(()) |