summaryrefslogtreecommitdiff
path: root/src/vapid
diff options
context:
space:
mode:
Diffstat (limited to 'src/vapid')
-rw-r--r--src/vapid/app.rs2
-rw-r--r--src/vapid/repo.rs19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/vapid/app.rs b/src/vapid/app.rs
index ebd2446..9949aa5 100644
--- a/src/vapid/app.rs
+++ b/src/vapid/app.rs
@@ -101,6 +101,7 @@ pub enum Error {
Database(#[from] sqlx::Error),
Ecdsa(#[from] p256::ecdsa::Error),
Pkcs8(#[from] p256::pkcs8::Error),
+ WebPush(#[from] web_push::WebPushError),
}
impl From<repo::Error> for Error {
@@ -110,6 +111,7 @@ impl From<repo::Error> for Error {
Error::Database(error) => error.into(),
Error::Ecdsa(error) => error.into(),
Error::Pkcs8(error) => error.into(),
+ Error::WebPush(error) => error.into(),
}
}
}
diff --git a/src/vapid/repo.rs b/src/vapid/repo.rs
index 98b3bae..9db61e1 100644
--- a/src/vapid/repo.rs
+++ b/src/vapid/repo.rs
@@ -1,8 +1,11 @@
+use std::io::Cursor;
+
use p256::{
ecdsa::SigningKey,
pkcs8::{DecodePrivateKey as _, EncodePrivateKey as _, LineEnding},
};
use sqlx::{Sqlite, SqliteConnection, Transaction};
+use web_push::{PartialVapidSignatureBuilder, VapidSignatureBuilder};
use super::{
History,
@@ -118,6 +121,21 @@ impl Vapid<'_> {
Ok(key)
}
+
+ pub async fn signer(&mut self) -> Result<PartialVapidSignatureBuilder, Error> {
+ let key = sqlx::query_scalar!(
+ r#"
+ select key
+ from vapid_signing_key
+ "#
+ )
+ .fetch_one(&mut *self.0)
+ .await?;
+ let key = Cursor::new(&key);
+ let signer = VapidSignatureBuilder::from_pem_no_sub(key)?;
+
+ Ok(signer)
+ }
}
#[derive(Debug, thiserror::Error)]
@@ -125,6 +143,7 @@ impl Vapid<'_> {
pub enum Error {
Ecdsa(#[from] p256::ecdsa::Error),
Pkcs8(#[from] p256::pkcs8::Error),
+ WebPush(#[from] web_push::WebPushError),
Database(#[from] sqlx::Error),
}