pub struct RecoveryCadence { /* private fields */ }Expand description
The persistent recovery-verification scheduler for one account on one device.
Construct it at setup with RecoveryCadence::armed_at_setup; drive it with
record_success, record_failure,
snooze, rearm, and declare_lost;
render state at now. All time arguments are explicit, so the whole
machine is deterministic under a mocked clock.
Implementations§
Source§impl RecoveryCadence
impl RecoveryCadence
Sourcepub fn armed_at_setup(now: Timestamp) -> Self
pub fn armed_at_setup(now: Timestamp) -> Self
Arm the ladder at account setup: the first prompt lands 7 days out.
Sourcepub const fn interval_for(consecutive_successes: u32) -> i64
pub const fn interval_for(consecutive_successes: u32) -> i64
The interval to the next prompt given the number of consecutive successes so far: 7 d for the initial check, 90 d after one success, 180 d (capped) after two.
Sourcepub const fn rewrap_due(&self) -> bool
pub const fn rewrap_due(&self) -> bool
Whether the repeated-failure (or explicit-loss) re-wrap threshold has tripped.
Sourcepub fn state(&self, now: Timestamp) -> VerificationState
pub fn state(&self, now: Timestamp) -> VerificationState
The state the UX should render at now.
Sourcepub fn record_success(&mut self, now: Timestamp)
pub fn record_success(&mut self, now: Timestamp)
Record a successful verification: advance the ladder, and clear the snooze and failure counters (a success re-arms the “consecutive” accounting).
Sourcepub fn record_failure(
&mut self,
now: Timestamp,
session: u64,
) -> VerificationState
pub fn record_failure( &mut self, now: Timestamp, session: u64, ) -> VerificationState
Record a failed verification during app session session. A failure keeps the
prompt due (it does not reschedule), but once
REWRAP_FAILURE_THRESHOLD failures span REWRAP_MIN_SESSIONS distinct
sessions the state escalates to VerificationState::RewrapDue. Returns the
state at now for the caller’s convenience.
Sourcepub fn snooze(
&mut self,
now: Timestamp,
dur: SnoozeDuration,
) -> VerificationState
pub fn snooze( &mut self, now: Timestamp, dur: SnoozeDuration, ) -> VerificationState
Snooze a due prompt. Permitted up to MAX_CONSECUTIVE_SNOOZES times; the
N+1-th request is a no-op that leaves the prompt in the persistent
VerificationState::Badge state. Returns the resulting state.
Sourcepub fn rearm(&mut self, now: Timestamp, _trigger: RearmTrigger)
pub fn rearm(&mut self, now: Timestamp, _trigger: RearmTrigger)
Re-arm the ladder back to the 7-day step (new device, secret rotation, or a completed restore-from-escrow), clearing snoozes and failures.
Sourcepub fn declare_lost(&mut self)
pub fn declare_lost(&mut self)
The user explicitly said “I lost it”: escalate straight to the guided re-wrap.
Sourcepub fn notify_facts(&self, now: Timestamp) -> RecoveryFacts
pub fn notify_facts(&self, now: Timestamp) -> RecoveryFacts
Project the scheduler into the flat facts the shared alert predicate consumes
(capsule_core::notify).
The direction matters: capsule-sdk depends on capsule-core and never the reverse, so
the predicate cannot read this scheduler. It is handed a projection instead, and this is
the only place that mapping exists — the ladder, the re-arm triggers, and the snooze
accounting stay owned here, and capsule_core::notify never recomputes them.
It is derived from state rather than from the fields, so the alert and
the prompt the UX renders can never disagree about whether a check is due. Two mappings
are worth stating:
VerificationState::Badgereportssnooze_budget_spent, which is what stops the alert being pre-armed as a notification while leaving the condition reported — the badge is persistent and non-blocking, and never escalates back into an alert.VerificationState::RewrapDueis due now, whatever the ladder says: repeated failure or an explicit “I lost it” is not a scheduled check. The alert class set is closed, sorecovery_check_dueis the only class that can carry it — which is why the escalation also ridesRecoveryFacts::rewrap_due, surfacing as the alert’srecoveryparameter. Without it the alert would be byte-identical to the routine ninety-day check, and the client could not know to route intoRecoveryClient::guided_rewraprather than a plain verification prompt.
Trait Implementations§
Source§impl Clone for RecoveryCadence
impl Clone for RecoveryCadence
Source§fn clone(&self) -> RecoveryCadence
fn clone(&self) -> RecoveryCadence
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RecoveryCadence
impl Debug for RecoveryCadence
Source§impl<'de> Deserialize<'de> for RecoveryCadence
impl<'de> Deserialize<'de> for RecoveryCadence
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RecoveryCadence
Source§impl PartialEq for RecoveryCadence
impl PartialEq for RecoveryCadence
Source§fn eq(&self, other: &RecoveryCadence) -> bool
fn eq(&self, other: &RecoveryCadence) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for RecoveryCadence
impl Serialize for RecoveryCadence
impl StructuralPartialEq for RecoveryCadence
Auto Trait Implementations§
impl Freeze for RecoveryCadence
impl RefUnwindSafe for RecoveryCadence
impl Send for RecoveryCadence
impl Sync for RecoveryCadence
impl Unpin for RecoveryCadence
impl UnsafeUnpin for RecoveryCadence
impl UnwindSafe for RecoveryCadence
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§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