pub trait WebhookHmac: Webhook {
type MAC: Mac + KeyInit + Send;
// Required methods
fn secret_key(&self) -> &[u8] ⓘ;
fn expected_signatures(
&self,
req: &Request<'_>,
) -> Outcome<'_, Vec<Vec<u8>>, WebhookError>;
// Provided methods
fn body_prefix(
&self,
req: &Request<'_>,
time_bounds: (u32, u32),
) -> Outcome<'_, Option<Vec<u8>>, WebhookError> { ... }
fn body_suffix(
&self,
req: &Request<'_>,
time_bounds: (u32, u32),
) -> Outcome<'_, Option<Vec<u8>>, WebhookError> { ... }
fn validate_with_hmac(
&self,
req: &Request<'_>,
body: impl AsyncRead + Unpin + Send + Sync,
time_bounds: (u32, u32),
) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
where Self: Sync,
Self::MAC: Sync { ... }
}
hmac
only.Expand description
Trait for webhooks that use HMAC signature validation.
Required Associated Types§
Required Methods§
Sourcefn secret_key(&self) -> &[u8] ⓘ
fn secret_key(&self) -> &[u8] ⓘ
Get the secret key used to sign the webhook
Sourcefn expected_signatures(
&self,
req: &Request<'_>,
) -> Outcome<'_, Vec<Vec<u8>>, WebhookError>
fn expected_signatures( &self, req: &Request<'_>, ) -> Outcome<'_, Vec<Vec<u8>>, WebhookError>
Get the expected signature(s) from the request. To obtain required headers,
you can use the self.get_header()
utility.
Provided Methods§
Sourcefn body_prefix(
&self,
req: &Request<'_>,
time_bounds: (u32, u32),
) -> Outcome<'_, Option<Vec<u8>>, WebhookError>
fn body_prefix( &self, req: &Request<'_>, time_bounds: (u32, u32), ) -> Outcome<'_, Option<Vec<u8>>, WebhookError>
Get an optional prefix to attach to the raw body when calculating the signature. Timestamps should be validated against the given bounds.
Sourcefn body_suffix(
&self,
req: &Request<'_>,
time_bounds: (u32, u32),
) -> Outcome<'_, Option<Vec<u8>>, WebhookError>
fn body_suffix( &self, req: &Request<'_>, time_bounds: (u32, u32), ) -> Outcome<'_, Option<Vec<u8>>, WebhookError>
Get an optional suffix to attach to the raw body when calculating the signature. Timestamps should be validated against the given bounds.
Sourcefn validate_with_hmac(
&self,
req: &Request<'_>,
body: impl AsyncRead + Unpin + Send + Sync,
time_bounds: (u32, u32),
) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
fn validate_with_hmac( &self, req: &Request<'_>, body: impl AsyncRead + Unpin + Send + Sync, time_bounds: (u32, u32), ) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
Read the request body and verify the HMAC signature. Calculates the HMAC directly from the raw streamed body (with a prefix if configured).
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.
Implementors§
Source§impl WebhookHmac for GitHubWebhook
Available on crate feature github
only.
impl WebhookHmac for GitHubWebhook
github
only.Source§impl WebhookHmac for ShopifyWebhook
Available on crate feature shopify
only.
impl WebhookHmac for ShopifyWebhook
shopify
only.Source§impl WebhookHmac for SlackWebhook
Available on crate feature slack
only.
impl WebhookHmac for SlackWebhook
slack
only.Source§impl WebhookHmac for StandardWebhook
Available on crate feature standard
only.
impl WebhookHmac for StandardWebhook
standard
only.Source§impl WebhookHmac for StripeWebhook
Available on crate feature stripe
only.
impl WebhookHmac for StripeWebhook
stripe
only.