2023-11-26 01:52:55 +00:00
|
|
|
use base64::prelude::*;
|
2021-12-13 18:34:17 +00:00
|
|
|
use sha2::{Sha224, Sha256, Sha384, Sha512};
|
2020-09-29 23:57:59 +00:00
|
|
|
|
|
|
|
use super::DigestCreate;
|
|
|
|
|
2021-12-13 18:34:17 +00:00
|
|
|
fn create<D: sha2::Digest + sha2::digest::FixedOutputReset>(
|
|
|
|
digest: &mut D,
|
|
|
|
input: &[u8],
|
|
|
|
) -> String {
|
|
|
|
sha2::Digest::update(digest, input);
|
2023-11-26 01:52:55 +00:00
|
|
|
BASE64_STANDARD.encode(&digest.finalize_reset())
|
2020-09-29 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DigestCreate for Sha224 {
|
|
|
|
const NAME: &'static str = "SHA-224";
|
|
|
|
|
|
|
|
fn compute(&mut self, input: &[u8]) -> String {
|
|
|
|
create(self, input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DigestCreate for Sha256 {
|
|
|
|
const NAME: &'static str = "SHA-256";
|
|
|
|
|
|
|
|
fn compute(&mut self, input: &[u8]) -> String {
|
|
|
|
create(self, input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DigestCreate for Sha384 {
|
|
|
|
const NAME: &'static str = "SHA-384";
|
|
|
|
|
|
|
|
fn compute(&mut self, input: &[u8]) -> String {
|
|
|
|
create(self, input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DigestCreate for Sha512 {
|
|
|
|
const NAME: &'static str = "SHA-512";
|
|
|
|
|
|
|
|
fn compute(&mut self, input: &[u8]) -> String {
|
|
|
|
create(self, input)
|
|
|
|
}
|
|
|
|
}
|