[−][src]Struct web_push::VapidSignatureBuilder
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
... or a base64 encoded string, which the client should convert into byte form before using:
openssl ec -in private.pem -pubout -outform DER|tail -c 65|base64|tr '/+' '_-'|tr -d '\n'
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]
pub fn from_pem<R: Read>(
pk_pem: R,
subscription_info: &'a SubscriptionInfo
) -> Result<VapidSignatureBuilder<'a>, WebPushError>
[src]
pk_pem: R,
subscription_info: &'a SubscriptionInfo
) -> Result<VapidSignatureBuilder<'a>, WebPushError>
Creates a new builder from a PEM formatted private key.
pub fn from_der<R: Read>(
pk_der: R,
subscription_info: &'a SubscriptionInfo
) -> Result<VapidSignatureBuilder<'a>, WebPushError>
[src]
pk_der: R,
subscription_info: &'a SubscriptionInfo
) -> Result<VapidSignatureBuilder<'a>, WebPushError>
Creates a new builder from a DER formatted private key.
pub fn add_claim<V>(&mut self, key: &'a str, val: V) where
V: Into<Value>,
[src]
V: Into<Value>,
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.
pub fn build(self) -> Result<VapidSignature, WebPushError>
[src]
Builds a signature to be used in WebPushMessageBuilder.
Auto Trait Implementations
impl<'a> RefUnwindSafe for VapidSignatureBuilder<'a>
impl<'a> Send for VapidSignatureBuilder<'a>
impl<'a> Sync for VapidSignatureBuilder<'a>
impl<'a> Unpin for VapidSignatureBuilder<'a>
impl<'a> UnwindSafe for VapidSignatureBuilder<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,