Move directories, fix http, clippy

This commit is contained in:
asonix 2022-11-28 18:34:13 -06:00
parent 0068556382
commit 670dd5129d
34 changed files with 50 additions and 22 deletions

View file

@ -13,11 +13,11 @@ edition = "2021"
[workspace] [workspace]
members = [ members = [
"http-signature-normalization-actix", "actix",
"http-signature-normalization-actix-extractor", "actix-extractor",
"http-signature-normalization-http", "http",
"http-signature-normalization-reqwest", "reqwest",
# "http-signature-normalization-warp", # "warp",
] ]
[dependencies] [dependencies]

View file

@ -178,9 +178,7 @@ where
.map_err(Into::into)?; .map_err(Into::into)?;
let digest_parts = if D::REQUIRED { let digest_parts = if D::REQUIRED {
req.headers() req.headers().get("digest").and_then(parse_digest)
.get("digest")
.and_then(|digest| parse_digest(digest))
} else { } else {
None None
}; };
@ -214,10 +212,8 @@ where
return Err(Error::Signature.into()); return Err(Error::Signature.into());
} }
if D::REQUIRED { if D::REQUIRED && !digest_verifier.verify(digest_parts.as_deref().unwrap_or(&[])) {
if !digest_verifier.verify(digest_parts.as_deref().unwrap_or(&[])) { return Err(Error::Digest.into());
return Err(Error::Digest.into());
}
} }
let signature = Signature { let signature = Signature {

View file

@ -1,7 +1,7 @@
[package] [package]
name = "http-signature-normalization-http" name = "http-signature-normalization-http"
description = "An HTTP Signatures library that leaves the signing to you" description = "An HTTP Signatures library that leaves the signing to you"
version = "0.4.0" version = "0.5.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
license-file = "../LICENSE" license-file = "../LICENSE"
readme = "../README.md" readme = "../README.md"

View file

@ -57,6 +57,15 @@ pub enum PrepareVerifyError {
Header(ToStrError), Header(ToStrError),
} }
#[derive(Debug)]
/// Errors produced when preparing to sign an Http Signature
pub enum PrepareSignError {
/// There was an error in the underlying library
Required(http_signature_normalization::RequiredError),
/// There was an error producing a String from the HeaderValue
Header(ToStrError),
}
impl Config { impl Config {
/// Begin the process of signing a request /// Begin the process of signing a request
/// ///
@ -66,7 +75,7 @@ impl Config {
method: &Method, method: &Method,
path_and_query: Option<&PathAndQuery>, path_and_query: Option<&PathAndQuery>,
headers: HeaderMap, headers: HeaderMap,
) -> Result<Unsigned, ToStrError> { ) -> Result<Unsigned, PrepareSignError> {
let headers = headers let headers = headers
.iter() .iter()
.map(|(k, v)| v.to_str().map(|v| (k.to_string(), v.to_string()))) .map(|(k, v)| v.to_str().map(|v| (k.to_string(), v.to_string())))
@ -74,11 +83,11 @@ impl Config {
let path_and_query = path_and_query let path_and_query = path_and_query
.map(|p| p.to_string()) .map(|p| p.to_string())
.unwrap_or(String::from("/")); .unwrap_or_else(|| String::from("/"));
let unsigned = self let unsigned = self
.config .config
.begin_sign(&method.to_string(), &path_and_query, headers); .begin_sign(method.as_ref(), &path_and_query, headers)?;
Ok(Unsigned { unsigned }) Ok(Unsigned { unsigned })
} }
@ -99,11 +108,11 @@ impl Config {
let path_and_query = path_and_query let path_and_query = path_and_query
.map(|p| p.to_string()) .map(|p| p.to_string())
.unwrap_or(String::from("/")); .unwrap_or_else(|| String::from("/"));
let unverified = self let unverified = self
.config .config
.begin_verify(&method.to_string(), &path_and_query, headers)?; .begin_verify(method.as_ref(), &path_and_query, headers)?;
Ok(unverified) Ok(unverified)
} }
@ -118,14 +127,16 @@ impl fmt::Display for PrepareVerifyError {
} }
} }
impl Error for PrepareVerifyError { impl fmt::Display for PrepareSignError {
fn description(&self) -> &str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
PrepareVerifyError::Sig(ref e) => e.description(), PrepareSignError::Required(ref e) => write!(f, "Required error, {}", e),
PrepareVerifyError::Header(ref e) => e.description(), PrepareSignError::Header(ref e) => write!(f, "Header error, {}", e),
} }
} }
}
impl Error for PrepareVerifyError {
fn source(&self) -> Option<&(dyn Error + 'static)> { fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self { match *self {
PrepareVerifyError::Sig(ref e) => Some(e), PrepareVerifyError::Sig(ref e) => Some(e),
@ -134,6 +145,15 @@ impl Error for PrepareVerifyError {
} }
} }
impl Error for PrepareSignError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
PrepareSignError::Required(ref e) => Some(e),
PrepareSignError::Header(ref e) => Some(e),
}
}
}
impl From<http_signature_normalization::PrepareVerifyError> for PrepareVerifyError { impl From<http_signature_normalization::PrepareVerifyError> for PrepareVerifyError {
fn from(e: http_signature_normalization::PrepareVerifyError) -> Self { fn from(e: http_signature_normalization::PrepareVerifyError) -> Self {
PrepareVerifyError::Sig(e) PrepareVerifyError::Sig(e)
@ -145,3 +165,15 @@ impl From<ToStrError> for PrepareVerifyError {
PrepareVerifyError::Header(e) PrepareVerifyError::Header(e)
} }
} }
impl From<http_signature_normalization::RequiredError> for PrepareSignError {
fn from(e: http_signature_normalization::RequiredError) -> Self {
PrepareSignError::Required(e)
}
}
impl From<ToStrError> for PrepareSignError {
fn from(e: ToStrError) -> Self {
PrepareSignError::Header(e)
}
}