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")] #[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| {