diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index 4c7e3a014..179abb6d5 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -14,7 +14,7 @@ chacha20poly1305 = { version = "0.10.1", optional = true } jsonwebtoken = "9.3.0" pbkdf2 = { version = "0.12.2", optional = true } rand = { workspace = true, optional = true } -sha2 = "0.10.8" +sha2 = { version = "0.10.8", optional = true } thiserror.workspace = true serde_json.workspace = true @@ -24,6 +24,7 @@ test-case.workspace = true time.workspace = true [features] +default = ["crypto", "fips"] fips = [] crypto = [ "dep:aes-gcm", @@ -31,8 +32,8 @@ crypto = [ "dep:chacha20poly1305", "dep:pbkdf2", "dep:rand", + "dep:sha2", ] -default = ["crypto", "fips"] [lints.clippy] unwrap_used = "deny" diff --git a/crypto/src/encdec/decrypt.rs b/crypto/src/encdec/decrypt.rs index 92de90052..e3660e6db 100644 --- a/crypto/src/encdec/decrypt.rs +++ b/crypto/src/encdec/decrypt.rs @@ -37,7 +37,7 @@ fn decryp(stream: T, nonce: &[u8], data: &[u8]) -> Resul .map_err(Error::ErrDecryptFailed) } -#[cfg(all(not(test), not(feature = "crypto")))] +#[cfg(not(any(test, feature = "crypto")))] pub fn decrypt_data(_password: &[u8], data: &[u8]) -> Result, crate::Error> { Ok(data.to_vec()) } diff --git a/crypto/src/encdec/encrypt.rs b/crypto/src/encdec/encrypt.rs index 76ddd2a13..885d46c05 100644 --- a/crypto/src/encdec/encrypt.rs +++ b/crypto/src/encdec/encrypt.rs @@ -55,7 +55,7 @@ fn encrypt( Ok(ciphertext) } -#[cfg(all(not(test), not(feature = "crypto")))] +#[cfg(not(any(test, feature = "crypto")))] pub fn encrypt_data(_password: &[u8], data: &[u8]) -> Result, crate::Error> { Ok(data.to_vec()) } diff --git a/crypto/src/error.rs b/crypto/src/error.rs index 6ab05e67a..d75ddde63 100644 --- a/crypto/src/error.rs +++ b/crypto/src/error.rs @@ -1,5 +1,3 @@ -use sha2::digest::InvalidLength; - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("unexpected header")] @@ -8,8 +6,9 @@ pub enum Error { #[error("invalid encryption algorithm ID: {0}")] ErrInvalidAlgID(u8), + #[cfg(any(test, feature = "crypto"))] #[error("{0}")] - ErrInvalidLength(#[from] InvalidLength), + ErrInvalidLength(#[from] sha2::digest::InvalidLength), #[cfg(any(test, feature = "crypto"))] #[error("encrypt failed")] diff --git a/iam/src/auth/credentials.rs b/iam/src/auth/credentials.rs index 3b72cb63f..ac4590c2a 100644 --- a/iam/src/auth/credentials.rs +++ b/iam/src/auth/credentials.rs @@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use std::cell::LazyCell; use std::collections::HashMap; -use std::env::var; use time::format_description::BorrowedFormatItem; use time::{Date, OffsetDateTime}; @@ -103,7 +102,7 @@ impl Credentials { Self::check_key_value(header) } - pub fn check_key_value(header: CredentialHeader) -> crate::Result { + pub fn check_key_value(_header: CredentialHeader) -> crate::Result { todo!() } diff --git a/iam/src/cache.rs b/iam/src/cache.rs index e615632f1..c3dbef97c 100644 --- a/iam/src/cache.rs +++ b/iam/src/cache.rs @@ -93,7 +93,7 @@ impl CacheInner { self.users.get(user_name).or_else(|| self.sts_accounts.get(user_name)) } - fn get_policy(&self, name: &str, groups: &[String]) -> crate::Result> { + fn get_policy(&self, _name: &str, _groups: &[String]) -> crate::Result> { todo!() } @@ -126,13 +126,13 @@ impl CacheInner { } // todo - pub fn is_allowed_sts(&self, args: &Args, parent: &str) -> bool { + pub fn is_allowed_sts(&self, _args: &Args, _parent: &str) -> bool { warn!("unimplement is_allowed_sts"); false } // todo - pub fn is_allowed_service_account(&self, args: &Args, parent: &str) -> bool { + pub fn is_allowed_service_account(&self, _args: &Args, _parent: &str) -> bool { warn!("unimplement is_allowed_sts"); false } @@ -141,7 +141,7 @@ impl CacheInner { todo!() } - pub fn policy_db_get(&self, name: &str, groups: &[String]) -> Vec { + pub fn policy_db_get(&self, _name: &str, _groups: &[String]) -> Vec { todo!() } } diff --git a/iam/src/error.rs b/iam/src/error.rs index c6b8a791c..cc92131d1 100644 --- a/iam/src/error.rs +++ b/iam/src/error.rs @@ -1,5 +1,3 @@ -use core::error; - use crate::policy; #[derive(thiserror::Error, Debug)] diff --git a/iam/src/handler.rs b/iam/src/handler.rs index eb291195b..50557f417 100644 --- a/iam/src/handler.rs +++ b/iam/src/handler.rs @@ -1,13 +1,12 @@ -use std::{borrow::Cow, collections::HashMap, f32::NAN}; +use std::{borrow::Cow, collections::HashMap}; use log::{info, warn}; -use time::OffsetDateTime; use crate::{ arn::ARN, - auth::{Credentials, UserIdentity}, - cache::{Cache, CacheInner}, - policy::{utils::get_values_from_claims, Args, MappedPolicy, Policy, UserType}, + auth::UserIdentity, + cache::CacheInner, + policy::{utils::get_values_from_claims, Args, Policy}, store::Store, Error, }; @@ -36,7 +35,7 @@ where .or_else(|| self.cache.sts_accounts.get(user_name)) } - async fn get_policy(&self, name: &str, groups: &[String]) -> crate::Result> { + async fn get_policy(&self, name: &str, _groups: &[String]) -> crate::Result> { if name.is_empty() { return Err(Error::InvalidArgument); } @@ -122,7 +121,7 @@ where false } - pub async fn get_combined_policy(&self, policyes: &[String]) -> Policy { + pub async fn get_combined_policy(&self, _policies: &[String]) -> Policy { todo!() } diff --git a/iam/src/policy/effect.rs b/iam/src/policy/effect.rs index f932fe247..48437f644 100644 --- a/iam/src/policy/effect.rs +++ b/iam/src/policy/effect.rs @@ -1,5 +1,3 @@ -use std::default; - use serde::{Deserialize, Serialize}; use strum::{EnumString, IntoStaticStr}; diff --git a/iam/src/policy/function.rs b/iam/src/policy/function.rs index f4b5b647b..b86ba19dc 100644 --- a/iam/src/policy/function.rs +++ b/iam/src/policy/function.rs @@ -1,7 +1,6 @@ use std::{collections::HashMap, ops::Deref}; use func::Func; -use key::Key; use serde::{de, Deserialize, Serialize}; pub mod addr; @@ -56,7 +55,7 @@ impl<'de> Deserialize<'de> for Functions { return Err(A::Error::custom("invalid codition")); } - let Some(name) = name else { return Err(A::Error::custom("invalid codition")) }; + let Some(_name) = name else { return Err(A::Error::custom("invalid codition")) }; let f = match qualifier { Some("ForAnyValues") => Func::ForAnyValues, diff --git a/iam/src/policy/statement.rs b/iam/src/policy/statement.rs index 04b1e7d4e..f10e7b8aa 100644 --- a/iam/src/policy/statement.rs +++ b/iam/src/policy/statement.rs @@ -1,5 +1,3 @@ -use std::borrow::Cow; - use serde::{Deserialize, Serialize}; use super::{action::Action, ActionSet, Args, Effect, Error, Functions, ResourceSet, Validator, ID}; diff --git a/iam/src/policy/utils/path.rs b/iam/src/policy/utils/path.rs index a6807ef3a..9eb52bf02 100644 --- a/iam/src/policy/utils/path.rs +++ b/iam/src/policy/utils/path.rs @@ -1,5 +1,3 @@ -use std::{fmt::Write, usize}; - struct LazyBuf<'a> { s: &'a str, buf: Option>, diff --git a/iam/src/store/object.rs b/iam/src/store/object.rs index 02f49324f..f884e2472 100644 --- a/iam/src/store/object.rs +++ b/iam/src/store/object.rs @@ -6,14 +6,14 @@ use ecstore::{ store_api::{HTTPRangeSpec, ObjectIO, ObjectInfo, ObjectOptions, PutObjReader}, utils::path::dir, }; -use futures::{future::try_join_all, SinkExt}; +use futures::future::try_join_all; use log::debug; use serde::{de::DeserializeOwned, Serialize}; use super::Store; use crate::{ auth::UserIdentity, - cache::{Cache, CacheEntity, CacheInner}, + cache::{Cache, CacheEntity}, policy::{utils::split_path, MappedPolicy, PolicyDoc, UserType}, Error, }; @@ -102,7 +102,7 @@ impl ObjectStore { Ok(Some(user)) } - async fn load_mapped_policy(&self, user_type: UserType, name: &str, is_group: bool) -> crate::Result { + async fn load_mapped_policy(&self, user_type: UserType, name: &str, _is_group: bool) -> crate::Result { let (p, _) = self .load_iam_config::(&format!("{base}{name}.json", base = user_type.prefix(), name = name)) .await?;