summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-01-04 17:26:55 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-01-04 17:26:55 +0100
commita01b070c9599be7f2be4dfaa25dd9ff01efe8a57 (patch)
treedfc18bcda1c076e02736709df5c0c8db6b13b844
parent81e8f7869ea40f0ca02eef16ced70b8339eca7c3 (diff)
openpgp: Change KeyIter::key_flags to not require an owned KeyFlags.
- Instead of taking a `KeyFlags`, change `KeyIter::key_flags` to take a `Borrow<KeyFlags>`. - Update callers to pass a reference instead of cloning.
-rw-r--r--openpgp/examples/encrypt-for.rs2
-rw-r--r--openpgp/src/cert/bindings.rs2
-rw-r--r--openpgp/src/cert/keyiter.rs10
-rw-r--r--tool/src/commands/mod.rs4
4 files changed, 11 insertions, 7 deletions
diff --git a/openpgp/examples/encrypt-for.rs b/openpgp/examples/encrypt-for.rs
index 93eba5b5..c76c7a1b 100644
--- a/openpgp/examples/encrypt-for.rs
+++ b/openpgp/examples/encrypt-for.rs
@@ -38,7 +38,7 @@ fn main() {
let mut recipients =
certs.iter()
.flat_map(|cert| {
- cert.keys().alive().revoked(false).key_flags(mode.clone())
+ cert.keys().alive().revoked(false).key_flags(&mode)
})
.map(|ka| ka.key().into())
.collect::<Vec<_>>();
diff --git a/openpgp/src/cert/bindings.rs b/openpgp/src/cert/bindings.rs
index 70e80983..52cc9527 100644
--- a/openpgp/src/cert/bindings.rs
+++ b/openpgp/src/cert/bindings.rs
@@ -37,7 +37,7 @@ impl<P: key::KeyParts> Key<P, key::SubordinateRole> {
/// // Let's add an encryption subkey.
/// let flags = KeyFlags::default().set_storage_encryption(true);
/// assert_eq!(cert.keys().alive().revoked(false)
- /// .key_flags(flags.clone()).count(),
+ /// .key_flags(&flags).count(),
/// 0);
///
/// // Generate a subkey and a binding signature.
diff --git a/openpgp/src/cert/keyiter.rs b/openpgp/src/cert/keyiter.rs
index a433e627..7bb59153 100644
--- a/openpgp/src/cert/keyiter.rs
+++ b/openpgp/src/cert/keyiter.rs
@@ -1,5 +1,6 @@
use std::fmt;
use std::convert::TryInto;
+use std::borrow::Borrow;
use crate::{
RevocationStatus,
@@ -254,11 +255,14 @@ impl<'a, P: 'a + key::KeyParts, R: 'a + key::KeyRole> KeyIter<'a, P, R>
/// [`Iterator::filter`].
///
/// [`Iterator::filter`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter
- pub fn key_flags(mut self, flags: KeyFlags) -> Self {
+ pub fn key_flags<F>(mut self, flags: F) -> Self
+ where F: Borrow<KeyFlags>
+ {
+ let flags = flags.borrow();
if let Some(flags_old) = self.flags {
- self.flags = Some(&flags | &flags_old);
+ self.flags = Some(flags | &flags_old);
} else {
- self.flags = Some(flags);
+ self.flags = Some(flags.clone());
}
self
}
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs
index b4ea9037..cde1e664 100644
--- a/tool/src/commands/mod.rs
+++ b/tool/src/commands/mod.rs
@@ -112,8 +112,8 @@ pub fn encrypt(mapping: &mut store::Mapping,
let mut recipient_subkeys: Vec<Recipient> = Vec::new();
for cert in certs.iter() {
let mut count = 0;
- for key in cert.keys().alive().revoked(false).
- key_flags(mode.clone()).map(|ka| ka.key())
+ for key in cert.keys().alive().revoked(false)
+ .key_flags(&mode).map(|ka| ka.key())
{
recipient_subkeys.push(key.into());
count += 1;