diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-15 17:52:00 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-18 14:24:48 +0100 |
commit | 6bf3deb539ac91bba56efa57127c6c0567cf161c (patch) | |
tree | a94628796020071e2210b9c6a8d5c57b067e696e /tool/src/commands | |
parent | 94c64d7a831227888c2ab6b5fe9ec0c29781caec (diff) |
openpgp: Use Cert::keys instead of Cert::subkeys.
Diffstat (limited to 'tool/src/commands')
-rw-r--r-- | tool/src/commands/decrypt.rs | 33 | ||||
-rw-r--r-- | tool/src/commands/inspect.rs | 10 |
2 files changed, 13 insertions, 30 deletions
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs index 325a657d..4c378a34 100644 --- a/tool/src/commands/decrypt.rs +++ b/tool/src/commands/decrypt.rs @@ -44,40 +44,23 @@ impl<'a> Helper<'a> { let mut identities: HashMap<KeyID, Fingerprint> = HashMap::new(); let mut hints: HashMap<KeyID, String> = HashMap::new(); for tsk in secrets { - fn can_encrypt<R, P>(_: &Key<P, R>, sig: Option<&Signature>) -> bool - where P: key::KeyParts, - R: key::KeyRole, - { - if let Some(sig) = sig { - sig.key_flags().for_storage_encryption() - || sig.key_flags().for_transport_encryption() - } else { - false - } - } - let hint = match tsk.userids().nth(0) { Some(uid) => format!("{} ({})", uid.userid(), KeyID::from(tsk.fingerprint())), None => format!("{}", KeyID::from(tsk.fingerprint())), }; - if can_encrypt(tsk.primary(), tsk.primary_key_signature(None)) { - let id: KeyID = tsk.fingerprint().into(); - keys.insert(id.clone(), tsk.primary().clone().into()); + for ka in tsk.keys() + // XXX: Should use the message's creation time that we do not know. + .policy(None) + .for_transport_encryption().for_storage_encryption() + .secret() + { + let id: KeyID = ka.key().fingerprint().into(); + keys.insert(id.clone(), ka.key().clone().into()); identities.insert(id.clone(), tsk.fingerprint()); hints.insert(id, hint.clone()); } - - for skb in tsk.subkeys() { - let key = skb.key(); - if can_encrypt(key, skb.binding_signature(None)) { - let id: KeyID = key.fingerprint().into(); - keys.insert(id.clone(), key.clone().into()); - identities.insert(id.clone(), tsk.fingerprint()); - hints.insert(id, hint.clone()); - } - } } Helper { diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index 8849b0ad..417ded93 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -138,11 +138,11 @@ fn inspect_cert(output: &mut dyn io::Write, cert: &openpgp::Cert, print_keygrips, print_certifications)?; writeln!(output)?; - for skb in cert.subkeys() { - writeln!(output, " Subkey: {}", skb.key().fingerprint())?; - inspect_revocation(output, "", skb.revoked(None))?; - inspect_key(output, "", skb.key(), skb.binding_signature(None), - skb.certifications(), + for ka in cert.keys().policy(None).skip(1) { + writeln!(output, " Subkey: {}", ka.key().fingerprint())?; + inspect_revocation(output, "", ka.revoked())?; + inspect_key(output, "", ka.key(), ka.binding_signature(), + ka.component().certifications(), print_keygrips, print_certifications)?; writeln!(output)?; } |