fix: verify_oneshot, maybe makes a difference?

This commit is contained in:
əlemi 2024-04-13 06:02:50 +02:00
parent 652af15771
commit 5d3c222774
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 6 additions and 3 deletions

View file

@ -17,6 +17,9 @@ pub enum UpubError {
#[error("fetch error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("invalid base64 string: {0}")]
Base64(#[from] base64::DecodeError),
}
impl UpubError {

View file

@ -89,9 +89,9 @@ where
fn verify_control_text(txt: &str, key: &str, control: &str) -> crate::Result<bool> {
let pubkey = PKey::public_key_from_pem(key.as_bytes())?;
let mut verifier = Verifier::new(MessageDigest::sha256(), &pubkey).unwrap();
verifier.update(txt.as_bytes())?;
Ok(verifier.verify(&base64::prelude::BASE64_URL_SAFE.decode(control).unwrap_or_default())?)
let mut verifier = Verifier::new(MessageDigest::sha256(), &pubkey)?;
let signature = base64::prelude::BASE64_URL_SAFE.decode(control)?;
Ok(verifier.verify_oneshot(&signature, txt.as_bytes())?)
}