From c627737dfa6a30b71e3f7c32cca05675cc7e9b97 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 17 Apr 2021 21:06:47 -0400 Subject: clippy --- src/bin/rbw/sock.rs | 4 ++-- src/cipherstring.rs | 14 +++++++------- src/error.rs | 4 ++-- src/json.rs | 6 +++--- src/lib.rs | 1 + src/pwgen.rs | 20 +++++++++----------- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/bin/rbw/sock.rs b/src/bin/rbw/sock.rs index f3fe365..1f5f0b2 100644 --- a/src/bin/rbw/sock.rs +++ b/src/bin/rbw/sock.rs @@ -34,7 +34,7 @@ impl Sock { let mut line = String::new(); buf.read_line(&mut line) .context("failed to read message from agent")?; - Ok(serde_json::from_str(&line) - .context("failed to parse message from agent")?) + serde_json::from_str(&line) + .context("failed to parse message from agent") } } diff --git a/src/cipherstring.rs b/src/cipherstring.rs index cd1d25b..72681f8 100644 --- a/src/cipherstring.rs +++ b/src/cipherstring.rs @@ -184,9 +184,9 @@ impl CipherString { let pkey = openssl::pkey::PKey::private_key_from_pkcs8( private_key.private_key(), ) - .map_err(|source| Error::OpenSSL { source })?; + .map_err(|source| Error::OpenSsl { source })?; let rsa = - pkey.rsa().map_err(|source| Error::OpenSSL { source })?; + pkey.rsa().map_err(|source| Error::OpenSsl { source })?; let mut res = crate::locked::Vec::new(); res.extend(std::iter::repeat(0).take(rsa.size() as usize)); @@ -197,7 +197,7 @@ impl CipherString { res.data_mut(), openssl::rsa::Padding::PKCS1_OAEP, ) - .map_err(|source| Error::OpenSSL { source })?; + .map_err(|source| Error::OpenSsl { source })?; res.truncate(bytes); Ok(res) @@ -221,19 +221,19 @@ fn decrypt_common_symmetric( if let Some(mac) = mac { let mut key = hmac::Hmac::::new_varkey(keys.mac_key()) .map_err(|source| Error::CreateHmac { source })?; - key.update(&iv); - key.update(&ciphertext); + key.update(iv); + key.update(ciphertext); if key.verify(mac).is_err() { return Err(Error::InvalidMac); } } - Ok(block_modes::Cbc::< + block_modes::Cbc::< aes::Aes256, block_modes::block_padding::Pkcs7, >::new_var(keys.enc_key(), iv) - .map_err(|source| Error::CreateBlockMode { source })?) + .map_err(|source| Error::CreateBlockMode { source }) } impl std::fmt::Display for CipherString { diff --git a/src/error.rs b/src/error.rs index 28f8504..7544e76 100644 --- a/src/error.rs +++ b/src/error.rs @@ -62,7 +62,7 @@ pub enum Error { InvalidTwoFactorProvider { ty: String }, #[error("failed to parse JSON")] - JSON { + Json { source: serde_path_to_error::Error, }, @@ -103,7 +103,7 @@ pub enum Error { }, #[error("openssl error")] - OpenSSL { source: openssl::error::ErrorStack }, + OpenSsl { source: openssl::error::ErrorStack }, #[error("failed to parse match type {s}")] ParseMatchType { s: String }, diff --git a/src/json.rs b/src/json.rs index d6c5328..ce95262 100644 --- a/src/json.rs +++ b/src/json.rs @@ -8,7 +8,7 @@ impl DeserializeJsonWithPath for String { fn json_with_path(self) -> Result { let jd = &mut serde_json::Deserializer::from_str(&self); serde_path_to_error::deserialize(jd) - .map_err(|source| Error::JSON { source }) + .map_err(|source| Error::Json { source }) } } @@ -18,7 +18,7 @@ impl DeserializeJsonWithPath for reqwest::blocking::Response { self.bytes().map_err(|source| Error::Reqwest { source })?; let jd = &mut serde_json::Deserializer::from_slice(&bytes); serde_path_to_error::deserialize(jd) - .map_err(|source| Error::JSON { source }) + .map_err(|source| Error::Json { source }) } } @@ -40,6 +40,6 @@ impl DeserializeJsonWithPathAsync for reqwest::Response { .map_err(|source| Error::Reqwest { source })?; let jd = &mut serde_json::Deserializer::from_slice(&bytes); serde_path_to_error::deserialize(jd) - .map_err(|source| Error::JSON { source }) + .map_err(|source| Error::Json { source }) } } diff --git a/src/lib.rs b/src/lib.rs index 5044eb2..f84880f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ #![allow(clippy::large_enum_variant)] #![allow(clippy::missing_const_for_fn)] #![allow(clippy::missing_errors_doc)] +#![allow(clippy::missing_panics_doc)] #![allow(clippy::must_use_candidate)] #![allow(clippy::similar_names)] #![allow(clippy::single_match)] diff --git a/src/pwgen.rs b/src/pwgen.rs index cf63bb2..4d2d497 100644 --- a/src/pwgen.rs +++ b/src/pwgen.rs @@ -17,16 +17,6 @@ pub enum Type { } pub fn pwgen(ty: Type, len: usize) -> String { - if ty == Type::Diceware { - let config = chbs::config::BasicConfig { - words: len, - capitalize_first: chbs::probability::Probability::Never, - capitalize_words: chbs::probability::Probability::Never, - ..chbs::config::BasicConfig::default() - }; - return config.to_scheme().generate(); - } - let alphabet = match ty { Type::AllChars => { let mut v = vec![]; @@ -51,7 +41,15 @@ pub fn pwgen(ty: Type, len: usize) -> String { v.extend(NONCONFUSABLES.iter().copied()); v } - Type::Diceware => unreachable!(), + Type::Diceware => { + let config = chbs::config::BasicConfig { + words: len, + capitalize_first: chbs::probability::Probability::Never, + capitalize_words: chbs::probability::Probability::Never, + ..chbs::config::BasicConfig::default() + }; + return config.to_scheme().generate(); + } }; let mut rng = rand::thread_rng(); -- cgit v1.2.3