Skip to content

Commit 55327ca

Browse files
authored
hmac: move EagerHash to the crate root (#189)
The trait was unintentionally moved to the `block_api` module. Since it's used in generic code with non-block `Hmac` and `HmacReset` types, it's worth to expose it in the crate root.
1 parent 64d671d commit 55327ca

3 files changed

Lines changed: 34 additions & 32 deletions

File tree

hmac/src/block_api.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,15 @@
1-
use crate::utils::{IPAD, OPAD, get_der_key};
1+
use crate::utils::{EagerHash, IPAD, OPAD, get_der_key};
22
use core::{fmt, slice};
33
use digest::{
4-
Digest, HashMarker, InvalidLength, KeyInit, MacMarker, Output, Reset,
4+
InvalidLength, KeyInit, MacMarker, Output, Reset,
55
block_api::{
6-
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreProxy, FixedOutputCore,
6+
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore,
77
OutputSizeUser, UpdateCore,
88
},
99
block_buffer::Eager,
1010
crypto_common::{Key, KeySizeUser},
1111
};
1212

13-
/// Trait implemented by eager hashes which expose their block-level core.
14-
pub trait EagerHash: BlockSizeUser + Digest {
15-
/// Block-level core type of the hash.
16-
type Core: HashMarker
17-
+ UpdateCore
18-
+ FixedOutputCore
19-
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
20-
+ BufferKindUser<BufferKind = Eager>
21-
+ Default
22-
+ Clone;
23-
}
24-
25-
impl<T> EagerHash for T
26-
where
27-
T: CoreProxy + BlockSizeUser + Digest,
28-
<T as CoreProxy>::Core: HashMarker
29-
+ UpdateCore
30-
+ FixedOutputCore
31-
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
32-
+ BufferKindUser<BufferKind = Eager>
33-
+ Default
34-
+ Clone,
35-
{
36-
type Core = T::Core;
37-
}
38-
3913
/// Generic core HMAC instance, which operates over blocks.
4014
pub struct HmacCore<D: EagerHash> {
4115
digest: D::Core,

hmac/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ mod utils;
106106

107107
pub use simple::SimpleHmac;
108108
pub use simple_reset::SimpleHmacReset;
109+
pub use utils::EagerHash;
109110

110-
use block_api::EagerHash;
111111
use core::fmt;
112112
use digest::block_api::{AlgorithmName, CoreProxy};
113113

hmac/src/utils.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use digest::{
2-
Digest,
3-
block_api::{Block, BlockSizeUser},
2+
Digest, HashMarker,
3+
block_api::{
4+
Block, BlockSizeUser, BufferKindUser, CoreProxy, Eager, FixedOutputCore, UpdateCore,
5+
},
46
};
57

68
pub(crate) const IPAD: u8 = 0x36;
@@ -30,3 +32,29 @@ pub(crate) fn get_der_key<D: Digest + BlockSizeUser>(key: &[u8]) -> Block<D> {
3032
}
3133
der_key
3234
}
35+
36+
/// Trait implemented by eager hashes which expose their block-level core.
37+
pub trait EagerHash: BlockSizeUser + Digest {
38+
/// Block-level core type of the hash.
39+
type Core: HashMarker
40+
+ UpdateCore
41+
+ FixedOutputCore
42+
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
43+
+ BufferKindUser<BufferKind = Eager>
44+
+ Default
45+
+ Clone;
46+
}
47+
48+
impl<T> EagerHash for T
49+
where
50+
T: CoreProxy + BlockSizeUser + Digest,
51+
<T as CoreProxy>::Core: HashMarker
52+
+ UpdateCore
53+
+ FixedOutputCore
54+
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
55+
+ BufferKindUser<BufferKind = Eager>
56+
+ Default
57+
+ Clone,
58+
{
59+
type Core = T::Core;
60+
}

0 commit comments

Comments
 (0)