Digest: add verify methods
This commit is contained in:
parent
fba736e7f7
commit
36255bfbb4
|
@ -3,6 +3,8 @@ pub trait Digest {
|
|||
|
||||
fn build() -> Self;
|
||||
fn digest(self, input: &[u8]) -> String;
|
||||
fn update(&mut self, input: &[u8]);
|
||||
fn verify(self, encoded: &str) -> bool;
|
||||
}
|
||||
|
||||
pub trait DigestFactory {
|
||||
|
|
|
@ -51,6 +51,16 @@ impl<'a> apub_core::digest::Digest for OpenSslDigest {
|
|||
|
||||
openssl::base64::encode_block(&bytes)
|
||||
}
|
||||
|
||||
fn update(&mut self, input: &[u8]) {
|
||||
self.digest.update(input);
|
||||
}
|
||||
|
||||
fn verify(self, encoded: &str) -> bool {
|
||||
let bytes = self.digest.finish();
|
||||
|
||||
openssl::base64::encode_block(&bytes) == encoded
|
||||
}
|
||||
}
|
||||
|
||||
impl apub_core::signature::Sign for OpenSslSigner {
|
||||
|
|
|
@ -60,6 +60,16 @@ impl apub_core::digest::Digest for Sha256Digest {
|
|||
|
||||
base64::encode(&bytes)
|
||||
}
|
||||
|
||||
fn update(&mut self, input: &[u8]) {
|
||||
self.digest.update(input);
|
||||
}
|
||||
|
||||
fn verify(self, encoded: &str) -> bool {
|
||||
let bytes = self.digest.finalize();
|
||||
|
||||
base64::encode(&bytes) == encoded
|
||||
}
|
||||
}
|
||||
|
||||
impl apub_core::signature::Sign for RsaSigner {
|
||||
|
|
Loading…
Reference in a new issue