Skip to main content

aria2_core/auth/
mod.rs

1//! HTTP Authentication module
2//!
3//! Provides implementations for HTTP authentication schemes:
4//! - **Basic** (RFC 7617) - Simple username/password authentication
5//! - **Digest** (RFC 7616) - Challenge-response authentication with MD5/SHA256/SHA512
6//!
7//! # Security Features
8//! - All credentials are wrapped in `Secret<T>` for automatic memory zeroing on drop
9//! - HTTPS-only enforcement option to prevent credential leakage over insecure connections
10//! - Atomic nonce counters to prevent replay attacks in Digest authentication
11//!
12//! # Examples
13//!
14//! ## Basic Authentication
15//!
16//! ```rust,no_run
17//! use aria2_core::auth::basic_auth::BasicAuthProvider;
18//! use aria2_core::auth::digest_auth::{AuthChallenge, AuthProvider, AuthScheme};
19//!
20//! let provider = BasicAuthProvider::new("admin".to_string(), "secret123".to_string(), true);
21//! assert_eq!(provider.scheme(), AuthScheme::Basic);
22//! let challenge = AuthChallenge { scheme: AuthScheme::Basic, realm: String::new(), nonce: None, opaque: None, qop: None, stale: false };
23//! let header = provider.build_authorization_header(&challenge).unwrap();
24//! // header contains Base64-encoded credentials
25//! ```
26//!
27//! ## Digest Authentication
28//!
29//! ```rust,no_run
30//! use aria2_core::auth::digest_auth::{DigestAuthProvider, AuthProvider, AuthScheme, DigestAlgorithm, parse_www_authenticate};
31//!
32//! let provider = DigestAuthProvider::new("alice".to_string(), "p@ssw0rd".to_string(), None);
33//! let scheme = provider.scheme();
34//! assert!(matches!(scheme, AuthScheme::Digest { .. }));
35//!
36//! // Parse server challenge from WWW-Authenticate header
37//! let challenge = parse_www_authenticate(
38//!     "Digest realm=\"secure\", nonce=\"abc123\", qop=\"auth\", algorithm=MD5"
39//! ).unwrap();
40//!
41//! let _response = provider.build_authorization_header_with_method(&challenge, "GET", "/protected", None);
42//! // response contains the computed Authorization header value
43//! ```
44//!
45//! ## Credential Store Integration
46//!
47//! ```rust,no_run
48//! use aria2_core::auth::credential_store::{CredentialStore, PasswordEntry};
49//!
50//! let store = CredentialStore::new();
51//! store.store("api.example.com", "user", b"pass");
52//!
53//! if let Some(cred) = store.get("api.example.com") {
54//!     println!("Found credentials for user: {}", cred.username);
55//! }
56//! ```
57
58pub mod basic_auth;
59pub mod credential_store;
60pub mod digest_auth;
61
62pub use digest_auth::{AuthChallenge, AuthProvider, AuthScheme};