pub struct MfaRecord {Show 16 fields
pub version: u8,
pub access_key: String,
pub algorithm: String,
pub digits: u8,
pub period_seconds: u32,
pub secret_b32: Option<String>,
pub pending_secret_b32: Option<String>,
pub pending_expires_at: Option<OffsetDateTime>,
pub created_at: OffsetDateTime,
pub activated_at: Option<OffsetDateTime>,
pub last_verified_at: Option<OffsetDateTime>,
pub last_used_step: Option<u64>,
pub recovery_codes: Vec<StoredRecoveryCode>,
pub recovery_codes_generated_at: Option<OffsetDateTime>,
pub failed_attempts: u32,
pub locked_until: Option<OffsetDateTime>,
}Expand description
The persisted MFA state for one identity.
Field-level notes:
secret_b32present means the second factor is active.pending_secret_b32present and unexpired means an enrollment awaits confirmation. Both may be present at once, which is a re-configuration.last_used_stepis the anti-replay high-water mark, not a timestamp.
Fields§
§version: u8§access_key: String§algorithm: String§digits: u8§period_seconds: u32§secret_b32: Option<String>§pending_secret_b32: Option<String>§pending_expires_at: Option<OffsetDateTime>§created_at: OffsetDateTime§activated_at: Option<OffsetDateTime>§last_verified_at: Option<OffsetDateTime>§last_used_step: Option<u64>§recovery_codes: Vec<StoredRecoveryCode>§recovery_codes_generated_at: Option<OffsetDateTime>§failed_attempts: u32§locked_until: Option<OffsetDateTime>Implementations§
Source§impl MfaRecord
impl MfaRecord
Sourcepub fn new(access_key: &str, now: OffsetDateTime) -> Self
pub fn new(access_key: &str, now: OffsetDateTime) -> Self
A record with nothing enrolled.
Sourcepub fn validate_version(&self) -> Result<(), MfaRecordError>
pub fn validate_version(&self) -> Result<(), MfaRecordError>
Reject a record this build cannot interpret.
Sourcepub const fn is_enabled(&self) -> bool
pub const fn is_enabled(&self) -> bool
Whether a second factor is active.
Sourcepub fn has_pending_enrollment(&self, now: OffsetDateTime) -> bool
pub fn has_pending_enrollment(&self, now: OffsetDateTime) -> bool
Whether an enrollment is awaiting confirmation.
Sourcepub fn recovery_codes_remaining(&self) -> u32
pub fn recovery_codes_remaining(&self) -> u32
Recovery codes still usable.
Sourcepub fn lock_remaining_seconds(&self, now: OffsetDateTime) -> Option<u64>
pub fn lock_remaining_seconds(&self, now: OffsetDateTime) -> Option<u64>
Whether verification is currently refused because of prior failures.
Sourcepub fn begin_enrollment(&mut self, secret: &TotpSecret, now: OffsetDateTime)
pub fn begin_enrollment(&mut self, secret: &TotpSecret, now: OffsetDateTime)
Start (or restart) an enrollment.
Overwrites any earlier pending secret: a user who reopened the setup dialog expects a fresh QR, and the previous unconfirmed secret has no standing. The active secret is untouched, so a re-configuration cannot lock the user out if they abandon it.
Sourcepub fn activate_enrollment(
&mut self,
code: &str,
now: OffsetDateTime,
) -> Result<(), MfaVerifyError>
pub fn activate_enrollment( &mut self, code: &str, now: OffsetDateTime, ) -> Result<(), MfaVerifyError>
Confirm the pending enrollment with code.
On success the pending secret becomes active, the replay high-water mark is seeded with the step that was just proven, and the caller is expected to install a fresh set of recovery codes.
Sourcepub fn verify(
&mut self,
code: &str,
now: OffsetDateTime,
) -> Result<MfaVerification, MfaVerifyError>
pub fn verify( &mut self, code: &str, now: OffsetDateTime, ) -> Result<MfaVerification, MfaVerifyError>
Verify a second factor against the active enrollment.
Accepts either a TOTP code or a recovery code and decides which by shape, so a client never has to ask the user to declare what they typed.
Sourcepub fn set_recovery_codes(
&mut self,
codes: Vec<StoredRecoveryCode>,
now: OffsetDateTime,
)
pub fn set_recovery_codes( &mut self, codes: Vec<StoredRecoveryCode>, now: OffsetDateTime, )
Replace the recovery code set.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MfaRecord
impl<'de> Deserialize<'de> for MfaRecord
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>,
Auto Trait Implementations§
impl Forget for MfaRecord
impl Freeze for MfaRecordwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
NonZero<i32>: Freeze,
PhantomData<StoredRecoveryCode>: Freeze,
impl Move for MfaRecord
impl RefUnwindSafe for MfaRecord
impl Send for MfaRecord
impl Sync for MfaRecord
impl Unpin for MfaRecord
impl UnsafeUnpin for MfaRecordwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
NonZeroI32Inner: UnsafeUnpin,
PhantomData<StoredRecoveryCode>: UnsafeUnpin,
impl UnwindSafe for MfaRecord
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request