From fc6ded10e255a2fc4423e7f360951a2f3eed5d6f Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Mon, 6 Jan 2020 22:36:01 +0100 Subject: openpgp: Use KeyAmalgamation::for_xxx instead of building a KeyFlags - Use the convenient functions KeyAmalgamation::for_storage_encryption, KeyAmalgamation::for_transport_encryption, etc., instead of building up a KeyFlags and then calling KeyAmalgamation::key_flags. - This pattern requires less boilerplate. --- openpgp/examples/decrypt-with.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'openpgp/examples') diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs index b3feceb6..c28dbe1c 100644 --- a/openpgp/examples/decrypt-with.rs +++ b/openpgp/examples/decrypt-with.rs @@ -58,18 +58,14 @@ impl Helper { // Map (sub)KeyIDs to secrets. let mut keys = HashMap::new(); for cert in certs { - for ka in cert.keys().policy(None) { - if ka.binding_signature(None) - .map(|s| (s.key_flags().for_storage_encryption() - || s.key_flags().for_transport_encryption())) - .unwrap_or(false) + for ka in cert.keys().policy(None) + .for_storage_encryption().for_transport_encryption() + { + // This only works for unencrypted secret keys. + if let Ok(keypair) = + ka.key().clone().mark_parts_secret().unwrap().into_keypair() { - // This only works for unencrypted secret keys. - if let Ok(keypair) = - ka.key().clone().mark_parts_secret().unwrap().into_keypair() - { - keys.insert(ka.key().keyid(), keypair); - } + keys.insert(ka.key().keyid(), keypair); } } } -- cgit v1.2.3