summaryrefslogtreecommitdiffstats
path: root/openpgp/examples/decrypt-with.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-08-29 12:54:18 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-08-29 17:11:58 +0200
commit5629e9625f821f614580a401e16eb41229c8528d (patch)
tree98c94befe444dafcd98767bbe3b21f4470a6f3b6 /openpgp/examples/decrypt-with.rs
parent94b27d574435330784a45d77cee825ca4fec8ffa (diff)
openpgp: Make the keys() iterator more useful.
- Return the corresponding (binding-)signature along with the keys.
Diffstat (limited to 'openpgp/examples/decrypt-with.rs')
-rw-r--r--openpgp/examples/decrypt-with.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs
index 4bcd4e9c..795185b4 100644
--- a/openpgp/examples/decrypt-with.rs
+++ b/openpgp/examples/decrypt-with.rs
@@ -30,9 +30,14 @@ pub fn main() {
openpgp::Reader::from_file(f)
.expect("Failed to open file"))
.expect("Failed to read key");
- for key in tsk.keys() {
- // XXX this is cheating, we just add all keys, even if
- // they should not be used for encryption
+ for (sig, key) in tsk.keys() {
+ if ! sig.map(|s| s.key_flags().can_encrypt_at_rest()
+ || s.key_flags().can_encrypt_for_transport())
+ .unwrap_or(false)
+ {
+ continue;
+ }
+
keys.insert(key.fingerprint().to_keyid(), key.clone());
}
}