pub struct Authenticator { /* private fields */ }Expand description
A server that issues digest challenges and checks the answers.
Nonces are self-describing: each carries its issue time and a MAC over it, so this can recognise its own nonce and read its expiry without a table of every nonce ever issued. The only table is the replay window, which is bounded and holds nothing that has not been used.
Implementations§
Source§impl Authenticator
impl Authenticator
Sourcepub fn new(realm: impl Into<String>, secret: [u8; 32]) -> Self
pub fn new(realm: impl Into<String>, secret: [u8; 32]) -> Self
A server for a protection space.
secret keys the nonce MAC. It must be stable across restarts if in-flight nonces are
to survive one, and not shared with another realm, or a nonce issued for one protection
space is accepted in the other.
Sourcepub fn with_random_secret(realm: impl Into<String>) -> Self
pub fn with_random_secret(realm: impl Into<String>) -> Self
A server with a freshly generated secret.
Convenient, and it means every restart invalidates every outstanding nonce — which clients
recover from with stale=true, so it costs a round trip and not a login.
Sourcepub fn with_algorithm(self, algorithm: Algorithm) -> Self
pub fn with_algorithm(self, algorithm: Algorithm) -> Self
Challenge with this algorithm.
SHA-256 by default rather than MD5. RFC 8760 §2 exists because MD5 should not be the only thing on offer, and a server choosing the default is the only place that choice can be made — a client can only answer what it is asked.
Sourcepub fn with_lifetime(self, lifetime: Duration) -> Self
pub fn with_lifetime(self, lifetime: Duration) -> Self
How long an issued nonce stays valid.
Sourcepub fn challenge_header(proxy: bool) -> HeaderName
pub fn challenge_header(proxy: bool) -> HeaderName
The header a challenge goes in: WWW-Authenticate, or Proxy-Authenticate for a proxy.
Sourcepub fn challenge(&self, stale: bool) -> String
pub fn challenge(&self, stale: bool) -> String
Mint a challenge value, as it goes in the header.
stale says the previous credentials were right and only the nonce was old.
Sourcepub fn challenge_at(&self, stale: bool, now: u64) -> String
pub fn challenge_at(&self, stale: bool, now: u64) -> String
Authenticator::challenge with the clock supplied, so a test can pin it.
Sourcepub fn verify(
&mut self,
presented: &Presented,
method: &str,
password: &str,
) -> Verdict
pub fn verify( &mut self, presented: &Presented, method: &str, password: &str, ) -> Verdict
Check the credentials a request presented.
password is the one this server holds for presented.username; looking it up is the
caller’s job, because a credential store is not this crate’s business. method is the
request’s, since the digest covers it.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Authenticator
impl RefUnwindSafe for Authenticator
impl Send for Authenticator
impl Sync for Authenticator
impl Unpin for Authenticator
impl UnsafeUnpin for Authenticator
impl UnwindSafe for Authenticator
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