summaryrefslogtreecommitdiffstats
path: root/tool
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 /tool
parentefe767fc4e48ef2a53e7f8cb7e44d46d884b9694 (diff)
openpgp: Use the builder pattern for stream::Encryptor.
- Fixes #375.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/commands/mod.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs
index f164e3a2..4450c8d6 100644
--- a/tool/src/commands/mod.rs
+++ b/tool/src/commands/mod.rs
@@ -105,6 +105,11 @@ pub fn encrypt(mapping: &mut store::Mapping,
}))?.into());
}
+ if tpks.len() + passwords.len() == 0 {
+ return Err(failure::format_err!(
+ "Neither recipient nor password given"));
+ }
+
let mut signers = get_signing_keys(&signers)?;
// Build a vector of references to hand to Signer.
@@ -128,10 +133,19 @@ pub fn encrypt(mapping: &mut store::Mapping,
let message = Message::new(output);
// We want to encrypt a literal data packet.
- let mut sink = Encryptor::new(message,
- passwords,
- recipient_subkeys,
- None, None)
+ let mut encryptor = if let Some(p) = passwords.pop() {
+ Encryptor::with_password(message, p)
+ } else {
+ Encryptor::for_recipient(message, recipient_subkeys.pop().unwrap())
+ };
+ for p in passwords {
+ encryptor = encryptor.add_password(p);
+ }
+ for r in recipient_subkeys {
+ encryptor = encryptor.add_recipient(r);
+ }
+
+ let mut sink = encryptor.build()
.context("Failed to create encryptor")?;
match compression {