Struct actix_hash::BodyHash
source · [−]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
sourceimpl<T, D: Digest> BodyHash<T, D>
impl<T, D: Digest> BodyHash<T, D>
sourcepub fn hash(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn hash(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Returns hash slice.
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
sourceimpl<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,
type Error = <T as FromRequest>::Error
type Error = <T as FromRequest>::Error
The associated error which can be returned.
sourcefn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Create a Self from request parts asynchronously.
sourcefn extract(req: &HttpRequest) -> Self::Future
fn extract(req: &HttpRequest) -> Self::Future
Create a Self from request head asynchronously. Read more
Auto Trait Implementations
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> where
T: Unpin,
<<D as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin,
impl<T, D> UnwindSafe for BodyHash<T, D> where
T: UnwindSafe,
<<D as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more