mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-25 10:51:01 +00:00
Merge branch 'master' of git.asonix.dog:Aardwolf/http-signature-normalization
This commit is contained in:
commit
926ed7fc56
1 changed files with 15 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
use bytes::Buf;
|
use bytes::BytesMut;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use warp::{header, Filter, Rejection};
|
use warp::{header, Filter, Rejection};
|
||||||
|
|
||||||
|
@ -36,31 +36,27 @@ pub enum ParseDigestError {
|
||||||
#[error("Could not parse request body")]
|
#[error("Could not parse request body")]
|
||||||
pub struct ParseBodyError;
|
pub struct ParseBodyError;
|
||||||
|
|
||||||
pub fn verify<F>(
|
pub fn verify(
|
||||||
verifier: impl DigestVerify + Clone + Send + Sync + 'static,
|
verifier: impl DigestVerify + Clone + Send + Sync + 'static,
|
||||||
filter: F,
|
) -> impl Filter<Extract = ((),), Error = Rejection> + Clone {
|
||||||
) -> impl Filter<Extract = F::Extract, Error = Rejection> + Clone
|
parse_digest_header()
|
||||||
where
|
.and(warp::body::inspect_request_body(
|
||||||
F: Filter + Clone + Send + Sync + 'static,
|
BytesMut::new(),
|
||||||
F::Extract: warp::Reply,
|
move |mut acc, bytes| {
|
||||||
F::Error: Into<Rejection>,
|
acc.extend_from_slice(bytes);
|
||||||
{
|
async move { acc }
|
||||||
filter.with(
|
},
|
||||||
warp::body::map_request_body(parse_digest_header(), move |body: hyper::body::Body, parts: (Vec<DigestPart>,)| {
|
))
|
||||||
|
.and_then(move |parts: Vec<DigestPart>, bytes_mut: BytesMut| {
|
||||||
let mut verifier = verifier.clone();
|
let mut verifier = verifier.clone();
|
||||||
async move {
|
async move {
|
||||||
let parts = parts.clone();
|
if verifier.verify(&parts, &bytes_mut.freeze()) {
|
||||||
let buf = hyper::body::aggregate(body).await.ok()?;
|
Ok(())
|
||||||
let bytes: Vec<u8> = buf.bytes().to_owned();
|
|
||||||
|
|
||||||
if verifier.verify(&parts.0, &bytes) {
|
|
||||||
Some(bytes.into())
|
|
||||||
} else {
|
} else {
|
||||||
None
|
Err(warp::reject::custom(VerifyError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_digest_header() -> impl Filter<Extract = (Vec<DigestPart>,), Error = Rejection> + Clone {
|
fn parse_digest_header() -> impl Filter<Extract = (Vec<DigestPart>,), Error = Rejection> + Clone {
|
||||||
|
|
Loading…
Reference in a new issue