Skip to main content

OtpStore

Trait OtpStore 

Source
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§

Source

fn insert( &self, record: OtpRecord, ) -> impl Future<Output = OtpResult<()>> + Send

Insert a new OTP record.

Source

fn find_by_hash( &self, hash: &[u8], ) -> impl Future<Output = OtpResult<Option<OtpRecord>>> + Send

Find a record by its token hash.

Source

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.

Source

fn revoke(&self, id: &Uuid) -> impl Future<Output = OtpResult<()>> + Send

Mark a record as revoked.

Source

fn cleanup_expired(&self) -> impl Future<Output = OtpResult<u64>> + Send

Remove all expired records (RHELBU-3536 R12).

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§

Source§

impl OtpStore for DbOtpStore

Available on crate feature db only.
Source§

impl OtpStore for InMemoryOtpStore