1
- use crate :: hasher:: Hasher ;
2
-
3
- #[ cfg( feature = "std" ) ]
4
- use std:: io;
5
-
6
- #[ cfg( not( feature = "std" ) ) ]
7
- use core2:: io;
8
-
1
+ #[ cfg( any( feature = "strobe" , feature = "identity" , feature = "blake3" ) ) ]
9
2
macro_rules! derive_write {
10
3
( $name: ident) => {
11
- impl <const S : usize > io:: Write for $name<S > {
12
- fn write( & mut self , buf: & [ u8 ] ) -> io:: Result <usize > {
4
+ impl <const S : usize > core2:: io:: Write for $name<S > {
5
+ fn write( & mut self , buf: & [ u8 ] ) -> core2:: io:: Result <usize > {
6
+ use multihash_derive:: Hasher as _;
7
+
13
8
self . update( buf) ;
14
9
Ok ( buf. len( ) )
15
10
}
16
11
17
- fn flush( & mut self ) -> io:: Result <( ) > {
12
+ fn flush( & mut self ) -> core2 :: io:: Result <( ) > {
18
13
Ok ( ( ) )
19
14
}
20
15
}
21
16
} ;
22
17
}
23
18
24
- #[ cfg( any( feature = "blake2b" , feature = "blake2s" ) ) ]
19
+ #[ cfg( any( feature = "blake2b" , feature = "blake2s" , feature = "blake3" ) ) ]
25
20
macro_rules! derive_hasher_blake {
26
21
( $module: ident, $name: ident) => {
27
22
/// Multihash hasher.
@@ -42,7 +37,7 @@ macro_rules! derive_hasher_blake {
42
37
}
43
38
}
44
39
45
- impl <const S : usize > Hasher for $name<S > {
40
+ impl <const S : usize > multihash_derive :: Hasher for $name<S > {
46
41
fn update( & mut self , input: & [ u8 ] ) {
47
42
self . state. update( input) ;
48
43
}
@@ -67,8 +62,6 @@ macro_rules! derive_hasher_blake {
67
62
68
63
#[ cfg( feature = "blake2b" ) ]
69
64
pub mod blake2b {
70
- use super :: * ;
71
-
72
65
derive_hasher_blake ! ( blake2b_simd, Blake2bHasher ) ;
73
66
74
67
/// 256 bit blake2b hasher.
@@ -80,8 +73,6 @@ pub mod blake2b {
80
73
81
74
#[ cfg( feature = "blake2s" ) ]
82
75
pub mod blake2s {
83
- use super :: * ;
84
-
85
76
derive_hasher_blake ! ( blake2s_simd, Blake2sHasher ) ;
86
77
87
78
/// 256 bit blake2b hasher.
@@ -93,8 +84,6 @@ pub mod blake2s {
93
84
94
85
#[ cfg( feature = "blake3" ) ]
95
86
pub mod blake3 {
96
- use super :: * ;
97
-
98
87
/// Multihash hasher.
99
88
#[ derive( Debug ) ]
100
89
pub struct Blake3Hasher < const S : usize > {
@@ -121,7 +110,7 @@ pub mod blake3 {
121
110
}
122
111
}
123
112
124
- impl < const S : usize > Hasher for Blake3Hasher < S > {
113
+ impl < const S : usize > multihash_derive :: Hasher for Blake3Hasher < S > {
125
114
fn update ( & mut self , input : & [ u8 ] ) {
126
115
self . hasher . update ( input) ;
127
116
}
@@ -143,7 +132,12 @@ pub mod blake3 {
143
132
pub type Blake3_256 = Blake3Hasher < 32 > ;
144
133
}
145
134
146
- #[ cfg( feature = "digest" ) ]
135
+ #[ cfg( any(
136
+ feature = "sha1" ,
137
+ feature = "sha2" ,
138
+ feature = "sha3" ,
139
+ feature = "ripemd"
140
+ ) ) ]
147
141
macro_rules! derive_rustcrypto_hasher {
148
142
( $module: ty, $name: ident, $size: expr) => {
149
143
/// Multihash hasher.
@@ -162,7 +156,7 @@ macro_rules! derive_rustcrypto_hasher {
162
156
}
163
157
}
164
158
165
- impl $crate :: hasher :: Hasher for $name {
159
+ impl :: multihash_derive :: Hasher for $name {
166
160
fn update( & mut self , input: & [ u8 ] ) {
167
161
use digest:: Digest ;
168
162
self . state. update( input)
@@ -183,13 +177,15 @@ macro_rules! derive_rustcrypto_hasher {
183
177
}
184
178
}
185
179
186
- impl io:: Write for $name {
187
- fn write( & mut self , buf: & [ u8 ] ) -> io:: Result <usize > {
180
+ impl core2:: io:: Write for $name {
181
+ fn write( & mut self , buf: & [ u8 ] ) -> core2:: io:: Result <usize > {
182
+ use multihash_derive:: Hasher as _;
183
+
188
184
self . update( buf) ;
189
185
Ok ( buf. len( ) )
190
186
}
191
187
192
- fn flush( & mut self ) -> io:: Result <( ) > {
188
+ fn flush( & mut self ) -> core2 :: io:: Result <( ) > {
193
189
Ok ( ( ) )
194
190
}
195
191
}
@@ -198,47 +194,37 @@ macro_rules! derive_rustcrypto_hasher {
198
194
199
195
#[ cfg( feature = "sha1" ) ]
200
196
pub mod sha1 {
201
- use super :: * ;
202
-
203
197
derive_rustcrypto_hasher ! ( :: sha1:: Sha1 , Sha1 , 20 ) ;
204
198
}
205
199
206
200
#[ cfg( feature = "sha2" ) ]
207
201
pub mod sha2 {
208
- use super :: * ;
209
-
210
- derive_rustcrypto_hasher ! ( sha_2:: Sha256 , Sha2_256 , 32 ) ;
211
- derive_rustcrypto_hasher ! ( sha_2:: Sha512 , Sha2_512 , 64 ) ;
202
+ derive_rustcrypto_hasher ! ( :: sha2:: Sha256 , Sha2_256 , 32 ) ;
203
+ derive_rustcrypto_hasher ! ( :: sha2:: Sha512 , Sha2_512 , 64 ) ;
212
204
}
213
205
214
206
#[ cfg( feature = "sha3" ) ]
215
207
pub mod sha3 {
216
- use super :: * ;
217
-
218
- derive_rustcrypto_hasher ! ( sha_3:: Sha3_224 , Sha3_224 , 28 ) ;
219
- derive_rustcrypto_hasher ! ( sha_3:: Sha3_256 , Sha3_256 , 32 ) ;
220
- derive_rustcrypto_hasher ! ( sha_3:: Sha3_384 , Sha3_384 , 48 ) ;
221
- derive_rustcrypto_hasher ! ( sha_3:: Sha3_512 , Sha3_512 , 64 ) ;
222
-
223
- derive_rustcrypto_hasher ! ( sha_3:: Keccak224 , Keccak224 , 28 ) ;
224
- derive_rustcrypto_hasher ! ( sha_3:: Keccak256 , Keccak256 , 32 ) ;
225
- derive_rustcrypto_hasher ! ( sha_3:: Keccak384 , Keccak384 , 48 ) ;
226
- derive_rustcrypto_hasher ! ( sha_3:: Keccak512 , Keccak512 , 64 ) ;
208
+ derive_rustcrypto_hasher ! ( :: sha3:: Sha3_224 , Sha3_224 , 28 ) ;
209
+ derive_rustcrypto_hasher ! ( :: sha3:: Sha3_256 , Sha3_256 , 32 ) ;
210
+ derive_rustcrypto_hasher ! ( :: sha3:: Sha3_384 , Sha3_384 , 48 ) ;
211
+ derive_rustcrypto_hasher ! ( :: sha3:: Sha3_512 , Sha3_512 , 64 ) ;
212
+
213
+ derive_rustcrypto_hasher ! ( :: sha3:: Keccak224 , Keccak224 , 28 ) ;
214
+ derive_rustcrypto_hasher ! ( :: sha3:: Keccak256 , Keccak256 , 32 ) ;
215
+ derive_rustcrypto_hasher ! ( :: sha3:: Keccak384 , Keccak384 , 48 ) ;
216
+ derive_rustcrypto_hasher ! ( :: sha3:: Keccak512 , Keccak512 , 64 ) ;
227
217
}
228
218
229
219
#[ cfg( feature = "ripemd" ) ]
230
220
pub mod ripemd {
231
-
232
- use super :: * ;
233
-
234
- derive_rustcrypto_hasher ! ( ripemd_rs:: Ripemd160 , Ripemd160 , 20 ) ;
235
- derive_rustcrypto_hasher ! ( ripemd_rs:: Ripemd256 , Ripemd256 , 32 ) ;
236
- derive_rustcrypto_hasher ! ( ripemd_rs:: Ripemd320 , Ripemd320 , 40 ) ;
221
+ derive_rustcrypto_hasher ! ( :: ripemd:: Ripemd160 , Ripemd160 , 20 ) ;
222
+ derive_rustcrypto_hasher ! ( :: ripemd:: Ripemd256 , Ripemd256 , 32 ) ;
223
+ derive_rustcrypto_hasher ! ( :: ripemd:: Ripemd320 , Ripemd320 , 40 ) ;
237
224
}
238
225
226
+ #[ cfg( feature = "identity" ) ]
239
227
pub mod identity {
240
- use super :: * ;
241
-
242
228
/// Identity hasher with a maximum size.
243
229
///
244
230
/// # Panics
@@ -259,7 +245,7 @@ pub mod identity {
259
245
}
260
246
}
261
247
262
- impl < const S : usize > Hasher for IdentityHasher < S > {
248
+ impl < const S : usize > multihash_derive :: Hasher for IdentityHasher < S > {
263
249
fn update ( & mut self , input : & [ u8 ] ) {
264
250
let start = self . i . min ( self . bytes . len ( ) ) ;
265
251
let end = ( self . i + input. len ( ) ) . min ( self . bytes . len ( ) ) ;
@@ -288,7 +274,6 @@ pub mod identity {
288
274
289
275
#[ cfg( feature = "strobe" ) ]
290
276
pub mod strobe {
291
- use super :: * ;
292
277
use strobe_rs:: { SecParam , Strobe } ;
293
278
294
279
/// Strobe hasher.
@@ -308,7 +293,7 @@ pub mod strobe {
308
293
}
309
294
}
310
295
311
- impl < const S : usize > Hasher for StrobeHasher < S > {
296
+ impl < const S : usize > multihash_derive :: Hasher for StrobeHasher < S > {
312
297
fn update ( & mut self , input : & [ u8 ] ) {
313
298
self . strobe . ad ( input, self . initialized ) ;
314
299
self . initialized = true ;
0 commit comments