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]
members = [
"http-signature-normalization-actix",
"http-signature-normalization-actix-extractor",
"http-signature-normalization-http",
"http-signature-normalization-reqwest",
# "http-signature-normalization-warp",
"actix",
"actix-extractor",
"http",
"reqwest",
# "warp",
]
[dependencies]

View file

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

View file

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

View file

@ -57,6 +57,15 @@ pub enum PrepareVerifyError {
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 {
/// Begin the process of signing a request
///
@ -66,7 +75,7 @@ impl Config {
method: &Method,
path_and_query: Option<&PathAndQuery>,
headers: HeaderMap,
) -> Result<Unsigned, ToStrError> {
) -> Result<Unsigned, PrepareSignError> {
let headers = headers
.iter()
.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
.map(|p| p.to_string())
.unwrap_or(String::from("/"));
.unwrap_or_else(|| String::from("/"));
let unsigned = self
.config
.begin_sign(&method.to_string(), &path_and_query, headers);
.begin_sign(method.as_ref(), &path_and_query, headers)?;
Ok(Unsigned { unsigned })
}
@ -99,11 +108,11 @@ impl Config {
let path_and_query = path_and_query
.map(|p| p.to_string())
.unwrap_or(String::from("/"));
.unwrap_or_else(|| String::from("/"));
let unverified = self
.config
.begin_verify(&method.to_string(), &path_and_query, headers)?;
.begin_verify(method.as_ref(), &path_and_query, headers)?;
Ok(unverified)
}
@ -118,14 +127,16 @@ impl fmt::Display for PrepareVerifyError {
}
}
impl Error for PrepareVerifyError {
fn description(&self) -> &str {
impl fmt::Display for PrepareSignError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
PrepareVerifyError::Sig(ref e) => e.description(),
PrepareVerifyError::Header(ref e) => e.description(),
PrepareSignError::Required(ref e) => write!(f, "Required error, {}", e),
PrepareSignError::Header(ref e) => write!(f, "Header error, {}", e),
}
}
}
impl Error for PrepareVerifyError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
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 {
fn from(e: http_signature_normalization::PrepareVerifyError) -> Self {
PrepareVerifyError::Sig(e)
@ -145,3 +165,15 @@ impl From<ToStrError> for PrepareVerifyError {
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)
}
}