Struct web_push::VapidSignatureBuilder [] [src]

pub struct VapidSignatureBuilder<'a> { /* fields omitted */ }

A VAPID signature builder for generating an optional signature to the request. With a given signature, one can pass the registration to Google's FCM service. And prevent unauthorized notifications to be sent to the client.

To communicate with the site, one needs to generate a private key to keep in the server and derive a public key from the generated private key to the client.

Private key generation:

openssl ecparam -name prime256v1 -genkey -noout -out private.pem

To derive a public key out of generated private key:

openssl ec -in private.pem -pubout -out vapid_public.pem

To get the byte form of the public key for the JavaScript client:

openssl ec -in private.pem -text -noout -conv_form uncompressed

To create a VAPID signature:

let subscription_info = SubscriptionInfo {
    keys: SubscriptionKeys {
        p256dh: String::from("something"),
        auth: String::from("secret"),
    },
    endpoint: String::from("https://mozilla.rules/something"),
};

let file = File::open("private.pem").unwrap();

let mut sig_builder = VapidSignatureBuilder::from_pem(file, &subscription_info).unwrap();
sig_builder.add_claim("sub", "mailto:test@example.com");
sig_builder.add_claim("foo", "bar");
sig_builder.add_claim("omg", 123);

let signature = sig_builder.build().unwrap();

Methods

impl<'a> VapidSignatureBuilder<'a>
[src]

[src]

Creates a new builder from a PEM formatted private key.

[src]

Creates a new builder from a DER formatted private key.

[src]

Add a claim to the signature. Claims aud and exp are automatically added to the signature. Add them manually to override the default values.

The function accepts any value that can be converted into a type JSON supports.

[src]

Builds a signature to be used in WebPushMessageBuilder.

Trait Implementations

Auto Trait Implementations

impl<'a> Send for VapidSignatureBuilder<'a>

impl<'a> Sync for VapidSignatureBuilder<'a>