pub struct MagicCodeStore { /* private fields */ }Expand description
An in-memory magic code store for development.
Implementations§
Source§impl MagicCodeStore
impl MagicCodeStore
pub fn new() -> Self
Sourcepub fn create(&self, email: &str) -> String
pub fn create(&self, email: &str) -> String
Generate a 6-digit code for an email and return it. Subject to a
per-email cooldown — returns the error-shape via try_create.
Sourcepub fn try_create(&self, email: &str) -> Result<String, MagicCodeError>
pub fn try_create(&self, email: &str) -> Result<String, MagicCodeError>
Create a magic code, enforcing per-email cooldown. Returns the code or an error describing why one couldn’t be issued.
Sourcepub fn verify(&self, email: &str, code: &str) -> bool
pub fn verify(&self, email: &str, code: &str) -> bool
Verify a code for an email. Returns true if valid and not expired.
Uses constant-time comparison to prevent timing attacks.
Back-compat wrapper around [try_verify].
Sourcepub fn try_verify(&self, email: &str, code: &str) -> Result<(), MagicCodeError>
pub fn try_verify(&self, email: &str, code: &str) -> Result<(), MagicCodeError>
Verify a code. Returns a typed error so callers can surface specific
messages. On the MAX_ATTEMPTS-th failure, the code is burned — even
correct subsequent attempts return TooManyAttempts.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MagicCodeStore
impl RefUnwindSafe for MagicCodeStore
impl Send for MagicCodeStore
impl Sync for MagicCodeStore
impl Unpin for MagicCodeStore
impl UnsafeUnpin for MagicCodeStore
impl UnwindSafe for MagicCodeStore
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
Mutably borrows from an owned value. Read more