use async_trait::async_trait; use std::collections::{HashMap, HashSet}; use tokio::sync::Mutex; use voprf::*; use privacypass::batched_tokens::server::*; use privacypass::{Nonce, NonceStore, TokenKeyId}; #[derive(Default)] pub struct MemoryNonceStore { nonces: Mutex>, } #[async_trait] impl NonceStore for MemoryNonceStore { async fn exists(&self, nonce: &Nonce) -> bool { let nonces = self.nonces.lock().await; nonces.contains(nonce) } async fn insert(&self, nonce: Nonce) { let mut nonces = self.nonces.lock().await; nonces.insert(nonce); } } #[derive(Default)] pub struct MemoryKeyStore { keys: Mutex>>, } #[async_trait] impl BatchedKeyStore for MemoryKeyStore { async fn insert(&self, token_key_id: TokenKeyId, server: VoprfServer) { let mut keys = self.keys.lock().await; keys.insert(token_key_id, server); } async fn get(&self, token_key_id: &TokenKeyId) -> Option> { self.keys.lock().await.get(token_key_id).cloned() } }