pub struct AuthConfig { /* private fields */ }Expand description
Loaded bearer-token validator. Constructed once at startup; cloneable
across handlers via Arc<AuthConfig>.
Implementations§
Source§impl AuthConfig
impl AuthConfig
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Load tokens from a file. One token per line; blank lines and lines
starting with # are ignored. Trailing whitespace is trimmed from
each token. Returns an error if the file is empty after parsing.
Sourcepub fn from_inline(token: &str) -> Result<Self>
pub fn from_inline(token: &str) -> Result<Self>
Build from a single inline token. The caller is expected to have already trimmed; we trim defensively to catch obvious mistakes.
Sourcepub fn token_count(&self) -> usize
pub fn token_count(&self) -> usize
Number of distinct tokens loaded. For startup logging only — never log the tokens themselves.
Sourcepub fn validate(&self, presented: &[u8]) -> bool
pub fn validate(&self, presented: &[u8]) -> bool
Validate a presented token in constant time relative to the length
of the candidate set. Returns true iff the presented token byte-
equals one of the loaded tokens.
The comparison is constant-time per candidate (no early exit on first mismatching byte); the loop over candidates is linear, which is fine because the operator controls the candidate count and it is small (typically 1–10). An attacker cannot insert candidates, so the linear scan does not leak exploitable timing information.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AuthConfig
impl RefUnwindSafe for AuthConfig
impl Send for AuthConfig
impl Sync for AuthConfig
impl Unpin for AuthConfig
impl UnwindSafe for AuthConfig
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more