pub struct ChallengeManager { /* private fields */ }Expand description
A rotating challenge manager that produces and validates challenges.
In production this rotates on a reviewed schedule (e.g. every 30 seconds with a 5-second overlap). Tests can use fixed values.
Implementations§
Source§impl ChallengeManager
impl ChallengeManager
Sourcepub fn new(initial: ServerChallenge, overlap_seconds: u64) -> Self
pub fn new(initial: ServerChallenge, overlap_seconds: u64) -> Self
Create with an initial challenge and a rotation overlap. Self-rotation
is disabled: the caller drives Self::rotate explicitly.
Sourcepub fn rotating_for_domain(
domain: ReplayDomainGuarantee,
window_seconds: u64,
overlap_seconds: u64,
now: u64,
) -> Option<Self>
pub fn rotating_for_domain( domain: ReplayDomainGuarantee, window_seconds: u64, overlap_seconds: u64, now: u64, ) -> Option<Self>
Create a self-rotating manager seeded from the OS CSPRNG, for a deployment whose replay admission domain is a single verifier instance.
Rotation is lazy rather than timer-driven: the current challenge is regenerated when its window has elapsed, at the moment it is next needed. A server that stops serving therefore cannot leave a stale challenge advertised, and there is no rotation task to stall.
Returns None for any other replay domain. Challenge validity is
scoped to the replay admission domain and has one exact deadline
shared by verification and replay garbage collection (§4.7): an
independently random per-process challenge cannot provide that across
several verifiers, so a shared or affine-routed domain must install a
domain-wide challenge source instead of this one. Refusing here is why
a multi-instance deployment cannot silently disagree about challenge
freshness.
Sourcepub fn rotating_with<F>(
window_seconds: u64,
overlap_seconds: u64,
now: u64,
generator: F,
) -> Self
pub fn rotating_with<F>( window_seconds: u64, overlap_seconds: u64, now: u64, generator: F, ) -> Self
Self-rotating manager over an explicit value source. Production passes
random_challenge_value; tests pass a deterministic sequence.
Sourcepub fn current_or_rotate(&self, now: u64) -> Option<ServerChallenge>
pub fn current_or_rotate(&self, now: u64) -> Option<ServerChallenge>
The challenge to advertise on a denial, rotating first if the current window has elapsed.
Returns None only when the manager cannot produce one — a manager
with no value source whose challenges have all expired. The caller then
refuses service rather than advertising an unusable challenge.
Sourcepub fn current(&self, now: u64) -> Option<ServerChallenge>
pub fn current(&self, now: u64) -> Option<ServerChallenge>
Get the current (newest still-valid) challenge for attaching to
DispatchDenied. Returns None if rotation has stalled and all
challenges have expired — the caller must refuse service rather than
advertise an unusable challenge.
Sourcepub fn validate(&self, presented: &[u8], now: u64) -> Option<u64>
pub fn validate(&self, presented: &[u8], now: u64) -> Option<u64>
Validate a presented challenge against all still-acceptable values.
Returns the matched challenge’s accept_until if valid, or None.
This atomically returns the deadline so the caller can compute
min(proof.exp, accept_until) without a TOCTOU race against
rotation.
Auto Trait Implementations§
impl !Freeze for ChallengeManager
impl !RefUnwindSafe for ChallengeManager
impl Send for ChallengeManager
impl Sync for ChallengeManager
impl Unpin for ChallengeManager
impl UnsafeUnpin for ChallengeManager
impl !UnwindSafe for ChallengeManager
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more