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.

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

Returns hash slice.

Returns hash output size.

Verifies HMAC hash against provides tag using constant-time equality.

Returns tuple containing body type, raw body bytes, and owned hash.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned.

Future that resolves to a Self.

Create a Self from request parts asynchronously.

Create a Self from request head asynchronously. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more