Expand description
Webhook signature verification (HMAC-SHA256). See webhook::verify_signature.
Webhook signature verification — HMAC-based, constant-time.
Most webhook providers (Stripe, GitHub, Slack, etc.) sign the request body with HMAC and put the signature in a header. This module verifies those signatures so you don’t run handler code on forged payloads.
§Quick start
ⓘ
use rustango::webhook::{verify_signature, SignatureFormat};
async fn handle_webhook(headers: HeaderMap, body: Bytes) -> impl IntoResponse {
let signature = headers.get("X-Hub-Signature-256")
.and_then(|v| v.to_str().ok())
.unwrap_or("");
if !verify_signature(SignatureFormat::HexSha256, secret, &body, signature) {
return StatusCode::UNAUTHORIZED;
}
// ... process the verified payload
StatusCode::OK
}Enums§
- Signature
Format - Signature encoding format — what the webhook provider sends.
Functions§
- sign
- Sign
bodywithsecret, producing a signature in the given format. Useful for generating webhooks (or in tests). - verify_
signature - Verify
signatureagainstbodyusing HMAC-SHA256 withsecret.