@@ -4,15 +4,21 @@ use hmac::digest::{
44} ;
55use hmac:: { EagerHash , Hmac , SimpleHmac } ;
66
7- pub trait Sealed < H : OutputSizeUser > {
7+ /// Trait representing a HMAC implementation.
8+ ///
9+ /// Most users should use [`Hmac`] or [`SimpleHmac`].
10+ pub trait HmacImpl < H : OutputSizeUser > : Clone {
11+ /// Create new HMAC state with the given key.
812 fn new_from_slice ( key : & [ u8 ] ) -> Self ;
913
14+ /// Update HMAC state.
1015 fn update ( & mut self , data : & [ u8 ] ) ;
1116
17+ /// Finalize the HMAC state and get generated tag.
1218 fn finalize ( self ) -> Output < H > ;
1319}
1420
15- impl < H : EagerHash > Sealed < H > for Hmac < H > {
21+ impl < H : EagerHash > HmacImpl < H > for Hmac < H > {
1622 #[ inline( always) ]
1723 fn new_from_slice ( key : & [ u8 ] ) -> Self {
1824 KeyInit :: new_from_slice ( key) . expect ( "HMAC can take a key of any size" )
@@ -24,15 +30,16 @@ impl<H: EagerHash> Sealed<H> for Hmac<H> {
2430 }
2531
2632 #[ inline( always) ]
27- #[ allow( deprecated) ] // clone_from_slice
2833 fn finalize ( self ) -> Output < H > {
29- // Output<H> and Output<H::Core> are always equal to each other,
30- // but we can not prove it at type level
31- Output :: < H > :: clone_from_slice ( & self . finalize_fixed ( ) )
34+ Output :: < H > :: try_from ( & self . finalize_fixed ( ) [ ..] )
35+ . expect ( "Output<H> and Output<Hmac<H>> are always equal to each other" )
3236 }
3337}
3438
35- impl < H : Digest + BlockSizeUser + Clone > Sealed < H > for SimpleHmac < H > {
39+ impl < H > HmacImpl < H > for SimpleHmac < H >
40+ where
41+ H : Digest + BlockSizeUser + Clone ,
42+ {
3643 #[ inline( always) ]
3744 fn new_from_slice ( key : & [ u8 ] ) -> Self {
3845 KeyInit :: new_from_slice ( key) . expect ( "HMAC can take a key of any size" )
@@ -44,10 +51,8 @@ impl<H: Digest + BlockSizeUser + Clone> Sealed<H> for SimpleHmac<H> {
4451 }
4552
4653 #[ inline( always) ]
47- #[ allow( deprecated) ] // clone_from_slice
4854 fn finalize ( self ) -> Output < H > {
49- // Output<H> and Output<H::Core> are always equal to each other,
50- // but we can not prove it at type level
51- Output :: < H > :: clone_from_slice ( & self . finalize_fixed ( ) )
55+ Output :: < H > :: try_from ( & self . finalize_fixed ( ) [ ..] )
56+ . expect ( "Output<H> and Output<SimpleHmac<H>> are always equal to each other" )
5257 }
5358}
0 commit comments