Skip to content

Commit 4127169

Browse files
committed
Migrate to separate newtype macros
1 parent c39b7eb commit 4127169

File tree

19 files changed

+108
-159
lines changed

19 files changed

+108
-159
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

belt-hash/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ pub use digest::{self, Digest};
1313
mod block_api;
1414
pub use block_api::{BeltHashCore, belt_compress};
1515

16-
digest::newtype!(
16+
digest::newtype_fixed_hash!(
1717
/// BelT hasher state.
1818
pub struct BeltHash(digest::core_api::CoreWrapper<BeltHashCore>);
19-
delegate_template: FixedOutputHash
2019
oid: "1.2.112.0.2.0.34.101.31.81"
2120
);

fsb/src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,23 @@ pub use block_api::{Fsb160Core, Fsb224Core, Fsb256Core, Fsb384Core, Fsb512Core};
1818

1919
use digest::core_api::CoreWrapper;
2020

21-
digest::newtype!(
21+
digest::newtype_fixed_hash!(
2222
/// FSB-160 hasher.
2323
pub struct Fsb160(CoreWrapper<Fsb160Core>);
24-
delegate_template: FixedOutputHash
2524
);
26-
digest::newtype!(
25+
digest::newtype_fixed_hash!(
2726
/// FSB-224 hasher.
2827
pub struct Fsb224(CoreWrapper<Fsb224Core>);
29-
delegate_template: FixedOutputHash
3028
);
31-
digest::newtype!(
29+
digest::newtype_fixed_hash!(
3230
/// FSB-256 hasher.
3331
pub struct Fsb256(CoreWrapper<Fsb256Core>);
34-
delegate_template: FixedOutputHash
3532
);
36-
digest::newtype!(
33+
digest::newtype_fixed_hash!(
3734
/// FSB-384 hasher.
3835
pub struct Fsb384(CoreWrapper<Fsb384Core>);
39-
delegate_template: FixedOutputHash
4036
);
41-
digest::newtype!(
37+
digest::newtype_fixed_hash!(
4238
/// FSB-512 hasher.
4339
pub struct Fsb512(CoreWrapper<Fsb512Core>);
44-
delegate_template: FixedOutputHash
4540
);

jh/src/block_api.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use digest::{
66
core_api::{
77
AlgorithmName, Block, Buffer, BufferKindUser, TruncSide, UpdateCore, VariableOutputCore,
88
},
9-
crypto_common::{BlockSizeUser, OutputSizeUser},
9+
crypto_common::{
10+
BlockSizeUser, OutputSizeUser,
11+
hazmat::{DeserializeStateError, SerializableState, SerializedState},
12+
},
1013
typenum::{U64, Unsigned},
1114
};
1215

@@ -108,3 +111,17 @@ impl Drop for JhCore {
108111

109112
#[cfg(feature = "zeroize")]
110113
impl digest::zeroize::ZeroizeOnDrop for JhCore {}
114+
115+
impl SerializableState for JhCore {
116+
type SerializedStateSize = U64;
117+
118+
fn serialize(&self) -> SerializedState<Self> {
119+
todo!()
120+
}
121+
122+
fn deserialize(
123+
_serialized_state: &SerializedState<Self>,
124+
) -> Result<Self, DeserializeStateError> {
125+
todo!()
126+
}
127+
}

jh/src/lib.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,19 @@ use digest::{
2222

2323
// note: we do not use `delegate_template: FixedOutputHash` because
2424
// `JhCore` does not implement `SerializableState`
25-
digest::newtype!(
25+
digest::newtype_fixed_hash!(
2626
/// JH-224 hasher.
2727
pub struct Jh224(CoreWrapper<CtVariableCoreWrapper<JhCore, U28>>);
28-
delegate:
29-
Debug Clone Default
30-
AlgorithmName
31-
BlockSizeUser OutputSizeUser
32-
HashMarker Reset Update
33-
FixedOutput FixedOutputReset
3428
);
35-
digest::newtype!(
29+
digest::newtype_fixed_hash!(
3630
/// JH-256 hasher.
3731
pub struct Jh256(CoreWrapper<CtVariableCoreWrapper<JhCore, U32>>);
38-
delegate:
39-
Debug Clone Default
40-
AlgorithmName
41-
BlockSizeUser OutputSizeUser
42-
HashMarker Reset Update
43-
FixedOutput FixedOutputReset
4432
);
45-
digest::newtype!(
33+
digest::newtype_fixed_hash!(
4634
/// JH-384 hasher.
4735
pub struct Jh384(CoreWrapper<CtVariableCoreWrapper<JhCore, U48>>);
48-
delegate:
49-
Debug Clone Default
50-
AlgorithmName
51-
BlockSizeUser OutputSizeUser
52-
HashMarker Reset Update
53-
FixedOutput FixedOutputReset
5436
);
55-
digest::newtype!(
37+
digest::newtype_fixed_hash!(
5638
/// JH-512 hasher.
5739
pub struct Jh512(CoreWrapper<CtVariableCoreWrapper<JhCore, U64>>);
58-
delegate:
59-
Debug Clone Default
60-
AlgorithmName
61-
BlockSizeUser OutputSizeUser
62-
HashMarker Reset Update
63-
FixedOutput FixedOutputReset
6440
);

md2/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ mod consts;
1515

1616
pub use block_api::Md2Core;
1717

18-
digest::newtype!(
18+
digest::newtype_fixed_hash!(
1919
/// MD2 hasher.
2020
pub struct Md2(digest::core_api::CoreWrapper<Md2Core>);
21-
delegate_template: FixedOutputHash
2221
oid: "1.2.840.113549.2.2"
2322
);

md4/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ mod block_api;
1414
mod compress;
1515
pub use block_api::Md4Core;
1616

17-
digest::newtype!(
17+
digest::newtype_fixed_hash!(
1818
/// MD4 hash.
1919
pub struct Md4(digest::core_api::CoreWrapper<Md4Core>);
20-
delegate_template: FixedOutputHash
2120
oid: "1.2.840.113549.2.4"
2221
);

md5/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ mod compress;
1414
mod consts;
1515
pub use block_api::Md5Core;
1616

17-
digest::newtype!(
17+
digest::newtype_fixed_hash!(
1818
/// MD5 hasher state.
1919
pub struct Md5(digest::core_api::CoreWrapper<Md5Core>);
20-
delegate_template: FixedOutputHash
2120
oid: "1.2.840.113549.2.5"
2221
);

ripemd/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,22 @@ use digest::core_api::CoreWrapper;
2525
// OpenSSL, GnuTLS, etc.) and the ISO one (1.0.10118.3.0.50/49), which seems
2626
// to be used by by Go and nobody else.
2727

28-
digest::newtype!(
28+
digest::newtype_fixed_hash!(
2929
/// RIPEMD-128 hasher
3030
pub struct Ripemd128(CoreWrapper<Ripemd128Core>);
31-
delegate_template: FixedOutputHash
3231
oid: "1.3.36.3.2.2"
3332
);
34-
digest::newtype!(
33+
digest::newtype_fixed_hash!(
3534
/// RIPEMD-160 hasher
3635
pub struct Ripemd160(CoreWrapper<Ripemd160Core>);
37-
delegate_template: FixedOutputHash
3836
oid: "1.3.36.3.2.1"
3937
);
40-
digest::newtype!(
38+
digest::newtype_fixed_hash!(
4139
/// RIPEMD-256 hasher
4240
pub struct Ripemd256(CoreWrapper<Ripemd256Core>);
43-
delegate_template: FixedOutputHash
4441
oid: "1.3.36.3.2.3"
4542
);
46-
digest::newtype!(
43+
digest::newtype_fixed_hash!(
4744
/// RIPEMD-320 hasher
4845
pub struct Ripemd320(CoreWrapper<Ripemd320Core>);
49-
delegate_template: FixedOutputHash
5046
);

sha1/src/block_api.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use digest::{
44
array::Array,
55
block_buffer::Eager,
66
core_api::{
7-
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, FixedOutputCore,
7+
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore,
88
OutputSizeUser, Reset, UpdateCore,
99
},
1010
crypto_common::hazmat::{DeserializeStateError, SerializableState, SerializedState},
@@ -26,13 +26,6 @@ pub struct Sha1Core {
2626
block_len: u64,
2727
}
2828

29-
digest::newtype!(
30-
/// SHA-1 hasher.
31-
pub struct Sha1(CoreWrapper<Sha1Core>);
32-
delegate_template: FixedOutputHash
33-
oid: "1.3.14.3.2.26"
34-
);
35-
3629
impl HashMarker for Sha1Core {}
3730

3831
impl BlockSizeUser for Sha1Core {

sha1/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ mod compress;
1515
pub use block_api::Sha1Core;
1616
pub use compress::compress;
1717

18-
digest::newtype!(
18+
digest::newtype_fixed_hash!(
1919
/// SHA-1 hasher.
2020
pub struct Sha1(digest::core_api::CoreWrapper<Sha1Core>);
21-
delegate_template: FixedOutputHash
2221
oid: "1.3.14.3.2.26"
2322
);

sha2/src/lib.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,33 @@ pub use sha512::compress512;
3636

3737
pub use block_api::{Sha256VarCore, Sha512VarCore};
3838

39-
digest::newtype!(
39+
digest::newtype_fixed_hash!(
4040
/// SHA-256 hasher.
4141
pub struct Sha256(CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U32>>);
42-
delegate_template: FixedOutputHash
4342
oid: "2.16.840.1.101.3.4.2.1"
4443
);
45-
digest::newtype!(
44+
digest::newtype_fixed_hash!(
4645
/// SHA-384 hasher.
4746
pub struct Sha384(CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U48>>);
48-
delegate_template: FixedOutputHash
4947
oid: "2.16.840.1.101.3.4.2.2"
5048
);
51-
digest::newtype!(
49+
digest::newtype_fixed_hash!(
5250
/// SHA-512 hasher.
5351
pub struct Sha512(CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U64>>);
54-
delegate_template: FixedOutputHash
5552
oid: "2.16.840.1.101.3.4.2.3"
5653
);
57-
digest::newtype!(
54+
digest::newtype_fixed_hash!(
5855
/// SHA-224 hasher.
5956
pub struct Sha224(CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U28>>);
60-
delegate_template: FixedOutputHash
6157
oid: "2.16.840.1.101.3.4.2.4"
6258
);
63-
digest::newtype!(
59+
digest::newtype_fixed_hash!(
6460
/// SHA-512/224 hasher.
6561
pub struct Sha512_224(CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U28>>);
66-
delegate_template: FixedOutputHash
6762
oid: "2.16.840.1.101.3.4.2.5"
6863
);
69-
digest::newtype!(
64+
digest::newtype_fixed_hash!(
7065
/// SHA-512/256 hasher.
7166
pub struct Sha512_256(CoreWrapper<CtVariableCoreWrapper<Sha512VarCore, U32>>);
72-
delegate_template: FixedOutputHash
7367
oid: "2.16.840.1.101.3.4.2.6"
7468
);

0 commit comments

Comments
 (0)