pub trait OtpStore: Send + Sync {
// Required methods
fn insert(
&self,
record: OtpRecord,
) -> impl Future<Output = OtpResult<()>> + Send;
fn find_by_hash(
&self,
hash: &[u8],
) -> impl Future<Output = OtpResult<Option<OtpRecord>>> + Send;
fn increment_uses(
&self,
id: &Uuid,
max_uses: u32,
) -> impl Future<Output = OtpResult<()>> + Send;
fn revoke(&self, id: &Uuid) -> impl Future<Output = OtpResult<()>> + Send;
fn cleanup_expired(&self) -> impl Future<Output = OtpResult<u64>> + Send;
}Expand description
Trait for pluggable OTP storage backends.
Implementors must be Send + Sync for use in async contexts.
Required Methods§
Sourcefn insert(
&self,
record: OtpRecord,
) -> impl Future<Output = OtpResult<()>> + Send
fn insert( &self, record: OtpRecord, ) -> impl Future<Output = OtpResult<()>> + Send
Insert a new OTP record.
Sourcefn find_by_hash(
&self,
hash: &[u8],
) -> impl Future<Output = OtpResult<Option<OtpRecord>>> + Send
fn find_by_hash( &self, hash: &[u8], ) -> impl Future<Output = OtpResult<Option<OtpRecord>>> + Send
Find a record by its token hash.
Sourcefn increment_uses(
&self,
id: &Uuid,
max_uses: u32,
) -> impl Future<Output = OtpResult<()>> + Send
fn increment_uses( &self, id: &Uuid, max_uses: u32, ) -> impl Future<Output = OtpResult<()>> + Send
Atomically increment the usage counter for a record.
The increment must only succeed when current_uses < max_uses,
preventing double-spend races where two concurrent validators
both read the same count and both increment. Returns
Err(OtpError::UsageLimitExceeded) if the OTP was already
fully consumed by a concurrent request.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl OtpStore for DbOtpStore
Available on crate feature
db only.