You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
837 B

use crate::common_types::DnsSecDigestAlgorithmKnown;
pub fn sha1(data: &[u8]) -> Vec<u8> {
use sha1::Digest;
sha1::Sha1::digest(data).as_slice().to_vec()
}
pub fn sha256(data: &[u8]) -> Vec<u8> {
use sha2::Digest;
sha2::Sha256::digest(data).as_slice().to_vec()
}
pub fn sha384(data: &[u8]) -> Vec<u8> {
use sha2::Digest;
sha2::Sha384::digest(data).as_slice().to_vec()
}
// gostR3411
pub fn gost_r3411(data: &[u8]) -> Vec<u8> {
use gost94::Digest;
gost94::Gost94CryptoPro::digest(data).as_slice().to_vec()
}
pub fn ds_hash(alg: DnsSecDigestAlgorithmKnown, data: &[u8]) -> Vec<u8> {
match alg {
DnsSecDigestAlgorithmKnown::SHA1 => sha1(data),
DnsSecDigestAlgorithmKnown::SHA256 => sha256(data),
DnsSecDigestAlgorithmKnown::GOST_R_34_11_94 => gost_r3411(data),
DnsSecDigestAlgorithmKnown::SHA384 => sha384(data),
}
}