Expose hmac_sha1 function
This commit is contained in:
parent
b7baacc047
commit
d8e821bae9
|
|
@ -344,6 +344,11 @@ pub fn hmac_sha512(key: &[u8], data: &[u8]) -> Result<[u8; 64], ErrorStack> {
|
|||
hmac(MessageDigest::sha512(), key, data)
|
||||
}
|
||||
|
||||
/// Computes HMAC with SHA-1 digest.
|
||||
pub fn hmac_sha1(key: &[u8], data: &[u8]) -> Result<[u8; 20], ErrorStack> {
|
||||
hmac(MessageDigest::sha1(), key, data)
|
||||
}
|
||||
|
||||
fn hmac<const N: usize>(
|
||||
digest: MessageDigest,
|
||||
key: &[u8],
|
||||
|
|
@ -437,6 +442,19 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hmac_sha1() {
|
||||
let hmac = hmac_sha1(b"That's a secret".as_slice(), b"Hello world!".as_slice()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
hmac,
|
||||
[
|
||||
0xe1, 0x06, 0x76, 0x46, 0x3b, 0x82, 0x67, 0xa1, 0xae, 0xe5, 0x1c, 0xfa, 0xee, 0x36,
|
||||
0x1d, 0x4b, 0xd4, 0x41, 0x6e, 0x37
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_md5() {
|
||||
for test in MD5_TESTS.iter() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue