summaryrefslogtreecommitdiffstats
path: root/openpgp/examples
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-04-03 18:22:55 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-04-03 18:32:03 +0200
commita9ca727cab50c0c91098a7ef8aea79f5f62a1f5c (patch)
treee7122be749e5b3b26ee96969f4f9e8347fe6532b /openpgp/examples
parent6494b37775ada713e8ff139ee40c5accdfcaf16a (diff)
openpgp: Unawkwardify the streaming encryptor.
Diffstat (limited to 'openpgp/examples')
-rw-r--r--openpgp/examples/encrypt-for.rs10
-rw-r--r--openpgp/examples/generate-encrypt-decrypt.rs10
-rw-r--r--openpgp/examples/pad.rs10
3 files changed, 9 insertions, 21 deletions
diff --git a/openpgp/examples/encrypt-for.rs b/openpgp/examples/encrypt-for.rs
index ef6486eb..d8c3affd 100644
--- a/openpgp/examples/encrypt-for.rs
+++ b/openpgp/examples/encrypt-for.rs
@@ -38,7 +38,7 @@ fn main() {
}).collect();
// Build a vector of recipients to hand to Encryptor.
- let mut recipients =
+ let recipients =
certs.iter()
.flat_map(|cert| {
cert.keys()
@@ -57,12 +57,8 @@ fn main() {
let message = Message::new(&mut sink);
// We want to encrypt a literal data packet.
- let mut encryptor = Encryptor::for_recipient(
- message, recipients.pop().expect("No encryption key found"));
- for r in recipients {
- encryptor = encryptor.add_recipient(r)
- }
- let encryptor = encryptor.build().expect("Failed to create encryptor");
+ let encryptor = Encryptor::for_recipients(message, recipients)
+ .build().expect("Failed to create encryptor");
let mut literal_writer = LiteralWriter::new(encryptor).build()
.expect("Failed to create literal writer");
diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs
index 4b0d3ff2..a5a49f0b 100644
--- a/openpgp/examples/generate-encrypt-decrypt.rs
+++ b/openpgp/examples/generate-encrypt-decrypt.rs
@@ -48,7 +48,7 @@ fn encrypt(p: &dyn Policy, sink: &mut dyn Write, plaintext: &str,
-> openpgp::Result<()>
{
// Build a vector of recipients to hand to Encryptor.
- let mut recipients =
+ let recipients =
recipient.keys().with_policy(p, None).alive().revoked(false)
.for_transport_encryption()
.map(|ka| ka.key().into())
@@ -58,12 +58,8 @@ fn encrypt(p: &dyn Policy, sink: &mut dyn Write, plaintext: &str,
let message = Message::new(sink);
// We want to encrypt a literal data packet.
- let mut encryptor = Encryptor::for_recipient(
- message, recipients.pop().expect("No encryption key found"));
- for r in recipients {
- encryptor = encryptor.add_recipient(r)
- }
- let encryptor = encryptor.build().expect("Failed to create encryptor");
+ let encryptor = Encryptor::for_recipients(message, recipients)
+ .build()?;
// Emit a literal data packet.
let mut literal_writer = LiteralWriter::new(encryptor).build()?;
diff --git a/openpgp/examples/pad.rs b/openpgp/examples/pad.rs
index 4a762b58..8e5915a8 100644
--- a/openpgp/examples/pad.rs
+++ b/openpgp/examples/pad.rs
@@ -38,7 +38,7 @@ fn main() {
}).collect();
// Build a vector of recipients to hand to Encryptor.
- let mut recipients = certs
+ let recipients = certs
.iter()
.flat_map(|cert| {
cert.keys()
@@ -57,12 +57,8 @@ fn main() {
let message = Message::new(&mut sink);
// We want to encrypt a literal data packet.
- let mut encryptor = Encryptor::for_recipient(
- message, recipients.pop().expect("No encryption key found"));
- for r in recipients {
- encryptor = encryptor.add_recipient(r)
- }
- let encryptor = encryptor.build().expect("Failed to create encryptor");
+ let encryptor = Encryptor::for_recipients(message, recipients)
+ .build().expect("Failed to create encryptor");
let padder = Padder::new(encryptor, padme)
.expect("Failed to create padder");