Simplify passing verifier

This commit is contained in:
asonix 2020-01-17 17:09:05 -06:00
parent 51bd0ad1ef
commit 1d37ebb812

View file

@ -35,16 +35,13 @@ pub enum ParseDigestError {
#[error("Could not parse request body")]
pub struct ParseBodyError;
pub fn verify_digest_bytes<D>(
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
) -> impl Filter<Extract = (Bytes,), Error = Rejection> + Clone
where
D: DigestVerify + Send,
{
verifier
.and(parse_digest_header())
pub fn verify_digest_bytes(
verifier: impl DigestVerify + Clone + Send,
) -> impl Filter<Extract = (Bytes,), Error = Rejection> + Clone {
parse_digest_header()
.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 {
if verifier.verify(&parts, &bytes) {
Ok(bytes)
@ -55,11 +52,10 @@ where
})
}
pub fn verify_digest_json<D, T>(
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
pub fn verify_digest_json<T>(
verifier: impl DigestVerify + Clone + Send
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
where
D: DigestVerify + Send,
T: serde::de::DeserializeOwned,
{
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {
@ -69,11 +65,10 @@ where
})
}
pub fn verify_digest_form<D, T>(
verifier: impl Filter<Extract = (D,), Error = Rejection> + Clone,
pub fn verify_digest_form<T>(
verifier: impl DigestVerify + Clone + Send,
) -> impl Filter<Extract = (T,), Error = Rejection> + Clone
where
D: DigestVerify + Send,
T: serde::de::DeserializeOwned,
{
verify_digest_bytes(verifier).and_then(|bytes: Bytes| {