From e15c69342140177c81611663c906e5e84521dde4 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Wed, 3 Jul 2024 12:18:45 +0300 Subject: [PATCH] chore: Returns nonce cache as `Arc` Signed-off-by: Awiteb --- crates/oxidetalis/src/extensions.rs | 10 ++++++---- crates/oxidetalis/src/middlewares/signature.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/oxidetalis/src/extensions.rs b/crates/oxidetalis/src/extensions.rs index ad91c2d..9e6b2e0 100644 --- a/crates/oxidetalis/src/extensions.rs +++ b/crates/oxidetalis/src/extensions.rs @@ -30,7 +30,7 @@ pub trait DepotExt { /// Returns the server configuration fn config(&self) -> &Config; /// Retutns the nonce cache - fn nonce_cache(&self) -> &NonceCache; + fn nonce_cache(&self) -> Arc; /// Returns the size of the nonce cache fn nonce_cache_size(&self) -> &usize; } @@ -52,9 +52,11 @@ impl DepotExt for Depot { self.obtain::>().expect("Config not found") } - fn nonce_cache(&self) -> &NonceCache { - self.obtain::>() - .expect("Nonce cache not found") + fn nonce_cache(&self) -> Arc { + Arc::clone( + self.obtain::>() + .expect("Nonce cache not found"), + ) } fn nonce_cache_size(&self) -> &usize { diff --git a/crates/oxidetalis/src/middlewares/signature.rs b/crates/oxidetalis/src/middlewares/signature.rs index b75dfbe..5dff94b 100644 --- a/crates/oxidetalis/src/middlewares/signature.rs +++ b/crates/oxidetalis/src/middlewares/signature.rs @@ -72,7 +72,7 @@ pub async fn signature_check( } }; - if !utils::is_valid_nonce(&signature, depot.nonce_cache(), depot.nonce_cache_size()) + if !utils::is_valid_nonce(&signature, &depot.nonce_cache(), depot.nonce_cache_size()) || !utils::is_valid_signature( &sender_public_key, &depot.config().server.private_key,