diff --git a/hashes/src/hmac.rs b/hashes/src/hmac.rs index c3dca2d85..a661f64e3 100644 --- a/hashes/src/hmac.rs +++ b/hashes/src/hmac.rs @@ -19,6 +19,16 @@ use crate::{FromSliceError, GeneralHash, Hash, HashEngine}; #[repr(transparent)] pub struct Hmac(T); +impl Hmac { + /// Constructs a new keyed HMAC engine from `key`. + pub fn engine(key: &[u8]) -> HmacEngine + where + ::Engine: Default, + { + HmacEngine::new(key) + } +} + impl str::FromStr for Hmac { type Err = ::Err; fn from_str(s: &str) -> Result { Ok(Hmac(str::FromStr::from_str(s)?)) } @@ -32,7 +42,7 @@ pub struct HmacEngine { } impl HmacEngine { - /// Constructs a new keyed HMAC from `key`. + /// Constructs a new keyed HMAC engine from `key`. /// /// We only support underlying hashes whose block sizes are ≤ 128 bytes. /// @@ -321,7 +331,7 @@ mod benches { #[bench] pub fn hmac_sha256_10(bh: &mut Bencher) { - let mut engine = HmacEngine::::new(&[]); + let mut engine = Hmac::::engine(&[]); let bytes = [1u8; 10]; bh.iter(|| { engine.input(&bytes); @@ -331,7 +341,7 @@ mod benches { #[bench] pub fn hmac_sha256_1k(bh: &mut Bencher) { - let mut engine = HmacEngine::::new(&[]); + let mut engine = Hmac::::engine(&[]); let bytes = [1u8; 1024]; bh.iter(|| { engine.input(&bytes); @@ -341,7 +351,7 @@ mod benches { #[bench] pub fn hmac_sha256_64k(bh: &mut Bencher) { - let mut engine = HmacEngine::::new(&[]); + let mut engine = Hmac::::engine(&[]); let bytes = [1u8; 65536]; bh.iter(|| { engine.input(&bytes);