Skip to main content

MemoryChallengeStore

Struct MemoryChallengeStore 

Source
pub struct MemoryChallengeStore { /* private fields */ }
Expand description

In-memory ChallengeStore: mutex-guarded map with lazy expiry and a capacity cap. Single-process only — state does not survive restarts (an unconsumed challenge dies with the process, which fails closed), and replicas sharing verification traffic would each accept the same challenge once. Deployments spanning processes or hosts need a ChallengeStore over shared storage whose consume is atomic (e.g. a single-row DELETE … RETURNING).

Implementations§

Source§

impl MemoryChallengeStore

Source

pub fn new(max_size: usize) -> Self

Create a store holding at most max_size pending challenges.

§Panics

Panics if max_size is 0 — a store that can never hold a challenge is a misconfiguration, not a policy.

Trait Implementations§

Source§

impl ChallengeStore for MemoryChallengeStore

Source§

fn issue( &self, session_context: &[u8], ttl_seconds: i64, ) -> Result<(Vec<u8>, i64), String>

Generate a fresh challenge bound to session_context (which must be empty or exactly 32 bytes; empty = unbound), valid for ttl_seconds (which must be positive). Returns the challenge and its expiry (unix seconds).
Source§

fn validate( &self, challenge: &[u8], session_context: &[u8], now: i64, ) -> Result<(), String>

Report whether challenge could be consumed right now — issued, unexpired, unconsumed, and bound to session_context — WITHOUT consuming it. verify_bundle calls this before any signature work.
Source§

fn consume( &self, challenge: &[u8], session_context: &[u8], now: i64, ) -> Result<(), String>

Atomically remove the challenge’s issuance record. Exactly one consume of a given challenge may ever succeed; all later calls (and calls with a mismatched session_context, which do NOT remove the record) return an error. Removing the record keeps the store’s capacity a count of PENDING challenges — a consumed challenge frees its slot immediately.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.