diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-01-06 22:36:01 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-01-06 23:01:29 +0100 |
commit | fc6ded10e255a2fc4423e7f360951a2f3eed5d6f (patch) | |
tree | b478c144171354bbf518a0d94d371a75139a94b4 /openpgp | |
parent | fe16487556c2b4d16400515aea8c448b0890e74c (diff) |
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.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/examples/decrypt-with.rs | 18 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 12 |
2 files changed, 10 insertions, 20 deletions
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); } } } diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 88c301ea..cabe130b 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -988,9 +988,7 @@ impl<'a> Encryptor<'a> { /// // Build a vector of recipients to hand to Encryptor. /// let recipient = /// cert.keys().policy(None).alive().revoked(false) - /// .key_flags(KeyFlags::default() - /// .set_storage_encryption(true) - /// .set_transport_encryption(true)) + /// .for_storage_encryption().for_transport_encryption() /// .map(|ka| ka.key().into()) /// .nth(0).unwrap(); /// @@ -1643,7 +1641,6 @@ mod test { use std::cmp; - use crate::types::KeyFlags; use crate::parse::{ stream::{ Decryptor, @@ -1678,8 +1675,7 @@ mod test { where D: FnMut(SymmetricAlgorithm, &SessionKey) -> Result<()> { let mut keypair = self.tsk.keys().policy(None) - .key_flags( - KeyFlags::default().set_transport_encryption(true)) + .for_transport_encryption() .map(|ka| ka.key()).next().unwrap() .clone().mark_parts_secret().unwrap() .into_keypair().unwrap(); @@ -1706,9 +1702,7 @@ mod test { let m = Message::new(&mut msg); let recipient = tsk .keys().policy(None) - .key_flags(KeyFlags::default() - .set_storage_encryption(true) - .set_transport_encryption(true)) + .for_storage_encryption().for_transport_encryption() .nth(0).unwrap().key().into(); let encryptor = Encryptor::for_recipient(m, recipient) .aead_algo(AEADAlgorithm::EAX) |