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>. It is assumed that the T extractor will consume the payload.
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.
Example
use actix_web::{Responder, web};
use actix_web_lab::extract::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 Future = LocalBoxFuture<'static, Result<Self, Self::Error>>
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>
Future that resolves to a Self.
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>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
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