From b44f4ca359061ad3409317d6993567b28b5303f2 Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Sun, 2 Jul 2023 19:28:40 -0400 Subject: [PATCH] Fix clippy warnings --- crates/asp/src/aspe/mod.rs | 4 ++-- crates/asp/src/keys/mod.rs | 10 +++++----- crates/asp/src/utils/jwk.rs | 2 +- crates/asp/src/utils/jwt.rs | 6 +++--- src/main.rs | 19 ++++++++----------- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/asp/src/aspe/mod.rs b/crates/asp/src/aspe/mod.rs index 1a5e064..53362df 100644 --- a/crates/asp/src/aspe/mod.rs +++ b/crates/asp/src/aspe/mod.rs @@ -26,7 +26,7 @@ pub enum AspeRequestFailure { impl From for AspeRequestFailure { fn from(value: reqwest::Error) -> Self { if !value.is_status() { - return Self::Unknown(value); + Self::Unknown(value) } else { match value.status().unwrap() { StatusCode::BAD_REQUEST => Self::BadRequest, @@ -52,7 +52,7 @@ pub enum AspeFetchFailure { impl From for AspeFetchFailure { fn from(value: reqwest::Error) -> Self { if !value.is_status() { - return Self::Unknown(value); + Self::Unknown(value) } else { match value.status().unwrap() { StatusCode::NOT_FOUND => Self::NotFound, diff --git a/crates/asp/src/keys/mod.rs b/crates/asp/src/keys/mod.rs index 5f0d963..1f911eb 100644 --- a/crates/asp/src/keys/mod.rs +++ b/crates/asp/src/keys/mod.rs @@ -20,11 +20,11 @@ pub enum AspKeyType { ES256, } -impl Into for AspKeyType { - fn into(self) -> i32 { - match self { - Self::Ed25519 => 0, - Self::ES256 => 1, +impl From for i32 { + fn from(value: AspKeyType) -> Self { + match value { + AspKeyType::Ed25519 => 0, + AspKeyType::ES256 => 1, } } } diff --git a/crates/asp/src/utils/jwk.rs b/crates/asp/src/utils/jwk.rs index fb586c3..ffd349a 100644 --- a/crates/asp/src/utils/jwk.rs +++ b/crates/asp/src/utils/jwk.rs @@ -92,7 +92,7 @@ impl JwtExt for Jwk { fn from_encrypted(secret: &[u8], jwe: &str) -> anyhow::Result { let decrypter = A256gcmkw.decrypter_from_bytes(secret)?; let (deserialized, _) = jwe::deserialize_compact(jwe, &decrypter)?; - let jwk = Jwk::from_bytes(&deserialized)?; + let jwk = Jwk::from_bytes(deserialized)?; Ok(jwk) } diff --git a/crates/asp/src/utils/jwt.rs b/crates/asp/src/utils/jwt.rs index 4478829..dc871ce 100644 --- a/crates/asp/src/utils/jwt.rs +++ b/crates/asp/src/utils/jwt.rs @@ -52,7 +52,7 @@ impl Deserialize<'de>> JwtSerialize fo let mut header = JwsHeader::new(); header.set_token_type("JWT"); header - .set_asp_key(&key) + .set_asp_key(key) .or(Err(JwtSerializationError::JwkUsageError))?; // Construct the payload @@ -66,14 +66,14 @@ impl Deserialize<'de>> JwtSerialize fo .or(Err(JwtSerializationError::PayloadSerializationError))?; // Sign it into a JWT - Ok(jwt::encode_with_signer( + jwt::encode_with_signer( &payload, &header, &*key .create_signer() .or(Err(JwtSerializationError::JwkUsageError))?, ) - .or(Err(JwtSerializationError::SerializationError))?) + .or(Err(JwtSerializationError::SerializationError)) } fn decode_and_verify(jwt: &str, key: &AspKey) -> Result, JwtDeserializationError> diff --git a/src/main.rs b/src/main.rs index 26902a3..1089d0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,11 +79,8 @@ pub enum AspmSubcommands { #[tokio::main] async fn main() { - match cli().await { - Err(e) => { - eprintln!("An error occurred while running that command:\n{e}"); - } - _ => (), + if let Err(e) = cli().await { + eprintln!("An error occurred while running that command:\n{e}"); } } @@ -94,11 +91,11 @@ async fn cli() -> Result<(), anyhow::Error> { let data_dir = parsed.data_dir.unwrap_or( std::env::var("ASPM_DATA_DIR").map(|s| s.into()).unwrap_or( app_dirs2::get_app_root(AppDataType::UserData, &APP_INFO) - .map_err(|e| AspmError::UnknownError(e.into()))?, + .map_err(|e| AspmError::Unknown(e.into()))?, ), ); - std::fs::create_dir_all(&data_dir).or(Err(AspmError::DataDirCreateError))?; - std::fs::read_dir(&data_dir).or(Err(AspmError::DataDirReadError))?; + std::fs::create_dir_all(&data_dir).or(Err(AspmError::DataDirCreate))?; + std::fs::read_dir(&data_dir).or(Err(AspmError::DataDirRead))?; // Construct the database in the dir let db = Database::connect(DATABASE_URL.replace("DB_PATH", &{ @@ -136,9 +133,9 @@ async fn cli() -> Result<(), anyhow::Error> { #[derive(Error, Debug)] enum AspmError { #[error("The data directory was unable to be created, is it correct, and does the current user have permission to create it?")] - DataDirCreateError, + DataDirCreate, #[error("The data directory was unable to be read, is it correct, and does the current user have permission to read it?")] - DataDirReadError, + DataDirRead, #[error("An unknown internal error occurred, please report this to the developer")] - UnknownError(#[source] anyhow::Error), + Unknown(#[source] anyhow::Error), }