From 00d839a59d14d6f476af59cfb9b2de4b97d0eecc Mon Sep 17 00:00:00 2001 From: Alexander Sukhachev Date: Wed, 31 Jan 2024 00:22:03 +0500 Subject: [PATCH] small improvements Signed-off-by: Alexander Sukhachev --- generate/src/main.rs | 11 ++--------- src/utils.rs | 17 ++++------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/generate/src/main.rs b/generate/src/main.rs index 9dde1d3..84d5673 100644 --- a/generate/src/main.rs +++ b/generate/src/main.rs @@ -82,8 +82,6 @@ fn generate_and_check( let strategy = ClaimsForSelectiveDisclosureStrategy::Custom(sd_claims_jsonpaths.iter().map(String::as_str).collect()); - dbg!(&strategy); - let jwk: Option = if specs.key_binding.unwrap_or(false) { let jwk: Jwk = serde_yaml::from_value(settings.key_settings.holder_key.clone()).unwrap(); Some(jwk) @@ -253,17 +251,12 @@ fn load_salts(path: &PathBuf) -> Result<()> { .map_err(|e| Error::from_msg(ErrorKind::IOError, e.to_string()))?; let salts: Vec = serde_json::from_str(&json_data)?; - - dbg!(&salts); - { - let mut map = SALTS.lock().unwrap(); + let mut s = SALTS.lock().unwrap(); for salt in salts.iter() { - map.push_back(salt.clone()); + s.push_back(salt.clone()); } - - dbg!(&map); } } diff --git a/src/utils.rs b/src/utils.rs index 3211420..d21985e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,7 +16,7 @@ use std::{collections::VecDeque, sync::Mutex}; #[cfg(feature = "mock_salts")] lazy_static! { - pub static ref SALTS: Mutex> = Mutex::new(VecDeque::with_capacity(100)); + pub static ref SALTS: Mutex> = Mutex::new(VecDeque::new()); } pub(crate) fn base64_hash(data: &[u8]) -> String { @@ -43,19 +43,10 @@ pub(crate) fn generate_salt(_key_for_predefined_salt: Option) -> String base64url_encode(&buf) } +#[cfg(feature = "mock_salts")] pub(crate) fn generate_salt_mock(_key_for_predefined_salt: Option) -> String { - - #[cfg(feature = "mock_salts")] - { - let mut salts = SALTS.lock().unwrap(); - - if let Some(salt) = salts.pop_front() { - //FIXME better mock approach - return salt.clone() - } - - panic!("salts is empty"); - } + let mut salts = SALTS.lock().unwrap(); + return salts.pop_front().expect("SALTS is empty"); } pub(crate) fn jwt_payload_decode(b64data: &str) -> Result> {