aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/headers.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-05 23:37:39 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-05 23:37:39 +0200
commita4c52bedef04cfb927f3d7809680fed0425a5125 (patch)
tree96e11f458049a3944fbfd1bd30fe9826d385c80d /src/encoding/headers.rs
parentb5e408b02cd99a7833faab9b46d33042786c568c (diff)
downloadsip-rs-a4c52bedef04cfb927f3d7809680fed0425a5125.tar
sip-rs-a4c52bedef04cfb927f3d7809680fed0425a5125.tar.bz2
sip-rs-a4c52bedef04cfb927f3d7809680fed0425a5125.tar.zst
udp transport
Diffstat (limited to 'src/encoding/headers.rs')
-rw-r--r--src/encoding/headers.rs41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/encoding/headers.rs b/src/encoding/headers.rs
index b45cfd5..60dca7f 100644
--- a/src/encoding/headers.rs
+++ b/src/encoding/headers.rs
@@ -1,5 +1,5 @@
use super::{headermap::HeaderMap, method::Method};
-use anyhow::{anyhow, bail};
+use anyhow::{anyhow, bail, Result};
use std::{fmt::Display, str::FromStr};
macro_rules! header {
@@ -76,30 +76,25 @@ impl FromStr for WWWAuthenticate {
let kvs = s
.strip_prefix("Digest ")
.ok_or(anyhow!("type not digest"))?
- .split(", ")
+ .split(",")
.map(|e| {
let Some((k, v)) = e.split_once("=") else {
bail!("not a KV-pair")
};
- Ok((
- k.to_string(),
- v.strip_prefix("\"")
- .ok_or(anyhow!("start quote missing"))?
- .strip_suffix("\"")
- .ok_or(anyhow!("end quote missing"))?
- .to_string(),
- ))
+ Ok((k.trim().to_string(), v.trim().to_string()))
})
.try_collect::<HeaderMap>()?;
Ok(WWWAuthenticate {
- realm: kvs
- .get_raw("realm")
- .ok_or(anyhow!("realm missing"))?
- .to_string(),
- nonce: kvs
- .get_raw("nonce")
- .ok_or(anyhow!("nonce missing"))?
- .to_string(),
+ realm: unquote(
+ &kvs.get_raw("realm")
+ .ok_or(anyhow!("realm missing"))?
+ .to_string(),
+ )?,
+ nonce: unquote(
+ &kvs.get_raw("nonce")
+ .ok_or(anyhow!("nonce missing"))?
+ .to_string(),
+ )?,
})
}
}
@@ -126,7 +121,7 @@ impl Display for Authorization {
} = self;
write!(
f,
- "Digest username={username:?} realm={realm:?}, nonce={nonce:?}, uri={uri:?}, response={response:?}"
+ "Digest username={username:?},\r\n realm={realm:?},\r\n nonce={nonce:?},\r\n uri={uri:?},\r\n response={response:?},\r\n algorithm=MD5"
)
}
}
@@ -136,3 +131,11 @@ impl FromStr for Authorization {
todo!()
}
}
+
+pub fn unquote(v: &str) -> Result<String> {
+ Ok(v.strip_prefix("\"")
+ .ok_or(anyhow!("start quote missing"))?
+ .strip_suffix("\"")
+ .ok_or(anyhow!("end quote missing"))?
+ .to_string())
+}