pub trait VerifyDigest:
    Default
    + Send
    + 'static {
    const REQUIRED: bool = true;

    // Required methods
    fn update(&mut self, bytes: &[u8]);
    fn verify(&mut self, parts: &[DigestPart]) -> bool;
}
Expand description

Verifies the Digest header from the request

For endpoints that do not accept request bodies, () can be used as the verifier

§Example:

use http_signature_normalization_actix_extractor::{DigestPart, VerifyDigest};
use openssl::sha::Sha256;

struct OpenSSLSha256(Option<Sha256>);

impl Default for OpenSSLSha256 {
    fn default() -> Self {
        Self::new()
    }
}

impl OpenSSLSha256 {
    fn new() -> Self {
        Self(Some(Sha256::new()))
    }
}

impl VerifyDigest for OpenSSLSha256 {
    fn update(&mut self, bytes: &[u8]) {
        self.0.as_mut().expect("Update called after verify").update(bytes);
    }

    fn verify(&mut self, parts: &[DigestPart]) -> bool {
        if let Some(decoded) = parts.iter().find_map(|p| {
            if p.algorithm.to_lowercase() == "sha-256" {
                openssl::base64::decode_block(&p.digest).ok()
            } else {
                None
            }
        }) {
            return openssl::memcmp::eq(
                &self.0.take().expect("verify called more than once").finish(),
                &decoded,
            );
        }

        false
    }
}

Provided Associated Constants§

Source

const REQUIRED: bool = true

Whether to run this verifier

Required Methods§

Source

fn update(&mut self, bytes: &[u8])

Update the verifier with th eprovided bytes

Source

fn verify(&mut self, parts: &[DigestPart]) -> bool

Given a slice of parts, verify that the one matching the current verifier is valid

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl VerifyDigest for ()

Source§

const REQUIRED: bool = false

Source§

fn update(&mut self, _: &[u8])

Source§

fn verify(&mut self, _: &[DigestPart]) -> bool

Source§

impl VerifyDigest for Sha224

Source§

fn update(&mut self, part: &[u8])

Source§

fn verify(&mut self, parts: &[DigestPart]) -> bool

Source§

impl VerifyDigest for Sha256

Source§

fn update(&mut self, part: &[u8])

Source§

fn verify(&mut self, parts: &[DigestPart]) -> bool

Source§

impl VerifyDigest for Sha384

Source§

fn update(&mut self, part: &[u8])

Source§

fn verify(&mut self, parts: &[DigestPart]) -> bool

Source§

impl VerifyDigest for Sha512

Source§

fn update(&mut self, part: &[u8])

Source§

fn verify(&mut self, parts: &[DigestPart]) -> bool

Implementors§