This commit is contained in:
asonix 2020-04-25 20:31:38 -05:00
parent 1997d54b36
commit a0974299c5
2 changed files with 16 additions and 17 deletions

View file

@ -53,17 +53,17 @@ use self::{
verify::{ParseSignatureError, ParsedHeader, Unverified, ValidateError}, verify::{ParseSignatureError, ParsedHeader, Unverified, ValidateError},
}; };
const REQUEST_TARGET: &'static str = "(request-target)"; const REQUEST_TARGET: &str = "(request-target)";
const CREATED: &'static str = "(created)"; const CREATED: &str = "(created)";
const EXPIRES: &'static str = "(expires)"; const EXPIRES: &str = "(expires)";
const KEY_ID_FIELD: &'static str = "keyId"; const KEY_ID_FIELD: &str = "keyId";
const ALGORITHM_FIELD: &'static str = "algorithm"; const ALGORITHM_FIELD: &str = "algorithm";
const ALGORITHM_VALUE: &'static str = "hs2019"; const ALGORITHM_VALUE: &str = "hs2019";
const CREATED_FIELD: &'static str = "created"; const CREATED_FIELD: &str = "created";
const EXPIRES_FIELD: &'static str = "expires"; const EXPIRES_FIELD: &str = "expires";
const HEADERS_FIELD: &'static str = "headers"; const HEADERS_FIELD: &str = "headers";
const SIGNATURE_FIELD: &'static str = "signature"; const SIGNATURE_FIELD: &str = "signature";
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
/// Configuration for signing and verifying signatures /// Configuration for signing and verifying signatures
@ -124,8 +124,7 @@ impl Config {
/// Mark a header as required /// Mark a header as required
pub fn require_header(mut self, header: &str) -> Self { pub fn require_header(mut self, header: &str) -> Self {
self.required_headers self.required_headers.insert(header.to_lowercase());
.insert(header.to_lowercase().to_owned());
self self
} }
@ -181,7 +180,7 @@ impl Config {
) -> Result<Unverified, PrepareVerifyError> { ) -> Result<Unverified, PrepareVerifyError> {
let mut headers: BTreeMap<String, String> = headers let mut headers: BTreeMap<String, String> = headers
.into_iter() .into_iter()
.map(|(k, v)| (k.to_lowercase().to_owned(), v)) .map(|(k, v)| (k.to_lowercase(), v))
.collect(); .collect();
let header = headers let header = headers
@ -230,7 +229,7 @@ fn build_signing_string(
) -> Result<String, RequiredError> { ) -> Result<String, RequiredError> {
let request_target = format!("{} {}", method.to_string().to_lowercase(), path_and_query); let request_target = format!("{} {}", method.to_string().to_lowercase(), path_and_query);
btm.insert(REQUEST_TARGET.to_owned(), request_target.clone()); btm.insert(REQUEST_TARGET.to_owned(), request_target);
if let Some(created) = created { if let Some(created) = created {
btm.insert(CREATED.to_owned(), created.timestamp().to_string()); btm.insert(CREATED.to_owned(), created.timestamp().to_string());
} }

View file

@ -249,7 +249,7 @@ impl FromStr for ParsedHeader {
let mut hm: HashMap<String, String> = s let mut hm: HashMap<String, String> = s
.split(',') .split(',')
.filter_map(|part| { .filter_map(|part| {
let mut i = part.splitn(2, "="); let mut i = part.splitn(2, '=');
if let Some(key) = i.next() { if let Some(key) = i.next() {
if let Some(value) = i.next() { if let Some(value) = i.next() {
@ -271,7 +271,7 @@ impl FromStr for ParsedHeader {
.remove(HEADERS_FIELD) .remove(HEADERS_FIELD)
.map(|h| h.split_whitespace().map(|s| s.to_owned()).collect()) .map(|h| h.split_whitespace().map(|s| s.to_owned()).collect())
.unwrap_or_else(|| vec![CREATED.to_owned()]), .unwrap_or_else(|| vec![CREATED.to_owned()]),
algorithm: hm.remove(ALGORITHM_FIELD).map(|s| Algorithm::from(s)), algorithm: hm.remove(ALGORITHM_FIELD).map(Algorithm::from),
created: parse_time(&mut hm, CREATED_FIELD)?, created: parse_time(&mut hm, CREATED_FIELD)?,
expires: parse_time(&mut hm, EXPIRES_FIELD)?, expires: parse_time(&mut hm, EXPIRES_FIELD)?,
parsed_at: Utc::now(), parsed_at: Utc::now(),
@ -352,7 +352,7 @@ impl fmt::Display for DeprecatedAlgorithm {
impl fmt::Display for Algorithm { impl fmt::Display for Algorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Algorithm::Hs2019 => write!(f, "{}", "hs2019"), Algorithm::Hs2019 => write!(f, "hs2019"),
Algorithm::Deprecated(d) => d.fmt(f), Algorithm::Deprecated(d) => d.fmt(f),
Algorithm::Unknown(other) => write!(f, "{}", other), Algorithm::Unknown(other) => write!(f, "{}", other),
} }