summaryrefslogtreecommitdiffstats
path: root/openpgp/examples/generate-encrypt-decrypt.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-11-20 14:11:29 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-11-20 14:11:53 +0100
commit13c437470cc7377d7b761b5bb9b8d4efb0ba385e (patch)
treedce09461d71932949024eae22d23b7189ab203ab /openpgp/examples/generate-encrypt-decrypt.rs
parentefe767fc4e48ef2a53e7f8cb7e44d46d884b9694 (diff)
openpgp: Use the builder pattern for stream::Encryptor.
- Fixes #375.
Diffstat (limited to 'openpgp/examples/generate-encrypt-decrypt.rs')
-rw-r--r--openpgp/examples/generate-encrypt-decrypt.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs
index f8eeb05f..d20219ab 100644
--- a/openpgp/examples/generate-encrypt-decrypt.rs
+++ b/openpgp/examples/generate-encrypt-decrypt.rs
@@ -41,7 +41,7 @@ fn generate() -> openpgp::Result<openpgp::TPK> {
fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::TPK)
-> openpgp::Result<()> {
// Build a vector of recipients to hand to Encryptor.
- let recipients =
+ let mut recipients =
recipient.keys_valid()
.key_flags(KeyFlags::default()
.set_encrypt_at_rest(true)
@@ -53,10 +53,12 @@ fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::TPK)
let message = Message::new(sink);
// We want to encrypt a literal data packet.
- let encryptor = Encryptor::new(message,
- &[], // No symmetric encryption.
- &recipients,
- None, None)?;
+ 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");
// Emit a literal data packet.
let mut literal_writer = LiteralWriter::new(encryptor).build()?;