diff --git a/http-signature-normalization-actix/Cargo.toml b/http-signature-normalization-actix/Cargo.toml index f226432..280355f 100644 --- a/http-signature-normalization-actix/Cargo.toml +++ b/http-signature-normalization-actix/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "http-signature-normalization-actix" description = "An HTTP Signatures library that leaves the signing to you" -version = "0.4.1" +version = "0.5.0-beta.1" authors = ["asonix "] license-file = "LICENSE" readme = "README.md" @@ -25,8 +25,8 @@ name = "client" required-features = ["sha-2"] [dependencies] -actix-web = { version = "3.0.1", default-features = false } -awc = { version = "2.0.0", default-features = false } +actix-web = { version = "4.0.0-beta.1", default-features = false } +awc = { version = "3.0.0-beta.1", default-features = false } base64 = { version = "0.12", optional = true } bytes = "0.5.4" chrono = "0.4.6" @@ -38,5 +38,5 @@ sha3 = { version = "0.9", optional = true } thiserror = "1.0" [dev-dependencies] -actix-rt = "1.1.1" +actix-rt = "=2.0.0-beta.1" pretty_env_logger = "0.4" diff --git a/http-signature-normalization-actix/README.md b/http-signature-normalization-actix/README.md index 73b1efc..e581ac0 100644 --- a/http-signature-normalization-actix/README.md +++ b/http-signature-normalization-actix/README.md @@ -13,10 +13,10 @@ This crate provides extensions the ClientRequest type from Actix Web, and provid #### First, add this crate to your dependencies ```toml -actix-rt = "1.1.1" -actix-web = "3.0.2" +actix-rt = "=2.0.0-beta.1" +actix-web = "4.0.0-beta.1" thiserror = "0.1" -http-signature-normalization-actix = { version = "0.4.1", default-features = false, features = ["sha-2"] } +http-signature-normalization-actix = { version = "0.5.0-beta.1", default-features = false, features = ["sha-2"] } sha2 = "0.9" ``` diff --git a/http-signature-normalization-actix/src/digest/middleware.rs b/http-signature-normalization-actix/src/digest/middleware.rs index 9a25e1d..c6269c9 100644 --- a/http-signature-normalization-actix/src/digest/middleware.rs +++ b/http-signature-normalization-actix/src/digest/middleware.rs @@ -7,15 +7,10 @@ use actix_web::{ http::{header::HeaderValue, StatusCode}, web, FromRequest, HttpMessage, HttpRequest, HttpResponse, ResponseError, }; -use bytes::Bytes; -use futures::{ - channel::mpsc, - future::{err, ok, ready, Ready}, - Stream, StreamExt, -}; +use futures::{channel::mpsc, Stream, StreamExt}; use log::{debug, warn}; use std::{ - future::Future, + future::{ready, Future, Ready}, pin::Pin, task::{Context, Poll}, }; @@ -85,15 +80,13 @@ impl FromRequest for DigestVerified { } } -impl Transform for VerifyDigest +impl Transform for VerifyDigest where T: DigestVerify + Clone + Send + 'static, - S: Service, Error = actix_web::Error> - + 'static, + S: Service, Error = actix_web::Error> + 'static, S::Error: 'static, B: MessageBody + 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; type Transform = VerifyMiddleware; @@ -101,21 +94,19 @@ where type Future = Ready>; fn new_transform(&self, service: S) -> Self::Future { - ok(VerifyMiddleware(service, self.0, self.1.clone())) + ready(Ok(VerifyMiddleware(service, self.0, self.1.clone()))) } } type FutResult = dyn Future>; -impl Service for VerifyMiddleware +impl Service for VerifyMiddleware where T: DigestVerify + Clone + Send + 'static, - S: Service, Error = actix_web::Error> - + 'static, + S: Service, Error = actix_web::Error> + 'static, S::Error: 'static, B: MessageBody + 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; type Future = Pin>>; @@ -130,7 +121,7 @@ where Some(vec) => vec, None => { warn!("Digest header could not be parsed"); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } }; let payload = req.take_payload(); @@ -138,7 +129,7 @@ where let (tx, rx) = mpsc::channel(1); let f1 = verify_payload(vec, self.2.clone(), payload, tx); - let payload: Pin> + 'static>> = + let payload: Pin> + 'static>> = Box::pin(rx.map(Ok)); req.set_payload(payload.into()); req.extensions_mut().insert(DigestVerified); @@ -150,7 +141,7 @@ where f2.await }) } else if self.1 { - Box::pin(err(VerifyError.into())) + Box::pin(ready(Err(VerifyError.into()))) } else { Box::pin(self.0.call(req)) } @@ -161,7 +152,7 @@ async fn verify_payload( vec: Vec, mut verify_digest: T, mut payload: Payload, - mut tx: mpsc::Sender, + mut tx: mpsc::Sender, ) -> Result<(), actix_web::Error> where T: DigestVerify + Clone + Send + 'static, diff --git a/http-signature-normalization-actix/src/middleware.rs b/http-signature-normalization-actix/src/middleware.rs index 4ee709c..d41ef48 100644 --- a/http-signature-normalization-actix/src/middleware.rs +++ b/http-signature-normalization-actix/src/middleware.rs @@ -6,10 +6,9 @@ use actix_web::{ http::StatusCode, Error, FromRequest, HttpMessage, HttpRequest, HttpResponse, ResponseError, }; -use futures::future::{err, ok, ready, Ready}; use log::{debug, warn}; use std::{ - future::Future, + future::{ready, Future, Ready}, pin::Pin, task::{Context, Poll}, }; @@ -93,7 +92,7 @@ impl VerifyMiddleware where T: SignatureVerify + 'static, T::Future: 'static, - S: Service, Error = Error> + 'static, + S: Service, Error = Error> + 'static, B: MessageBody + 'static, { fn handle( @@ -110,23 +109,23 @@ where Ok(unverified) => unverified, Err(PrepareVerifyError::Expired) => { warn!("Header is expired"); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } Err(PrepareVerifyError::Missing) => { debug!("Header is missing"); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } Err(PrepareVerifyError::ParseField(field)) => { debug!("Failed to parse field {}", field); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } Err(PrepareVerifyError::Header(e)) => { debug!("Failed to parse header {}", e); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } Err(PrepareVerifyError::Required(req)) => { debug!("Missing required headers, {:?}", req); - return Box::pin(err(VerifyError.into())); + return Box::pin(ready(Err(VerifyError.into()))); } }; @@ -183,15 +182,13 @@ impl FromRequest for SignatureVerified { } } -impl Transform for VerifySignature +impl Transform for VerifySignature where T: SignatureVerify + Clone + 'static, - S: Service, Error = actix_web::Error> - + 'static, + S: Service, Error = actix_web::Error> + 'static, S::Error: 'static, B: MessageBody + 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; type Transform = VerifyMiddleware; @@ -199,26 +196,24 @@ where type Future = Ready>; fn new_transform(&self, service: S) -> Self::Future { - ok(VerifyMiddleware( + ready(Ok(VerifyMiddleware( service, self.1.clone(), self.2, self.3, self.0.clone(), - )) + ))) } } type FutResult = dyn Future>; -impl Service for VerifyMiddleware +impl Service for VerifyMiddleware where T: SignatureVerify + Clone + 'static, - S: Service, Error = actix_web::Error> - + 'static, + S: Service, Error = actix_web::Error> + 'static, S::Error: 'static, B: MessageBody + 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; type Error = actix_web::Error; type Future = Pin>>; @@ -241,13 +236,13 @@ where } debug!("Authorization or Signature headers are missing"); - Box::pin(err(VerifyError.into())) + Box::pin(ready(Err(VerifyError.into()))) } else if self.3 { debug!("Headers are missing but Optional is true, continuing"); Box::pin(self.0.call(req)) } else { debug!("Authorization or Signature headers are missing"); - Box::pin(err(VerifyError.into())) + Box::pin(ready(Err(VerifyError.into()))) } } }