diff --git a/age-core/src/plugin.rs b/age-core/src/plugin.rs index 3334670a..7dc0063d 100644 --- a/age-core/src/plugin.rs +++ b/age-core/src/plugin.rs @@ -176,15 +176,13 @@ impl Connection { fn grease_gun(&mut self) -> impl Iterator { // Add 5% grease let mut rng = thread_rng(); - (0..2) - .map(move |_| { - if rng.gen_range(0..100) < 5 { - Some(grease_the_joint()) - } else { - None - } - }) - .flatten() + (0..2).filter_map(move |_| { + if rng.gen_range(0..100) < 5 { + Some(grease_the_joint()) + } else { + None + } + }) } fn done(&mut self) -> io::Result<()> { @@ -484,7 +482,7 @@ mod tests { .unwrap(); let stanza = plugin_conn .unidir_receive::<_, (), (), _, _, _, _>( - ("test", |s| Ok(s)), + ("test", Ok), ("other", |_| Err(())), (None, |_| Ok(())), ) diff --git a/age/src/encrypted.rs b/age/src/encrypted.rs index 08aaa5f3..af38b828 100644 --- a/age/src/encrypted.rs +++ b/age/src/encrypted.rs @@ -48,7 +48,7 @@ impl IdentityState { let passphrase = match callbacks.request_passphrase(&fl!( crate::i18n::LANGUAGE_LOADER, "encrypted-passphrase-prompt", - filename = filename.as_deref().unwrap_or_default() + filename = filename.unwrap_or_default() )) { Some(passphrase) => passphrase, None => todo!(), diff --git a/age/src/identity.rs b/age/src/identity.rs index 99fe814f..90c63b60 100644 --- a/age/src/identity.rs +++ b/age/src/identity.rs @@ -27,8 +27,8 @@ impl IdentityFileEntry { IdentityFileEntry::Native(i) => Ok(Box::new(i)), #[cfg(feature = "plugin")] IdentityFileEntry::Plugin(i) => Ok(Box::new(crate::plugin::IdentityPluginV1::new( - &i.plugin().to_owned(), - &[i], + i.plugin(), + &[i.clone()], callbacks, )?)), } @@ -43,7 +43,7 @@ impl IdentityFileEntry { IdentityFileEntry::Native(i) => Ok(Box::new(i.to_public())), #[cfg(feature = "plugin")] IdentityFileEntry::Plugin(i) => Ok(Box::new(crate::plugin::RecipientPluginV1::new( - &i.plugin().to_owned(), + i.plugin(), &[], &[i.clone()], callbacks, diff --git a/age/src/primitives/armor.rs b/age/src/primitives/armor.rs index eaca79a2..1ac5997c 100644 --- a/age/src/primitives/armor.rs +++ b/age/src/primitives/armor.rs @@ -269,7 +269,7 @@ enum ArmorIs { #[pin] inner: LineEndingWriter, byte_buf: Option>, - encoded_buf: [u8; BASE64_CHUNK_SIZE_COLUMNS], + encoded_buf: Box<[u8; BASE64_CHUNK_SIZE_COLUMNS]>, #[cfg(feature = "async")] #[cfg_attr(docsrs, doc(cfg(feature = "async")))] encoded_line: Option, @@ -293,7 +293,7 @@ impl ArmoredWriter { ArmoredWriter(ArmorIs::Enabled { inner: w, byte_buf: Some(Vec::with_capacity(BASE64_CHUNK_SIZE_BYTES)), - encoded_buf: [0; BASE64_CHUNK_SIZE_COLUMNS], + encoded_buf: Box::new([0; BASE64_CHUNK_SIZE_COLUMNS]), #[cfg(feature = "async")] encoded_line: None, }) @@ -317,7 +317,7 @@ impl ArmoredWriter { } => { let byte_buf = byte_buf.unwrap(); let encoded = - base64::encode_config_slice(&byte_buf, base64::STANDARD, &mut encoded_buf); + base64::encode_config_slice(&byte_buf, base64::STANDARD, &mut encoded_buf[..]); inner.write_all(&encoded_buf[..encoded])?; inner.finish() } @@ -359,10 +359,14 @@ impl Write for ArmoredWriter { break; } else { assert_eq!( - base64::encode_config_slice(&byte_buf, base64::STANDARD, encoded_buf), + base64::encode_config_slice( + &byte_buf, + base64::STANDARD, + &mut encoded_buf[..], + ), BASE64_CHUNK_SIZE_COLUMNS ); - inner.write_all(encoded_buf)?; + inner.write_all(&encoded_buf[..])?; byte_buf.clear(); }; } @@ -390,7 +394,7 @@ impl ArmoredWriter { Format::AsciiArmor => ArmoredWriter(ArmorIs::Enabled { inner: LineEndingWriter::new_async(output), byte_buf: Some(Vec::with_capacity(BASE64_CHUNK_SIZE_BYTES)), - encoded_buf: [0; BASE64_CHUNK_SIZE_COLUMNS], + encoded_buf: Box::new([0; BASE64_CHUNK_SIZE_COLUMNS]), encoded_line: None, }), Format::Binary => ArmoredWriter(ArmorIs::Disabled { inner: output }), @@ -455,7 +459,11 @@ impl AsyncWrite for ArmoredWriter { // line must be written in poll_close(). if !buf.is_empty() { assert_eq!( - base64::encode_config_slice(&byte_buf, base64::STANDARD, encoded_buf), + base64::encode_config_slice( + &byte_buf, + base64::STANDARD, + &mut encoded_buf[..], + ), ARMORED_COLUMNS_PER_LINE ); *encoded_line = Some(EncodedBytes { @@ -499,7 +507,8 @@ impl AsyncWrite for ArmoredWriter { if let Some(byte_buf) = byte_buf { // Finish the armored format with a partial line (if necessary) and the end // marker. - let encoded = base64::encode_config_slice(&byte_buf, base64::STANDARD, encoded_buf); + let encoded = + base64::encode_config_slice(&byte_buf, base64::STANDARD, &mut encoded_buf[..]); *encoded_line = Some(EncodedBytes { offset: 0, end: encoded, @@ -982,7 +991,7 @@ impl AsyncRead for ArmoredReader { { // Emulates `AsyncBufReadExt::read_line`. let mut this = self.as_mut().project(); - let buf: &mut String = &mut this.line_buf; + let buf: &mut String = this.line_buf; let mut bytes = mem::take(buf).into_bytes(); let mut read = 0; ready!(read_line_internal( diff --git a/age/src/scrypt.rs b/age/src/scrypt.rs index 256e4cc6..c3dfc965 100644 --- a/age/src/scrypt.rs +++ b/age/src/scrypt.rs @@ -130,7 +130,7 @@ impl<'a> crate::Identity for Identity<'a> { // Place bounds on the work factor we will accept (roughly 16 seconds). let target = target_scrypt_work_factor(); - if log_n > self.max_work_factor.unwrap_or_else(|| target + 4) { + if log_n > self.max_work_factor.unwrap_or(target + 4) { return Some(Err(DecryptError::ExcessiveWork { required: log_n, target,