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§
Required Methods§
Sourcefn verify(&mut self, parts: &[DigestPart]) -> bool
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.