summaryrefslogtreecommitdiff
path: root/src/push/vapid.rs
blob: b13a00c0b607cab6814c1a4a80da6677e59c2de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::fmt;

use web_push::{PartialVapidSignatureBuilder, VapidSignatureBuilder, WebPushError};

#[derive(Clone)]
pub struct PrivateKey(String);

impl PrivateKey {
    pub fn as_signature_builder(&self) -> Result<PartialVapidSignatureBuilder, WebPushError> {
        let Self(key) = self;
        VapidSignatureBuilder::from_base64_no_sub(key)
    }
}

impl fmt::Debug for PrivateKey {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_tuple("PrivateKey").field(&"********").finish()
    }
}

impl<S> From<S> for PrivateKey
where
    S: Into<String>,
{
    fn from(value: S) -> Self {
        Self(value.into())
    }
}