Skip to main content

Module vapid

Module vapid 

Source
Expand description

Utilities for creating VAPID signatures according to RFC8292.

WebPushBuilder::with_vapid can be used to automatically add VAPID signature headers to your responses. Use VapidSignature when you need to manually create and store VAPID signatures.

§Example

use base64ct::{Base64UrlUnpadded, Encoding as _};
use web_push_native::{jwt_simple::algorithms::ES256KeyPair, vapid::VapidSignature};

const VAPID_PRIVATE: &str = "RS0WdYWWo1HajXg3NZR1olzCf31i-ZBGDkFyCs7j1jw";

let key_pair = ES256KeyPair::from_bytes(&Base64UrlUnpadded::decode_vec(VAPID_PRIVATE)?)?;
let signature = VapidSignature::sign(
    &http::Uri::from_static("https://example.com/"),
    std::time::Duration::new(60, 0),
    "mailto:john.doe@example.com",
    &key_pair,
)?;

assert!(signature.to_string().starts_with("vapid"));

Structs§

VapidAuthorization
Marker for adding VAPID authorization to a WebPushBuilder
VapidSignature
VAPID (Voluntary Application Server Identification) signature