pub struct WebhookSignature;Expand description
Helper for constructing signature configurations.
Use in webhook attributes like:
#[forge::webhook(
signature = WebhookSignature::hmac_sha256("X-Stripe-Signature", "STRIPE_SECRET"),
)]Implementations§
Source§impl WebhookSignature
impl WebhookSignature
Sourcepub const fn hmac_sha256(
header: &'static str,
secret_env: &'static str,
) -> SignatureConfig
pub const fn hmac_sha256( header: &'static str, secret_env: &'static str, ) -> SignatureConfig
Create HMAC-SHA256 signature config.
§Arguments
header- The HTTP header containing the signature (e.g., “X-Hub-Signature-256”)secret_env- Environment variable containing the secret
Sourcepub const fn hmac_sha1(
header: &'static str,
secret_env: &'static str,
) -> SignatureConfig
pub const fn hmac_sha1( header: &'static str, secret_env: &'static str, ) -> SignatureConfig
Create HMAC-SHA1 signature config.
§Arguments
header- The HTTP header containing the signaturesecret_env- Environment variable containing the secret
Sourcepub const fn hmac_sha512(
header: &'static str,
secret_env: &'static str,
) -> SignatureConfig
pub const fn hmac_sha512( header: &'static str, secret_env: &'static str, ) -> SignatureConfig
Create HMAC-SHA512 signature config.
§Arguments
header- The HTTP header containing the signaturesecret_env- Environment variable containing the secret
Sourcepub const fn standard_webhooks(secret_env: &'static str) -> SignatureConfig
pub const fn standard_webhooks(secret_env: &'static str) -> SignatureConfig
Create a Standard Webhooks signature config (https://www.standardwebhooks.com).
Used by Polar and other services that implement the Standard Webhooks spec.
The signature header is always webhook-signature; no need to specify it.
The secret may have a whsec_ or polar_whs_ prefix — both are stripped
and the remainder is base64-decoded to obtain the raw HMAC key.
§Arguments
secret_env- Environment variable containing the webhook secret
Sourcepub const fn stripe_webhooks(secret_env: &'static str) -> SignatureConfig
pub const fn stripe_webhooks(secret_env: &'static str) -> SignatureConfig
Create a Stripe webhook signature config.
Signs {timestamp}.{body} with HMAC-SHA256. The Stripe-Signature header
carries both the timestamp (t=) and one or more signatures (v1=). Requests
older than 5 minutes are rejected to guard against replay attacks.
§Arguments
secret_env- Environment variable containing the Stripe webhook signing secret
Sourcepub const fn shopify_webhooks(secret_env: &'static str) -> SignatureConfig
pub const fn shopify_webhooks(secret_env: &'static str) -> SignatureConfig
Create a Shopify webhook signature config.
HMAC-SHA256 over the raw body, base64-encoded. The signature arrives in the
X-Shopify-Hmac-Sha256 header.
§Arguments
secret_env- Environment variable containing the Shopify webhook secret
Sourcepub const fn ed25519(
header: &'static str,
public_key_env: &'static str,
) -> SignatureConfig
pub const fn ed25519( header: &'static str, public_key_env: &'static str, ) -> SignatureConfig
Create an Ed25519 asymmetric signature config.
The service signs the request body with an Ed25519 private key and publishes
the matching public key for you to verify with. The public_key_env variable
should hold the base64-encoded 32-byte Ed25519 public key.
§Arguments
header- The HTTP header containing the base64-encoded signaturepublic_key_env- Environment variable containing the base64-encoded public key
Auto Trait Implementations§
impl Freeze for WebhookSignature
impl RefUnwindSafe for WebhookSignature
impl Send for WebhookSignature
impl Sync for WebhookSignature
impl Unpin for WebhookSignature
impl UnsafeUnpin for WebhookSignature
impl UnwindSafe for WebhookSignature
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more