pub struct CanaryTokenStore { /* private fields */ }Expand description
A thread-safe, per-tenant canary token store.
Uses Arc<RwLock<HashMap<String, Vec<CanaryToken>>>> internally so it can
be shared across async tasks and threads.
§Examples
use llmtrace_security::canary::{CanaryConfig, CanaryToken, CanaryTokenStore};
let store = CanaryTokenStore::new();
let config = CanaryConfig::default();
let token = CanaryToken::generate(&config);
let token_string = token.token.clone();
store.add("tenant-1", token);
assert_eq!(store.get("tenant-1").len(), 1);
store.remove("tenant-1", &token_string);
assert!(store.get("tenant-1").is_empty());Implementations§
Source§impl CanaryTokenStore
impl CanaryTokenStore
Sourcepub fn add(&self, tenant_id: &str, token: CanaryToken)
pub fn add(&self, tenant_id: &str, token: CanaryToken)
Add a canary token for the given tenant.
Sourcepub fn remove(&self, tenant_id: &str, token_str: &str) -> bool
pub fn remove(&self, tenant_id: &str, token_str: &str) -> bool
Remove a canary token (by token string) for the given tenant.
Returns true if a token was removed, false otherwise.
Sourcepub fn get(&self, tenant_id: &str) -> Vec<CanaryToken>
pub fn get(&self, tenant_id: &str) -> Vec<CanaryToken>
Get all canary tokens for a tenant (cloned).
Returns an empty Vec if the tenant has no tokens.
Sourcepub fn tenant_count(&self) -> usize
pub fn tenant_count(&self) -> usize
Return the number of tenants with registered tokens.
Sourcepub fn token_count(&self) -> usize
pub fn token_count(&self) -> usize
Return the total number of tokens across all tenants.
Trait Implementations§
Source§impl Clone for CanaryTokenStore
impl Clone for CanaryTokenStore
Source§fn clone(&self) -> CanaryTokenStore
fn clone(&self) -> CanaryTokenStore
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CanaryTokenStore
impl Debug for CanaryTokenStore
Auto Trait Implementations§
impl Freeze for CanaryTokenStore
impl RefUnwindSafe for CanaryTokenStore
impl Send for CanaryTokenStore
impl Sync for CanaryTokenStore
impl Unpin for CanaryTokenStore
impl UnsafeUnpin for CanaryTokenStore
impl UnwindSafe for CanaryTokenStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more