1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! # webhook-verify
//!
//! One function to verify inbound webhook signatures from major providers.
//!
//! Every backend that accepts webhooks ends up hand-rolling HMAC verification,
//! and getting subtle details wrong: re-serialized bodies instead of raw bytes,
//! non-constant-time comparison, missing replay protection, provider-specific
//! encoding quirks. This crate does it once, correctly, behind a single API.
//!
//! ## Example: verifying a GitHub delivery
//!
//! ```no_run
//! use webhook_verify::{verify, HeaderMap, Provider, Secret};
//!
//! let headers: Vec<(String, String)> = vec![(
//! "X-Hub-Signature-256".to_string(),
//! "sha256=757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17".to_string(),
//! )];
//! let raw_body = b"Hello, World!";
//!
//! let result = verify(
//! Provider::GitHub,
//! &headers,
//! raw_body,
//! &Secret::new("It's a Secret to Everybody"),
//! Default::default(),
//! );
//!
//! assert!(result.is_ok());
//! ```
//!
//! `raw_body` **must** be the exact bytes the provider sent — before any JSON
//! parsing or re-serialization. Verification against anything else will fail.
//!
//! ## Supported providers
//!
//! A single [`Provider`] enum drives signature verification for:
//!
//! | Provider | Scheme |
//! |---|---|
//! | Stripe | HMAC-SHA256 over `timestamp.body`, tolerance window |
//! | GitHub | HMAC-SHA256, `X-Hub-Signature-256` |
//! | Shopify | HMAC-SHA256, base64 |
//! | Slack | HMAC-SHA256 `v0=` scheme + timestamp |
//! | Square | HMAC-SHA256 over notification URL + body, base64 |
//! | Twilio | HMAC-SHA1 over URL + sorted form params |
//! | Discord | Ed25519 public-key signatures (no shared secret) |
//! | PayPal | RSASSA-PKCS1-v1_5 SHA-256, X.509 cert + webhook ID |
//! | SendGrid | ECDSA P-256 over `timestamp.body` |
//! | Linear | HMAC-SHA256, `linear-signature` |
//! | Zoom | HMAC-SHA256 `v0=` scheme + timestamp |
//! | Dropbox | HMAC-SHA256, `X-Dropbox-Signature` |
//! | Standard Webhooks | HMAC-SHA256 with replay + rotation lists (Svix, Clerk, Resend, ...) |
//! | Custom | User-supplied HMAC scheme via [`Provider::Custom`] |
//!
//! PayPal and SendGrid ship behind crate features; calling [`verify()`] with
//! them while the feature is off fails closed with [`VerifyError::UnsupportedProvider`].
//!
//! ## Crate features
//!
//! - `std` *(default)* — provides the wall clock used for replay protection
//! and the `std::error::Error` impl. Disable for `no_std + alloc` targets
//! (validated against `wasm32-unknown-unknown`); supply your own [`Clock`]
//! for timestamped providers.
//! - `sendgrid` — enables the SendGrid provider (ECDSA P-256).
//! - `paypal` — enables the PayPal provider (RSA, X.509, CRC-32).
//! - `http` — `HeaderMap` impl for `http::HeaderMap` (axum, tower, hyper).
//! - `tower` — generic `tower::Layer`/`Service` middleware (works with axum
//! routers too; `http` is implied).
//! - `actix` — actix-web 4 extractor + header bridge.
//!
//! See [`verify_any`] for cross-secret key rotation during a rotation window.
//!
//! ## Security properties
//!
//! - All signature comparisons are constant-time ([`subtle::ConstantTimeEq`]).
//! - Bodies are hashed exactly as received; never re-encoded.
//! - No secret material ever appears in errors, `Debug`, or `Display` output.
//! - Parsing paths return [`VerifyError`] instead of panicking on
//! attacker-controlled input.
//!
//! [`subtle::ConstantTimeEq`]: https://docs.rs/subtle/latest/subtle/trait.ConstantTimeEq.html
extern crate alloc;
pub use crateSystemClock;
pub use crate;
pub use crate;