pub struct BodyHash<T, D: Digest> { /* private fields */ }Expand description
Wraps an extractor and calculates a body checksum hash alongside.
If your extractor would usually be T and you want to create a hash of type D then you need
to use BodyHash<T, D>. E.g., BodyHash<String, Sha256>.
Any hasher that implements Digest can be used. Type aliases for common hashing algorithms
are available at the crate root.
§Errors
This extractor produces no errors of its own and all errors from the underlying extractor are propagated correctly; for example, if the payload limits are exceeded.
§When Used On The Wrong Extractor
Use on a non-body extractor is tolerated unless it is used after a different extractor that takes the payload. In this case, the resulting hash will be as if an empty input was given to the hasher.
§Example
use actix_web::{Responder, web};
use actix_hash::BodyHash;
use sha2::Sha256;
async fn hash_payload(form: BodyHash<web::Json<T>, Sha256>) -> impl Responder {
if !form.verify_slice(b"correct-signature") {
// return unauthorized error
}
"Ok"
}Implementations§
Source§impl<T, D: Digest> BodyHash<T, D>
impl<T, D: Digest> BodyHash<T, D>
Sourcepub fn verify_slice(&self, tag: &[u8]) -> bool
pub fn verify_slice(&self, tag: &[u8]) -> bool
Verifies HMAC hash against provided tag using constant-time equality.
Sourcepub fn into_parts(self) -> BodyHashParts<T>
pub fn into_parts(self) -> BodyHashParts<T>
Returns body type parts, including extracted body type, raw body bytes, and hash bytes.
Trait Implementations§
Source§impl<T, D> FromRequest for BodyHash<T, D>where
T: FromRequest + 'static,
D: Digest + 'static,
impl<T, D> FromRequest for BodyHash<T, D>where
T: FromRequest + 'static,
D: Digest + 'static,
Source§type Error = <T as FromRequest>::Error
type Error = <T as FromRequest>::Error
Source§fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Self from request parts asynchronously.Auto Trait Implementations§
impl<T, D> Freeze for BodyHash<T, D>
impl<T, D> RefUnwindSafe for BodyHash<T, D>where
T: RefUnwindSafe,
<<D as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
impl<T, D> Send for BodyHash<T, D>where
T: Send,
impl<T, D> Sync for BodyHash<T, D>where
T: Sync,
impl<T, D> Unpin for BodyHash<T, D>
impl<T, D> UnwindSafe for BodyHash<T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more