Skip to main content

sign_standard

Function sign_standard 

Source
pub fn sign_standard(
    secret: &str,
    id: &str,
    timestamp: i64,
    body: &[u8],
) -> Result<String>
Expand description

The webhook-signature header value (v1,<base64>) of a Standard Webhooks delivery of body with this id and timestamp (Unix seconds): what verify_standard checks. For an app that sends Standard Webhooks, and for tests of one that receives them.

§Errors

Error::Internal when the secret is not whsec_ followed by base64.

§Examples

use axum::http::HeaderMap;
use ocre::webhooks::{sign_standard, verify_standard};

let secret = "whsec_c2VjcmV0";
let mut headers = HeaderMap::new();
headers.insert("webhook-id", "msg_1".parse().unwrap());
headers.insert("webhook-timestamp", "1700000000".parse().unwrap());
let signature = sign_standard(secret, "msg_1", 1_700_000_000, b"{}").unwrap();
headers.insert("webhook-signature", signature.parse().unwrap());
assert!(verify_standard(secret, &headers, b"{}", 300, 1_700_000_000).is_ok());