pub struct HmacTokenGenerator { /* private fields */ }Expand description
HMAC-based token generator for MVP.
Implementations§
Source§impl HmacTokenGenerator
impl HmacTokenGenerator
Sourcepub const MIN_SECRET_LEN: usize = 16
pub const MIN_SECRET_LEN: usize = 16
Minimum secret length in bytes for HMAC token generation.
Secrets shorter than this are rejected to prevent trivially forgeable tokens. 16 bytes (128 bits) is the minimum recommended for HMAC-SHA256.
Sourcepub fn new(secret: TokenSecret) -> Result<Self, TokenError>
pub fn new(secret: TokenSecret) -> Result<Self, TokenError>
Create a new HMAC token generator with a TokenSecret.
§Errors
Returns TokenError::SecretTooShort if the secret is shorter than
Self::MIN_SECRET_LEN (16 bytes).
Sourcepub fn new_from_bytes(bytes: impl Into<Vec<u8>>) -> Result<Self, TokenError>
pub fn new_from_bytes(bytes: impl Into<Vec<u8>>) -> Result<Self, TokenError>
Create from raw bytes (backward-compatible migration helper).
Wraps the bytes in a TokenSecret internally. Prefer constructing
a TokenSecret directly for new code.
§Errors
Returns TokenError::SecretTooShort if the secret is shorter than
Self::MIN_SECRET_LEN (16 bytes).
Trait Implementations§
Source§impl TokenGenerator for HmacTokenGenerator
impl TokenGenerator for HmacTokenGenerator
Source§fn generate(
&self,
code: &str,
user_id: &str,
session_id: &str,
server_id: &str,
context_hash: &str,
risk_level: RiskLevel,
ttl_seconds: i64,
) -> ApprovalToken
fn generate( &self, code: &str, user_id: &str, session_id: &str, server_id: &str, context_hash: &str, risk_level: RiskLevel, ttl_seconds: i64, ) -> ApprovalToken
Generate a signed approval token.
Source§fn verify(&self, token: &ApprovalToken) -> Result<(), ExecutionError>
fn verify(&self, token: &ApprovalToken) -> Result<(), ExecutionError>
Verify a token and return Ok if valid.
Source§fn verify_code(
&self,
code: &str,
token: &ApprovalToken,
) -> Result<(), ExecutionError>
fn verify_code( &self, code: &str, token: &ApprovalToken, ) -> Result<(), ExecutionError>
Verify that submitted code matches the token’s code hash.
Auto Trait Implementations§
impl Freeze for HmacTokenGenerator
impl RefUnwindSafe for HmacTokenGenerator
impl Send for HmacTokenGenerator
impl Sync for HmacTokenGenerator
impl Unpin for HmacTokenGenerator
impl UnsafeUnpin for HmacTokenGenerator
impl UnwindSafe for HmacTokenGenerator
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
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 moreCreates a shared type from an unshared type.