Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Oct 26, 2022
1 parent 490fca7 commit de96ae7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
18 changes: 8 additions & 10 deletions age-core/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,13 @@ impl<R: Read, W: Write> Connection<R, W> {
fn grease_gun(&mut self) -> impl Iterator<Item = Stanza> {
// 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<()> {
Expand Down Expand Up @@ -484,7 +482,7 @@ mod tests {
.unwrap();
let stanza = plugin_conn
.unidir_receive::<_, (), (), _, _, _, _>(
("test", |s| Ok(s)),
("test", Ok),
("other", |_| Err(())),
(None, |_| Ok(())),
)
Expand Down
2 changes: 1 addition & 1 deletion age/src/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<R: io::Read> IdentityState<R> {
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!(),
Expand Down
6 changes: 3 additions & 3 deletions age/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?)),
}
Expand All @@ -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,
Expand Down
27 changes: 18 additions & 9 deletions age/src/primitives/armor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ enum ArmorIs<W> {
#[pin]
inner: LineEndingWriter<W>,
byte_buf: Option<Vec<u8>>,
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<EncodedBytes>,
Expand All @@ -293,7 +293,7 @@ impl<W: Write> ArmoredWriter<W> {
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,
})
Expand All @@ -317,7 +317,7 @@ impl<W: Write> ArmoredWriter<W> {
} => {
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()
}
Expand Down Expand Up @@ -359,10 +359,14 @@ impl<W: Write> Write for ArmoredWriter<W> {
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();
};
}
Expand Down Expand Up @@ -390,7 +394,7 @@ impl<W: AsyncWrite> ArmoredWriter<W> {
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 }),
Expand Down Expand Up @@ -455,7 +459,11 @@ impl<W: AsyncWrite> AsyncWrite for ArmoredWriter<W> {
// 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 {
Expand Down Expand Up @@ -499,7 +507,8 @@ impl<W: AsyncWrite> AsyncWrite for ArmoredWriter<W> {
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,
Expand Down Expand Up @@ -982,7 +991,7 @@ impl<R: AsyncBufRead + Unpin> AsyncRead for ArmoredReader<R> {
{
// 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(
Expand Down
2 changes: 1 addition & 1 deletion age/src/scrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit de96ae7

Please sign in to comment.