pub struct HotpManager { /* private fields */ }Expand description
HOTP manager for generating and validating counter-based OTPs.
Implementations§
Source§impl HotpManager
impl HotpManager
Sourcepub fn new(config: HotpConfig) -> Self
pub fn new(config: HotpConfig) -> Self
Create a new HOTP manager with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new HOTP manager with default configuration.
Sourcepub fn generate_secret() -> Result<String>
pub fn generate_secret() -> Result<String>
Generate a cryptographically random 20-byte secret encoded as RFC 4648 Base32 (with padding).
Sourcepub fn generate(&self, secret_b32: &str, counter: u64) -> Result<String>
pub fn generate(&self, secret_b32: &str, counter: u64) -> Result<String>
Generate an HOTP code for the given secret and counter value.
Implements RFC 4226 §5.3 — Dynamic Truncation.
Sourcepub fn validate(
&self,
secret_b32: &str,
counter: u64,
code: &str,
) -> Result<Option<u64>>
pub fn validate( &self, secret_b32: &str, counter: u64, code: &str, ) -> Result<Option<u64>>
Validate an HOTP code against the expected counter value.
On success, returns the counter value that matched (which may be
ahead of counter by up to look_ahead_window). The caller should
persist matched_counter + 1 as the new expected counter.
Auto Trait Implementations§
impl Freeze for HotpManager
impl RefUnwindSafe for HotpManager
impl Send for HotpManager
impl Sync for HotpManager
impl Unpin for HotpManager
impl UnsafeUnpin for HotpManager
impl UnwindSafe for HotpManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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>
Converts
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>
Converts
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