diff options
Diffstat (limited to 'tool/src')
-rw-r--r-- | tool/src/commands/mod.rs | 17 | ||||
-rw-r--r-- | tool/src/sq.rs | 17 |
2 files changed, 15 insertions, 19 deletions
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index fa8ed857..a2c2e8cb 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -86,16 +86,12 @@ fn get_signing_keys(certs: &[openpgp::Cert], p: &dyn Policy, } pub fn encrypt(policy: &dyn Policy, - mapping: &mut store::Mapping, input: &mut dyn io::Read, output: &mut dyn io::Write, - npasswords: usize, recipients: Vec<&str>, - mut certs: Vec<openpgp::Cert>, signers: Vec<openpgp::Cert>, + npasswords: usize, recipients: &[openpgp::Cert], + signers: Vec<openpgp::Cert>, mode: openpgp::types::KeyFlags, compression: &str, time: Option<SystemTime>) -> Result<()> { - for r in recipients { - certs.push(mapping.lookup(r).context("No such key found")?.cert()?); - } let mut passwords: Vec<crypto::Password> = Vec::with_capacity(npasswords); for n in 0..npasswords { let nprompt = format!("Enter password {}: ", n + 1); @@ -107,19 +103,16 @@ pub fn encrypt(policy: &dyn Policy, }))?.into()); } - if certs.len() + passwords.len() == 0 { + if recipients.len() + passwords.len() == 0 { return Err(anyhow::anyhow!( "Neither recipient nor password given")); } let mut signers = get_signing_keys(&signers, policy, time)?; - // Build a vector of references to hand to Signer. - let recipients: Vec<&openpgp::Cert> = certs.iter().collect(); - // Build a vector of recipients to hand to Encryptor. let mut recipient_subkeys: Vec<Recipient> = Vec::new(); - for cert in certs.iter() { + for cert in recipients.iter() { let mut count = 0; for key in cert.keys().with_policy(policy, None).alive().revoked(false) .key_flags(&mode).map(|ka| ka.key()) @@ -167,7 +160,7 @@ pub fn encrypt(policy: &dyn Policy, signer = signer.creation_time(time); } } - for r in recipients { + for r in recipients.iter() { signer = signer.add_intended_recipient(r); } sink = signer.build()?; diff --git a/tool/src/sq.rs b/tool/src/sq.rs index 6d770e6d..03e87956 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -275,14 +275,17 @@ fn main() -> Result<()> { create_or_stdout_pgp(m.value_of("output"), force, m.is_present("binary"), armor::Kind::Message)?; - let mut mapping = Mapping::open(&ctx, realm_name, mapping_name) + let mapping = Mapping::open(&ctx, realm_name, mapping_name) .context("Failed to open the mapping")?; - let recipients = m.values_of("recipient") - .map(|r| r.collect()) - .unwrap_or(vec![]); - let additional_certs = m.values_of("recipient-key-file") + let mut recipients = m.values_of("recipient-key-file") .map(load_certs) .unwrap_or(Ok(vec![]))?; + if let Some(r) = m.values_of("recipient") { + for recipient in r { + recipients.push(mapping.lookup(recipient) + .context("No such key found")?.cert()?); + } + } let additional_secrets = m.values_of("signer-key-file") .map(load_certs) .unwrap_or(Ok(vec![]))?; @@ -303,9 +306,9 @@ fn main() -> Result<()> { } else { None }; - commands::encrypt(policy, &mut mapping, &mut input, &mut output, + commands::encrypt(policy, &mut input, &mut output, m.occurrences_of("symmetric") as usize, - recipients, additional_certs, additional_secrets, + &recipients, additional_secrets, mode, m.value_of("compression").expect("has default"), time.into())?; |