From 85932442fe0d702ef58966661e14121a34729273 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 25 Apr 2020 20:41:21 -0500 Subject: [PATCH] Clippy --- .../src/digest/middleware.rs | 18 ++++++++---------- .../src/digest/sha2.rs | 4 ++-- .../src/digest/sha3.rs | 4 ++-- http-signature-normalization-actix/src/lib.rs | 4 ++-- .../src/middleware.rs | 19 ++++++++----------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/http-signature-normalization-actix/src/digest/middleware.rs b/http-signature-normalization-actix/src/digest/middleware.rs index b081445..10f511d 100644 --- a/http-signature-normalization-actix/src/digest/middleware.rs +++ b/http-signature-normalization-actix/src/digest/middleware.rs @@ -74,11 +74,7 @@ impl FromRequest for DigestVerified { type Config = (); fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { - let res = req - .extensions() - .get::() - .map(|s| *s) - .ok_or(VerifyError); + let res = req.extensions().get::().copied().ok_or(VerifyError); if res.is_err() { debug!("Failed to fetch DigestVerified from request"); @@ -108,6 +104,8 @@ where } } +type FutResult = dyn Future>; + impl Service for VerifyMiddleware where T: DigestVerify + Clone + 'static, @@ -119,7 +117,7 @@ where type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; - type Future = Pin>>>; + type Future = Pin>>; fn poll_ready(&mut self, cx: &mut Context) -> Poll> { self.0.poll_ready(cx) @@ -140,7 +138,7 @@ where let f1 = verify_payload(vec, self.2.clone(), payload, tx); let payload: Pin> + 'static>> = - Box::pin(rx.map(|bytes| Ok(bytes))); + Box::pin(rx.map(Ok)); req.set_payload(payload.into()); req.extensions_mut().insert(DigestVerified); @@ -190,11 +188,11 @@ where } fn parse_digest(h: &HeaderValue) -> Option> { - let h = h.to_str().ok()?.split(";").next()?; + let h = h.to_str().ok()?.split(';').next()?; let v: Vec<_> = h - .split(",") + .split(',') .filter_map(|p| { - let mut iter = p.splitn(2, "="); + let mut iter = p.splitn(2, '='); iter.next() .and_then(|alg| iter.next().map(|value| (alg, value))) }) diff --git a/http-signature-normalization-actix/src/digest/sha2.rs b/http-signature-normalization-actix/src/digest/sha2.rs index 1589752..3938777 100644 --- a/http-signature-normalization-actix/src/digest/sha2.rs +++ b/http-signature-normalization-actix/src/digest/sha2.rs @@ -25,9 +25,9 @@ fn verify(digest: &mut impl sha2::Digest, name: &str, parts: &[DigestPart], byte parts.iter().fold(String::new(), |mut acc, item| { if acc.is_empty() { } else { - acc.extend(", ".chars()); + acc.push_str(", "); } - acc.extend(item.algorithm.chars()); + acc.push_str(&item.algorithm); acc }) ); diff --git a/http-signature-normalization-actix/src/digest/sha3.rs b/http-signature-normalization-actix/src/digest/sha3.rs index 204de40..7322c3a 100644 --- a/http-signature-normalization-actix/src/digest/sha3.rs +++ b/http-signature-normalization-actix/src/digest/sha3.rs @@ -28,9 +28,9 @@ fn verify(digest: &mut impl sha2::Digest, name: &str, parts: &[DigestPart], byte parts.iter().fold(String::new(), |mut acc, item| { if acc.is_empty() { } else { - acc.extend(", ".chars()); + acc.push_str(", "); } - acc.extend(item.algorithm.chars()); + acc.push_str(&item.algorithm); acc }) ); diff --git a/http-signature-normalization-actix/src/lib.rs b/http-signature-normalization-actix/src/lib.rs index 400c35d..7471258 100644 --- a/http-signature-normalization-actix/src/lib.rs +++ b/http-signature-normalization-actix/src/lib.rs @@ -382,7 +382,7 @@ impl Config { let path_and_query = path_and_query .map(|p| p.to_string()) - .unwrap_or(String::from("/")); + .unwrap_or_else(|| "/".to_string()); let unsigned = self .config @@ -405,7 +405,7 @@ impl Config { let path_and_query = path_and_query .map(|p| p.to_string()) - .unwrap_or(String::from("/")); + .unwrap_or_else(|| "/".to_string()); let unverified = self .config diff --git a/http-signature-normalization-actix/src/middleware.rs b/http-signature-normalization-actix/src/middleware.rs index efba818..4ee709c 100644 --- a/http-signature-normalization-actix/src/middleware.rs +++ b/http-signature-normalization-actix/src/middleware.rs @@ -130,7 +130,7 @@ where } }; - let algorithm = unverified.algorithm().map(|a| a.clone()); + let algorithm = unverified.algorithm().cloned(); let key_id = unverified.key_id().to_owned(); let f1 = unverified.verify(|signature, signing_string| { @@ -158,12 +158,12 @@ where } impl HeaderKind { - pub fn is_authorization(&self) -> bool { - HeaderKind::Authorization == *self + pub fn is_authorization(self) -> bool { + HeaderKind::Authorization == self } - pub fn is_signature(&self) -> bool { - HeaderKind::Signature == *self + pub fn is_signature(self) -> bool { + HeaderKind::Signature == self } } @@ -173,11 +173,7 @@ impl FromRequest for SignatureVerified { type Config = (); fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { - let res = req - .extensions() - .get::() - .map(|s| s.clone()) - .ok_or(VerifyError); + let res = req.extensions().get::().cloned().ok_or(VerifyError); if res.is_err() { debug!("Failed to fetch SignatureVerified from request"); @@ -213,6 +209,7 @@ where } } +type FutResult = dyn Future>; impl Service for VerifyMiddleware where T: SignatureVerify + Clone + 'static, @@ -224,7 +221,7 @@ where type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; - type Future = Pin>>>; + type Future = Pin>>; fn poll_ready(&mut self, cx: &mut Context) -> Poll> { self.0.poll_ready(cx)