aboutsummaryrefslogtreecommitdiff
path: root/src/transaction/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transaction/auth.rs')
-rw-r--r--src/transaction/auth.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/src/transaction/auth.rs b/src/transaction/auth.rs
deleted file mode 100644
index 4c46f9b..0000000
--- a/src/transaction/auth.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-use crate::encoding::{
- headers::{Authorization, WWWAuthenticate},
- method::Method,
- request::Request,
- response::Response,
- uri::Uri,
-};
-use anyhow::Result;
-
-impl Authorization {
- pub fn construct(
- request: &Request,
- failed_response: &Response,
- username: &str,
- password: &str,
- ) -> Result<Authorization> {
- let challenge = failed_response.headers.get_res::<WWWAuthenticate>()?;
-
- Ok(Authorization {
- response: response_digest(
- username.to_string(),
- challenge.realm.clone(),
- password.to_string(),
- request.method,
- challenge.nonce.clone(),
- request.uri.clone(),
- ),
- nonce: challenge.nonce,
- realm: challenge.realm,
- uri: request.uri.to_string(),
- username: username.to_string(),
- })
- }
-}
-
-fn response_digest(
- username: String,
- realm: String,
- password: String,
- method: Method,
- nonce: String,
- uri: Uri,
-) -> String {
- let h = |s: String| hex::encode(md5::compute(s.as_bytes()).0);
- let kd = |secret, data| h(format!("{secret}:{data}"));
-
- let a1 = format!("{username}:{realm}:{password}");
- let a2 = format!("{method}:{uri}");
- let response_digest = kd(h(a1), format!("{nonce}:{}", h(a2)));
- return response_digest;
-}