From 9307503bdc464753637430f74ca32cdfe2985928 Mon Sep 17 00:00:00 2001 From: shimun Date: Tue, 7 Apr 2020 20:06:24 +0200 Subject: [PATCH] applied clippy lints --- src/cli.rs | 15 ++++++--------- src/config.rs | 5 +++-- src/device.rs | 4 ++-- src/luks.rs | 7 +++---- src/util.rs | 4 ++-- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index b5bddfc..3f3e39b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -138,7 +138,7 @@ impl SecretGeneration { while let Ok(el) = start.elapsed() { if el > timeout { - Err(error::Fido2LuksError::NoAuthenticatorError)?; + return Err(error::Fido2LuksError::NoAuthenticatorError); } if get_devices() .map(|devices| !devices.is_empty()) @@ -287,9 +287,9 @@ pub fn run_cli() -> Fido2LuksResult<()> { .patch(&args, Some(false)) .obtain_secret("Password")?; if *binary { - stdout.write(&secret[..])?; + stdout.write_all(&secret[..])?; } else { - stdout.write(hex::encode(&secret[..]).as_bytes())?; + stdout.write_all(hex::encode(&secret[..]).as_bytes())?; } Ok(stdout.flush()?) } @@ -363,14 +363,11 @@ pub fn run_cli() -> Fido2LuksResult<()> { { Err(e) => { match e { - Fido2LuksError::WrongSecret if retries > 0 => (), + Fido2LuksError::WrongSecret if retries > 0 => {} Fido2LuksError::AuthenticatorError { ref cause } - if cause.kind() == FidoErrorKind::Timeout && retries > 0 => - { - () - } + if cause.kind() == FidoErrorKind::Timeout && retries > 0 => {} - e => break Err(e)?, + e => return Err(e), } retries -= 1; eprintln!("{}", e); diff --git a/src/config.rs b/src/config.rs index 0d1ea8e..5a6b593 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,7 +24,7 @@ impl Default for InputSalt { impl From<&str> for InputSalt { fn from(s: &str) -> Self { - let mut parts = s.split(":").into_iter(); + let mut parts = s.split(':'); match parts.next() { Some("ask") | Some("Ask") => InputSalt::AskPassword, Some("file") => InputSalt::File { @@ -87,6 +87,7 @@ impl InputSalt { #[derive(Debug, Clone)] pub enum PasswordHelper { Script(String), + #[allow(dead_code)] Systemd, Stdin, } @@ -134,7 +135,7 @@ impl PasswordHelper { Systemd => unimplemented!(), Stdin => Ok(util::read_password("Password", true)?), Script(password_helper) => { - let mut helper_parts = password_helper.split(" "); + let mut helper_parts = password_helper.split(' '); let password = Command::new((&mut helper_parts).next().unwrap()) .args(helper_parts) diff --git a/src/device.rs b/src/device.rs index a6fa374..12cae6f 100644 --- a/src/device.rs +++ b/src/device.rs @@ -7,7 +7,7 @@ use ctap::{ }; use std::time::Duration; -const RP_ID: &'static str = "fido2luks"; +const RP_ID: &str = "fido2luks"; pub fn make_credential_id(name: Option<&str>) -> Fido2LuksResult { let mut request = FidoCredentialRequestBuilder::default().rp_id(RP_ID); @@ -52,7 +52,7 @@ pub fn get_devices() -> Fido2LuksResult> { match FidoDevice::new(&di) { Err(e) => match e.kind() { FidoErrorKind::ParseCtap | FidoErrorKind::DeviceUnsupported => (), - err => Err(FidoError::from(err))?, + err => return Err(FidoError::from(err).into()), }, Ok(dev) => devices.push(dev), } diff --git a/src/luks.rs b/src/luks.rs index 1baeb16..2b1f7ac 100644 --- a/src/luks.rs +++ b/src/luks.rs @@ -11,7 +11,7 @@ fn load_device_handle>(path: P) -> Fido2LuksResult { .into_iter() .fold(None, |res, format| match res { Some(Ok(())) => res, - Some(e) => Some(e.or(load(format))), + Some(e) => Some(e.or_else(|_| load(format))), None => Some(load(format)), }) .unwrap()?; @@ -58,9 +58,8 @@ pub fn remove_keyslots>(path: P, exclude: &[u32]) -> Fido2LuksRes } _ => (), } - match handle.status()? { - KeyslotInfo::ActiveLast => break, - _ => (), + if let KeyslotInfo::ActiveLast = handle.status()? { + break; } } Ok(destroyed) diff --git a/src/util.rs b/src/util.rs index e7366d0..3fb2585 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::io::Read; use std::path::PathBuf; -pub fn sha256<'a>(messages: &[&[u8]]) -> [u8; 32] { +pub fn sha256(messages: &[&[u8]]) -> [u8; 32] { let mut digest = digest::Context::new(&digest::SHA256); for m in messages.iter() { digest.update(m); @@ -23,7 +23,7 @@ pub fn read_password(q: &str, verify: bool) -> Fido2LuksResult { { Err(Fido2LuksError::AskPassError { cause: AskPassError::Mismatch, - })? + }) } pass => Ok(pass), }