pub struct HttpVerifier { /* private fields */ }Expand description
HTTP request signature verifier.
§Example
use herolib_crypt::httpsig::HttpVerifier;
use herolib_crypt::keys::Ed25519Keypair;
let keypair = Ed25519Keypair::generate()?;
let public_key = keypair.public_key();
let verifier = HttpVerifier::new()
.with_key(public_key);
// Verify would be called with actual request dataImplementations§
Source§impl HttpVerifier
impl HttpVerifier
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new verifier.
You must configure either a default key with with_key() or
a key getter function with with_key_getter().
Sourcepub fn with_key(self, public_key: Ed25519PublicKey) -> Self
pub fn with_key(self, public_key: Ed25519PublicKey) -> Self
Set a default public key for single-key scenarios.
Sourcepub fn with_key_getter(
self,
getter: Box<dyn Fn(&str) -> Result<Ed25519PublicKey, HttpSigError> + Send + Sync>,
) -> Self
pub fn with_key_getter( self, getter: Box<dyn Fn(&str) -> Result<Ed25519PublicKey, HttpSigError> + Send + Sync>, ) -> Self
Set a dynamic key lookup function.
The function receives the key ID from the signature and should return the corresponding public key.
Note: This method is not available when the rhai feature is enabled,
as function pointers are not cloneable. Use with_key() instead.
§Example
let verifier = HttpVerifier::new()
.with_key_getter(Box::new(|key_id| {
// Look up key from database, cache, etc.
// For this example, just return an error
Err(herolib_crypt::httpsig::HttpSigError::KeyNotFound(key_id.to_string()))
}));Sourcepub fn with_tolerance(self, seconds: u64) -> Self
pub fn with_tolerance(self, seconds: u64) -> Self
Set the timestamp tolerance in seconds (default: 60).
Signatures with timestamps outside the window of
now - tolerance to now + tolerance will be rejected.
Sourcepub fn with_required_components(self, components: Vec<String>) -> Self
pub fn with_required_components(self, components: Vec<String>) -> Self
Require additional signed components beyond the defaults.
Sourcepub fn verify_request<B>(
&self,
request: &Request<B>,
body: &[u8],
) -> Result<VerificationResult, HttpSigError>
pub fn verify_request<B>( &self, request: &Request<B>, body: &[u8], ) -> Result<VerificationResult, HttpSigError>
Verify an HTTP request.
This method works with any HTTP library that uses http::Request.
§Arguments
request- Reference to the HTTP requestbody- Request body bytes
Sourcepub fn verify_response<B>(
&self,
response: &Response<B>,
body: &[u8],
) -> Result<VerificationResult, HttpSigError>
pub fn verify_response<B>( &self, response: &Response<B>, body: &[u8], ) -> Result<VerificationResult, HttpSigError>
Verify an HTTP response.
This method works with any HTTP library that uses http::Response.
§Arguments
response- Reference to the HTTP responsebody- Response body bytes