mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-22 01:11:00 +00:00
Simplify passing verifier
This commit is contained in:
parent
51bd0ad1ef
commit
1d37ebb812
1 changed files with 10 additions and 15 deletions
|
@ -35,16 +35,13 @@ pub enum ParseDigestError {
|
||||||
#[error("Could not parse request body")]
|
#[error("Could not parse request body")]
|
||||||
pub struct ParseBodyError;
|
pub struct ParseBodyError;
|
||||||
|
|
||||||
pub fn verify_digest_bytes<D>(
|
pub fn verify_digest_bytes(
|
||||||
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
|
verifier: impl DigestVerify + Clone + Send,
|
||||||
) -> impl Filter<Extract = (Bytes,), Error = Rejection> + Clone
|
) -> impl Filter<Extract = (Bytes,), Error = Rejection> + Clone {
|
||||||
where
|
parse_digest_header()
|
||||||
D: DigestVerify + Send,
|
|
||||||
{
|
|
||||||
verifier
|
|
||||||
.and(parse_digest_header())
|
|
||||||
.and(body::bytes())
|
.and(body::bytes())
|
||||||
.and_then(|mut verifier: D, parts: Vec<DigestPart>, bytes: Bytes| {
|
.and_then(move |parts: Vec<DigestPart>, bytes: Bytes| {
|
||||||
|
let mut verifier = verifier.clone();
|
||||||
async move {
|
async move {
|
||||||
if verifier.verify(&parts, &bytes) {
|
if verifier.verify(&parts, &bytes) {
|
||||||
Ok(bytes)
|
Ok(bytes)
|
||||||
|
@ -55,11 +52,10 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_digest_json<D, T>(
|
pub fn verify_digest_json<T>(
|
||||||
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
|
verifier: impl DigestVerify + Clone + Send
|
||||||
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
|
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
|
||||||
where
|
where
|
||||||
D: DigestVerify + Send,
|
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {
|
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {
|
||||||
|
@ -69,11 +65,10 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_digest_form<D, T>(
|
pub fn verify_digest_form<T>(
|
||||||
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
|
verifier: impl DigestVerify + Clone + Send,
|
||||||
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
|
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
|
||||||
where
|
where
|
||||||
D: DigestVerify + Send,
|
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {
|
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {
|
||||||
|
|
Loading…
Reference in a new issue