use pgp_native::{SignedPublicKey, StandaloneSignature};
use tokio::task;
use crate::{Error, Result};
pub async fn verify(
pkey: SignedPublicKey,
signature: StandaloneSignature,
signed_bytes: Vec<u8>,
) -> Result<()> {
task::spawn_blocking(move || {
signature
.verify(&pkey, &signed_bytes)
.map_err(Error::VerifySignatureError)?;
Ok(())
})
.await?
}
#[cfg(test)]
mod tests {
use crate::{gen_key_pair, read_sig_from_bytes, sign, verify};
#[tokio::test]
async fn sign_then_verify() {
let (skey, pkey) = gen_key_pair("test@localhost", "").await.unwrap();
let msg = b"signed message".to_vec();
let raw_sig = sign(skey, "", msg.clone()).await.unwrap();
let sig = read_sig_from_bytes(raw_sig).await.unwrap();
verify(pkey, sig, msg).await.unwrap();
}
}