pub struct OtpValidator<S: OtpStore> { /* private fields */ }Expand description
Validates and consumes OTP tokens.
Performs timing-safe hash comparison against the store to prevent timing side-channel attacks (RHELBU-3536 R8).
Implementations§
Source§impl<S: OtpStore> OtpValidator<S>
impl<S: OtpStore> OtpValidator<S>
Sourcepub async fn validate(
&self,
plaintext_token: &str,
) -> OtpResult<ValidationResult>
pub async fn validate( &self, plaintext_token: &str, ) -> OtpResult<ValidationResult>
Validate a plaintext OTP token.
Checks, in order:
- Token exists in the store (by SHA-256 hash lookup)
- Token is not revoked
- Token has not expired
- Token has not exceeded its max-use count
On success, increments the usage counter and returns entity
metadata for authorization. Single-use tokens are consumed
(marked with current_uses == max_uses) on first successful
validation.
§Timing Safety (RHELBU-3536 R8)
The store lookup is by hash, not by iterating and comparing plaintext values. The SHA-256 pre-image resistance ensures that even if an attacker observes lookup timing, they cannot infer the token value.
Auto Trait Implementations§
impl<S> Freeze for OtpValidator<S>where
S: Freeze,
impl<S> RefUnwindSafe for OtpValidator<S>where
S: RefUnwindSafe,
impl<S> Send for OtpValidator<S>
impl<S> Sync for OtpValidator<S>
impl<S> Unpin for OtpValidator<S>where
S: Unpin,
impl<S> UnsafeUnpin for OtpValidator<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for OtpValidator<S>where
S: UnwindSafe,
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