pub struct WebhookVerifier { /* private fields */ }Expand description
The signature core every scheme shares: compute what a matching delivery must carry — an HMAC (SHA-256 or SHA-1) over the scheme’s signed payload, or, for a token scheme, the secret itself — compare it against every candidate in constant time with no early exit, and hold the delivery to its timestamp.
Implementations§
Source§impl WebhookVerifier
impl WebhookVerifier
Sourcepub fn new(scheme: impl SignatureScheme + 'static) -> Self
pub fn new(scheme: impl SignatureScheme + 'static) -> Self
A verifier with the default tolerance (DEFAULT_TOLERANCE_SECS).
use cratefield_core::{Svix, WebhookVerifier};
use http::HeaderMap;
let verifier = WebhookVerifier::new(Svix);
// `raw` is the body exactly as it arrived, before any parsing; the
// empty secret here means the delivery is refused, never guessed at.
assert!(!verifier.verify("", &HeaderMap::new(), b"{}", 0));Sourcepub const fn tolerance_secs(self, secs: i64) -> Self
pub const fn tolerance_secs(self, secs: i64) -> Self
Overrides the replay tolerance, in seconds, in both directions.
Sourcepub fn verify(
&self,
secret: &str,
headers: &HeaderMap,
body: &[u8],
now_unix: i64,
) -> bool
pub fn verify( &self, secret: &str, headers: &HeaderMap, body: &[u8], now_unix: i64, ) -> bool
Whether body really was signed for this delivery with secret.
Fails closed on every unreadable input; a timestamp in the future
counts against the tolerance exactly as a stale one does.
§Panics
Only if the HMAC refused the derived key — which it cannot: HMAC accepts keys of any length.
Trait Implementations§
Source§impl Clone for WebhookVerifier
impl Clone for WebhookVerifier
Auto Trait Implementations§
impl !RefUnwindSafe for WebhookVerifier
impl !UnwindSafe for WebhookVerifier
impl Freeze for WebhookVerifier
impl Send for WebhookVerifier
impl Sync for WebhookVerifier
impl Unpin for WebhookVerifier
impl UnsafeUnpin for WebhookVerifier
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
Mutably borrows from an owned value. Read more