Skip to main content

DigestAuthProvider

Struct DigestAuthProvider 

Source
pub struct DigestAuthProvider { /* private fields */ }
Expand description

Digest authentication provider implementing RFC 7616.

This provider handles the complex challenge-response protocol required for Digest authentication, including:

  • HA1 computation (hash of username:realm:password)
  • HA2 computation (hash of method:uri or method:uri:entity_hash)
  • Response computation (KD function combining HA1 with challenge parameters)
  • Atomic nonce counter management for replay attack prevention

Implementations§

Source§

impl DigestAuthProvider

Source

pub fn new( username: String, password: String, algorithm: Option<DigestAlgorithm>, ) -> Self

Creates a new Digest authentication provider.

§Arguments
  • username - The username for authentication
  • password - The password for authentication
  • algorithm - The hash algorithm to use (defaults to MD5)
Source

pub fn algorithm(&self) -> DigestAlgorithm

Returns the current hash algorithm being used.

Source

pub fn compute_ha1(&self, realm: &str) -> String

Computes HA1 = H(username:realm:password).

This is the first step in Digest authentication response calculation. The hash algorithm depends on the provider’s configured algorithm.

§Arguments
  • realm - The realm from the authentication challenge
§Returns

Hex-encoded hash string

Source

pub fn compute_ha2( &self, method: &str, uri: &str, qop: Option<&str>, entity_body: Option<&[u8]>, ) -> String

Computes HA2 = H(method:uri) or H(method:uri:H(entity-body)).

When qop is “auth-int”, includes the hash of the entity body.

§Arguments
  • method - HTTP method (GET, POST, etc.)
  • uri - Request URI
  • qop - Quality of protection mode
  • entity_body - Optional entity body for auth-int mode
§Returns

Hex-encoded hash string

Source

pub fn compute_response( &self, ha1: &str, nonce: &str, nonce_count: &str, cnonce: &str, qop: Option<&str>, ha2: &str, ) -> String

Computes the final response = KD(HA1, nonce:nc:cnonce:qop:HA2).

KD(secret, data) = H(concat(secret, “:”, data))

§Arguments
  • ha1 - Pre-computed HA1 value
  • nonce - Server-provided nonce
  • nonce_count - Hex-encoded 8-digit nonce count
  • cnonce - Client-generated nonce
  • qop - Quality of protection mode
  • ha2 - Pre-computed HA2 value
§Returns

Hex-encoded response string

Source

pub fn build_authorization_header_with_method( &self, challenge: &AuthChallenge, method: &str, uri: &str, entity_body: Option<&[u8]>, ) -> Result<String>

Builds a complete Digest Authorization header value.

Constructs all necessary components including:

  • Username, realm, nonce, uri
  • Algorithm specification
  • Response hash
  • Optional: qop, nc, cnonce, opaque
§Arguments
  • challenge - Server authentication challenge
  • method - HTTP method for the request
  • uri - Request URI
  • entity_body - Optional entity body for auth-int
§Returns

Complete Authorization header value starting with “Digest “

Source

pub fn reset_nonce_counter(&self)

Resets the nonce counter (useful for testing or new sessions).

Trait Implementations§

Source§

impl AuthProvider for DigestAuthProvider

Source§

fn scheme(&self) -> AuthScheme

Returns the authentication scheme this provider implements.
Source§

fn build_authorization_header( &self, _challenge: &AuthChallenge, ) -> Result<String>

Builds an Authorization header value based on the server’s challenge. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more