From f74dd2ec4bad5e2205c86f5097516f23da1c41fb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 4 Apr 2021 16:55:34 +1200 Subject: [PATCH] Fix clippy lints --- src/builder.rs | 8 ++------ src/main.rs | 18 +++++++++--------- src/yubikey.rs | 8 ++++---- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index f09c902..2176fe0 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -78,13 +78,9 @@ impl IdentityBuilder { let keys = Key::list(yubikey)?; USABLE_SLOTS .iter() - .find(|&&slot| { - keys.iter() - .find(|key| key.slot() == SlotId::Retired(slot)) - .is_none() - }) + .find(|&&slot| !keys.iter().any(|key| key.slot() == SlotId::Retired(slot))) .cloned() - .ok_or(Error::NoEmptySlots(yubikey.serial()))? + .ok_or_else(|| Error::NoEmptySlots(yubikey.serial()))? } }; diff --git a/src/main.rs b/src/main.rs index 916dacf..55543e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -265,8 +265,8 @@ fn main() -> Result<(), Error> { if let Some(state_machine) = opts.age_plugin { run_state_machine( &state_machine, - || plugin::RecipientPlugin::default(), - || plugin::IdentityPlugin::default(), + plugin::RecipientPlugin::default, + plugin::IdentityPlugin::default, )?; Ok(()) } else if opts.generate { @@ -279,17 +279,17 @@ fn main() -> Result<(), Error> { list(true) } else { eprintln!("✨ Let's get your YubiKey set up for age! ✨"); - eprintln!(""); + eprintln!(); eprintln!("This tool can create a new age identity in a free slot of your YubiKey."); eprintln!("It will generate an identity file that you can use with an age client,"); eprintln!("along with the corresponding recipient."); - eprintln!(""); + eprintln!(); eprintln!("If you are already using a YubiKey with age, you can select an existing"); eprintln!("slot to recreate its corresponding identity file and recipient."); - eprintln!(""); + eprintln!(); eprintln!("When asked below to select an option, use the up/down arrow keys to"); eprintln!("make your choice, or press [Esc] or [q] to quit."); - eprintln!(""); + eprintln!(); if Readers::open()?.iter()?.len() == 0 { eprintln!("⏳ Please insert the YubiKey you want to set up."); @@ -299,8 +299,8 @@ fn main() -> Result<(), Error> { // Filter out readers we can't connect to. let readers_list: Vec<_> = readers .iter()? - .filter_map(|reader| match reader.open() { - Ok(_) => Some(reader), + .filter(|reader| match reader.open() { + Ok(_) => true, Err(e) => { use std::error::Error; let reason = if let Some(inner) = e.source() { @@ -309,7 +309,7 @@ fn main() -> Result<(), Error> { e.to_string() }; warn!("Ignoring {}: {}", reader.name(), reason); - None + false } }) .collect(); diff --git a/src/yubikey.rs b/src/yubikey.rs index 43c84d9..8d45963 100644 --- a/src/yubikey.rs +++ b/src/yubikey.rs @@ -71,7 +71,7 @@ pub(crate) fn open(serial: Option) -> Result { } pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> { - eprintln!(""); + eprintln!(); let pin = Password::new() .with_prompt(&format!( "Enter PIN for YubiKey with serial {} (default is 123456)", @@ -82,15 +82,15 @@ pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> { // If the user is using the default PIN, help them to change it. if pin == "123456" { - eprintln!(""); + eprintln!(); eprintln!("✨ Your key is using the default PIN. Let's change it!"); eprintln!("✨ We'll also set the PUK equal to the PIN."); - eprintln!(""); + eprintln!(); eprintln!("🔐 The PIN is up to 8 numbers, letters, or symbols. Not just numbers!"); eprintln!( "❌ Your keys will be lost if the PIN and PUK are locked after 3 incorrect tries." ); - eprintln!(""); + eprintln!(); let current_puk = Password::new() .with_prompt("Enter current PUK (default is 12345678)") .interact()?;