diff options
-rw-r--r-- | openpgp-ffi/src/serialize.rs | 5 | ||||
-rw-r--r-- | openpgp/src/autocrypt.rs | 5 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 28 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 7 |
4 files changed, 20 insertions, 25 deletions
diff --git a/openpgp-ffi/src/serialize.rs b/openpgp-ffi/src/serialize.rs index 8b0fedbd..9613886c 100644 --- a/openpgp-ffi/src/serialize.rs +++ b/openpgp-ffi/src/serialize.rs @@ -13,9 +13,6 @@ use libc::{c_char, size_t, ssize_t}; extern crate sequoia_openpgp as openpgp; extern crate time; -use self::openpgp::{ - crypto::Password, -}; use self::openpgp::constants::{ AEADAlgorithm, HashAlgorithm, @@ -347,7 +344,7 @@ pub extern "C" fn pgp_encryptor_new<'a> Some(aead_algo.into()) }; ffi_try_box!(Encryptor::new(*inner, - &passwords_.iter().collect::<Vec<&Password>>(), + passwords_.iter().collect::<Vec<_>>(), recipients_, cipher_algo, aead_algo)) diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs index e2ccf8e3..e2ae988f 100644 --- a/openpgp/src/autocrypt.rs +++ b/openpgp/src/autocrypt.rs @@ -468,9 +468,8 @@ impl AutocryptSetupMessage { // Passphrase-Format header with value numeric9x4 let m = Message::new(w); let w = Encryptor::new(m, - &[ self.passcode.as_ref().unwrap() ], - &[], - None, None)?; + vec![ self.passcode.as_ref().unwrap() ], + &[], None, None)?; let mut w = LiteralWriter::new(w, None, /* filename*/ None, /* date */ None)?; diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index c8788d83..28864b89 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -979,7 +979,7 @@ impl<'a> Encryptor<'a> { /// let mut o = vec![]; /// let message = Message::new(&mut o); /// let encryptor = Encryptor::new(message, - /// &[&"совершенно секретно".into()], + /// &["совершенно секретно".into()], /// &recipients, None, None) /// .expect("Failed to create encryptor"); /// let mut w = LiteralWriter::new(encryptor, None, None, None)?; @@ -988,28 +988,30 @@ impl<'a> Encryptor<'a> { /// # Ok(()) /// # } /// ``` - pub fn new<C, A, R>(inner: writer::Stack<'a, Cookie>, - passwords: &[&Password], - recipients: R, - cipher_algo: C, - aead_algo: A) - -> Result<writer::Stack<'a, Cookie>> - where C: Into<Option<SymmetricAlgorithm>>, - A: Into<Option<AEADAlgorithm>>, + pub fn new<'r, P, R, C, A>(inner: writer::Stack<'a, Cookie>, + passwords: P, recipients: R, + cipher_algo: C, aead_algo: A) + -> Result<writer::Stack<'a, Cookie>> + where P: IntoIterator, + P::Item: Borrow<Password>, R: IntoIterator, - R::Item: Borrow<Recipient<'a>> + 'a + R::Item: Borrow<Recipient<'r>>, + C: Into<Option<SymmetricAlgorithm>>, + A: Into<Option<AEADAlgorithm>>, { + let passwords = passwords.into_iter().collect::<Vec<_>>(); + let passwords_ref = passwords.iter().map(|r| r.borrow()).collect(); let recipients = recipients.into_iter().collect::<Vec<_>>(); let recipients_ref = recipients.iter().map(|r| r.borrow()).collect(); Self::make(inner, - passwords, + passwords_ref, recipients_ref, cipher_algo.into().unwrap_or_default(), aead_algo.into()) } fn make(mut inner: writer::Stack<'a, Cookie>, - passwords: &[&Password], + passwords: Vec<&Password>, recipients: Vec<&Recipient>, algo: SymmetricAlgorithm, aead_algo: Option<AEADAlgorithm>) @@ -1447,7 +1449,7 @@ mod test { { let m = Message::new(&mut o); let encryptor = Encryptor::new( - m, &passwords.iter().collect::<Vec<&Password>>(), + m, &passwords, &[], None, None) .unwrap(); let mut literal = LiteralWriter::new(encryptor, None, None, None) diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index 7ba0aab0..44173e04 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -94,7 +94,7 @@ pub fn encrypt(store: &mut store::Store, for r in recipients { tpks.push(store.lookup(r).context("No such key found")?.tpk()?); } - let mut passwords = Vec::with_capacity(npasswords); + let mut passwords: Vec<crypto::Password> = Vec::with_capacity(npasswords); for n in 0..npasswords { let nprompt = format!("Enter password {}: ", n + 1); passwords.push(rpassword::read_password_from_tty(Some( @@ -124,15 +124,12 @@ pub fn encrypt(store: &mut store::Store, } } - let passwords_: Vec<&openpgp::crypto::Password> = - passwords.iter().collect(); - // Stream an OpenPGP message. let message = Message::new(output); // We want to encrypt a literal data packet. let mut sink = Encryptor::new(message, - &passwords_, + passwords, recipient_subkeys, None, None) .context("Failed to create encryptor")?; |