chore: Returns nonce cache as Arc

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-03 12:18:45 +03:00
parent f47bc82b19
commit e15c693421
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
2 changed files with 7 additions and 5 deletions

View file

@ -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<NonceCache>;
/// Returns the size of the nonce cache
fn nonce_cache_size(&self) -> &usize;
}
@ -52,9 +52,11 @@ impl DepotExt for Depot {
self.obtain::<Arc<Config>>().expect("Config not found")
}
fn nonce_cache(&self) -> &NonceCache {
self.obtain::<Arc<NonceCache>>()
.expect("Nonce cache not found")
fn nonce_cache(&self) -> Arc<NonceCache> {
Arc::clone(
self.obtain::<Arc<NonceCache>>()
.expect("Nonce cache not found"),
)
}
fn nonce_cache_size(&self) -> &usize {

View file

@ -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,