mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-21 17:00:59 +00:00
Clippy
This commit is contained in:
parent
a0974299c5
commit
85932442fe
5 changed files with 22 additions and 27 deletions
|
@ -74,11 +74,7 @@ impl FromRequest for DigestVerified {
|
|||
type Config = ();
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
let res = req
|
||||
.extensions()
|
||||
.get::<Self>()
|
||||
.map(|s| *s)
|
||||
.ok_or(VerifyError);
|
||||
let res = req.extensions().get::<Self>().copied().ok_or(VerifyError);
|
||||
|
||||
if res.is_err() {
|
||||
debug!("Failed to fetch DigestVerified from request");
|
||||
|
@ -108,6 +104,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
|
||||
|
||||
impl<T, S, B> Service for VerifyMiddleware<T, S>
|
||||
where
|
||||
T: DigestVerify + Clone + 'static,
|
||||
|
@ -119,7 +117,7 @@ where
|
|||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = actix_web::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||
type Future = Pin<Box<FutResult<Self::Response, Self::Error>>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx)
|
||||
|
@ -140,7 +138,7 @@ where
|
|||
let f1 = verify_payload(vec, self.2.clone(), payload, tx);
|
||||
|
||||
let payload: Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>> + '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<Vec<DigestPart>> {
|
||||
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)))
|
||||
})
|
||||
|
|
|
@ -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
|
||||
})
|
||||
);
|
||||
|
|
|
@ -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
|
||||
})
|
||||
);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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::<Self>()
|
||||
.map(|s| s.clone())
|
||||
.ok_or(VerifyError);
|
||||
let res = req.extensions().get::<Self>().cloned().ok_or(VerifyError);
|
||||
|
||||
if res.is_err() {
|
||||
debug!("Failed to fetch SignatureVerified from request");
|
||||
|
@ -213,6 +209,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
|
||||
impl<T, S, B> Service for VerifyMiddleware<T, S>
|
||||
where
|
||||
T: SignatureVerify + Clone + 'static,
|
||||
|
@ -224,7 +221,7 @@ where
|
|||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = actix_web::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||
type Future = Pin<Box<FutResult<Self::Response, Self::Error>>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx)
|
||||
|
|
Loading…
Reference in a new issue