From 77126481d2ce21d70869004d784ee0de6b5062bf Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 19 Feb 2019 16:16:19 +0100 Subject: openpgp: Return &[Signature] from TPK accessors. - Fixes #196. --- examples/guide-exploring-openpgp.rs | 8 ++--- openpgp/src/packet/signature/mod.rs | 2 +- openpgp/src/tpk/mod.rs | 68 ++++++++++++++++++------------------- tool/src/commands/inspect.rs | 10 +++--- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/guide-exploring-openpgp.rs b/examples/guide-exploring-openpgp.rs index 409475ef..358c1922 100644 --- a/examples/guide-exploring-openpgp.rs +++ b/examples/guide-exploring-openpgp.rs @@ -55,15 +55,15 @@ fn main() { for (i, u) in tpk.userids().enumerate() { println!("{}: UID: {}, {} self-signature(s), {} certification(s)", i, u.userid(), - u.selfsigs().count(), - u.certifications().count()); + u.selfsigs().len(), + u.certifications().len()); } // List subkeys. for (i, s) in tpk.subkeys().enumerate() { println!("{}: Fingerprint: {}, {} self-signature(s), {} certification(s)", i, s.subkey().fingerprint(), - s.selfsigs().count(), - s.certifications().count()); + s.selfsigs().len(), + s.certifications().len()); } } diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index af1af7f1..35f75dae 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1103,7 +1103,7 @@ mod test { let test2 = TPK::from_file( path_to("keys/test2-signed-by-test1.pgp")).unwrap(); let uid_binding = &test2.primary_key_signature_full().unwrap().0.unwrap(); - let cert = uid_binding.certifications().next().unwrap(); + let cert = &uid_binding.certifications()[0]; assert_eq!(cert.verify_userid_binding(cert_key1, test2.primary(), uid_binding.userid()).ok(), Some(true)); } diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index 1b49aa8b..61bb388f 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -566,29 +566,29 @@ impl SubkeyBinding { /// /// All self-signatures have been validated, and the newest /// self-signature is first. - pub fn selfsigs(&self) -> slice::Iter { - self.selfsigs.iter() + pub fn selfsigs(&self) -> &[Signature] { + &self.selfsigs } /// Any third-party certifications. /// /// The signatures have *not* been validated. - pub fn certifications(&self) -> slice::Iter { - self.certifications.iter() + pub fn certifications(&self) -> &[Signature] { + &self.certifications } /// Revocations issued by the key itself. /// /// The revocations have been validated, and the newest is first. - pub fn self_revocations(&self) -> slice::Iter { - self.self_revocations.iter() + pub fn self_revocations(&self) -> &[Signature] { + &self.self_revocations } /// Revocations issued by other keys. /// /// The revocations have *not* been validated. - pub fn other_revocations(&self) -> slice::Iter { - self.other_revocations.iter() + pub fn other_revocations(&self) -> &[Signature] { + &self.other_revocations } /// Returns the subkey's revocation status. @@ -685,29 +685,29 @@ impl UserIDBinding { /// /// The self-signatures have been validated, and the newest /// self-signature is first. - pub fn selfsigs(&self) -> slice::Iter { - self.selfsigs.iter() + pub fn selfsigs(&self) -> &[Signature] { + &self.selfsigs } /// Any third-party certifications. /// /// The signatures have *not* been validated. - pub fn certifications(&self) -> slice::Iter { - self.certifications.iter() + pub fn certifications(&self) -> &[Signature] { + &self.certifications } /// Revocations issued by the key itself. /// /// The revocations have been validated, and the newest is first. - pub fn self_revocations(&self) -> slice::Iter { - self.self_revocations.iter() + pub fn self_revocations(&self) -> &[Signature] { + &self.self_revocations } /// Revocations issued by other keys. /// /// The revocations have *not* been validated. - pub fn other_revocations(&self) -> slice::Iter { - self.other_revocations.iter() + pub fn other_revocations(&self) -> &[Signature] { + &self.other_revocations } /// Returns the user id's revocation status at time `t`. If `t` is None, @@ -795,29 +795,29 @@ impl UserAttributeBinding { /// /// The self-signatures have been validated, and the newest /// self-signature is first. - pub fn selfsigs(&self) -> slice::Iter { - self.selfsigs.iter() + pub fn selfsigs(&self) -> &[Signature] { + &self.selfsigs } /// Any third-party certifications. /// /// The signatures have *not* been validated. - pub fn certifications(&self) -> slice::Iter { - self.certifications.iter() + pub fn certifications(&self) -> &[Signature] { + &self.certifications } /// Revocations issued by the key itself. /// /// The revocations have been validated, and the newest is first. - pub fn self_revocations(&self) -> slice::Iter { - self.self_revocations.iter() + pub fn self_revocations(&self) -> &[Signature] { + &self.self_revocations } /// Revocations issued by other keys. /// /// The revocations have *not* been validated. - pub fn other_revocations(&self) -> slice::Iter { - self.other_revocations.iter() + pub fn other_revocations(&self) -> &[Signature] { + &self.other_revocations } /// Returns the `UserAttribute`'s revocation status. @@ -1444,29 +1444,29 @@ impl TPK { /// /// All self-signatures have been validated, and the newest /// self-signature is first. - pub fn selfsigs(&self) -> slice::Iter { - self.primary_selfsigs.iter() + pub fn selfsigs(&self) -> &[Signature] { + &self.primary_selfsigs } /// Any third-party certifications. /// /// The signatures have *not* been validated. - pub fn certifications(&self) -> slice::Iter { - self.primary_certifications.iter() + pub fn certifications(&self) -> &[Signature] { + &self.primary_certifications } /// Revocations issued by the key itself.primary_ /// /// The revocations have been validated, and the newest is first. - pub fn self_revocations(&self) -> slice::Iter { - self.primary_self_revocations.iter() + pub fn self_revocations(&self) -> &[Signature] { + &self.primary_self_revocations } /// Revocations issued by other keys. /// /// The revocations have *not* been validated. - pub fn other_revocations(&self) -> slice::Iter { - self.primary_other_revocations.iter() + pub fn other_revocations(&self) -> &[Signature] { + &self.primary_other_revocations } /// Returns the TPK's revocation status. @@ -1755,7 +1755,7 @@ impl TPK { None => Vec::default(), Some((None, sig)) => vec![sig], Some((Some(uid), sig)) => - uid.selfsigs().chain(iter::once(sig)).collect(), + uid.selfsigs().iter().chain(iter::once(sig)).collect(), }; let prim = Some(&self.primary) .filter(|k| is_usable(k, prim_sigs.iter(), now, &cap)); @@ -1763,7 +1763,7 @@ impl TPK { .iter() .filter(|sb| { sb.revoked(None) == RevocationStatus::NotAsFarAsWeKnow && - is_usable(sb.subkey(), sb.selfsigs(), now, &cap) + is_usable(sb.subkey(), sb.selfsigs().iter(), now, &cap) }) .map(|sb| sb.subkey()) .collect::>(); diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index ae5a4f81..4a09dcab 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -123,7 +123,7 @@ fn inspect_tpk(output: &mut io::Write, tpk: &openpgp::TPK, writeln!(output, " Fingerprint: {}", tpk.fingerprint())?; inspect_revocation(output, "", tpk.revoked(None))?; inspect_key(output, "", tpk.primary(), tpk.primary_key_signature(), - &tpk.certifications().collect::>()[..], + tpk.certifications(), print_keygrips, print_certifications)?; writeln!(output)?; @@ -131,7 +131,7 @@ fn inspect_tpk(output: &mut io::Write, tpk: &openpgp::TPK, writeln!(output, " Subkey: {}", skb.subkey().fingerprint())?; inspect_revocation(output, "", skb.revoked(None))?; inspect_key(output, "", skb.subkey(), skb.binding_signature(), - &skb.certifications().collect::>()[..], + skb.certifications(), print_keygrips, print_certifications)?; writeln!(output)?; } @@ -147,7 +147,7 @@ fn inspect_tpk(output: &mut io::Write, tpk: &openpgp::TPK, } } inspect_certifications(output, - &uidb.certifications().collect::>()[..], + uidb.certifications(), print_certifications)?; writeln!(output)?; } @@ -159,7 +159,7 @@ fn inspect_key(output: &mut io::Write, indent: &str, key: &openpgp::packet::Key, binding_signature: Option<&openpgp::packet::Signature>, - certs: &[&openpgp::packet::Signature], + certs: &[openpgp::packet::Signature], print_keygrips: bool, print_certifications: bool) -> Result<()> { @@ -263,7 +263,7 @@ fn inspect_signatures(output: &mut io::Write, } fn inspect_certifications(output: &mut io::Write, - certs: &[&openpgp::packet::Signature], + certs: &[openpgp::packet::Signature], print_certifications: bool) -> Result<()> { if print_certifications { for sig in certs { -- cgit v1.2.3