pub struct WebhookVerifier { /* private fields */ }Expand description
Verifies Paymos webhook signatures over the exact raw request bytes.
Implementations§
Source§impl WebhookVerifier
impl WebhookVerifier
Sourcepub fn new(secret: impl Into<String>) -> Result<Self, WebhookError>
pub fn new(secret: impl Into<String>) -> Result<Self, WebhookError>
Creates a verifier with the default five-minute replay window.
§Errors
Returns WebhookError::Configuration when the secret is empty.
Sourcepub fn with_tolerance(
secret: impl Into<String>,
tolerance_seconds: u64,
) -> Result<Self, WebhookError>
pub fn with_tolerance( secret: impl Into<String>, tolerance_seconds: u64, ) -> Result<Self, WebhookError>
Creates a verifier with an explicit replay window in seconds.
§Errors
Returns WebhookError::Configuration when the secret is empty.
Sourcepub fn verify(
&self,
signature_header: &str,
raw_body: &[u8],
) -> Result<(), WebhookError>
pub fn verify( &self, signature_header: &str, raw_body: &[u8], ) -> Result<(), WebhookError>
Verifies a signature using the current system clock.
§Errors
Returns a WebhookError for a malformed header, stale timestamp,
signature mismatch, or invalid local clock.
Sourcepub fn verify_at(
&self,
signature_header: &str,
raw_body: &[u8],
now: i64,
) -> Result<(), WebhookError>
pub fn verify_at( &self, signature_header: &str, raw_body: &[u8], now: i64, ) -> Result<(), WebhookError>
Verifies a signature against an explicit Unix timestamp.
§Errors
Returns a WebhookError for a malformed header, stale timestamp, or
signature mismatch.
§Panics
The underlying HMAC constructor accepts keys of every length, so its error branch is unreachable for this algorithm.
Sourcepub fn construct_event<T: DeserializeOwned>(
&self,
signature_header: &str,
raw_body: &[u8],
) -> Result<WebhookEvent<T>, WebhookError>
pub fn construct_event<T: DeserializeOwned>( &self, signature_header: &str, raw_body: &[u8], ) -> Result<WebhookEvent<T>, WebhookError>
Verifies and deserializes a typed event using the current system clock.
§Errors
Returns a WebhookError when verification or event decoding fails.
Sourcepub fn construct_event_at<T: DeserializeOwned>(
&self,
signature_header: &str,
raw_body: &[u8],
now: i64,
) -> Result<WebhookEvent<T>, WebhookError>
pub fn construct_event_at<T: DeserializeOwned>( &self, signature_header: &str, raw_body: &[u8], now: i64, ) -> Result<WebhookEvent<T>, WebhookError>
Verifies and deserializes a typed event against an explicit Unix timestamp.
§Errors
Returns a WebhookError when verification or event decoding fails.