|
6 | 6 | //! A `MultihashRef` is the same as a `Multihash`, except that it doesn't own its data.
|
7 | 7 | //!
|
8 | 8 |
|
| 9 | +#![deny(missing_docs)] |
| 10 | + |
9 | 11 | mod errors;
|
10 | 12 | mod hashes;
|
11 | 13 | mod storage;
|
12 | 14 |
|
| 15 | +use std::cmp; |
13 | 16 | use std::convert::TryFrom;
|
14 |
| -use std::fmt::Debug; |
| 17 | +use std::fmt::{self, Debug}; |
15 | 18 | use std::hash;
|
16 | 19 |
|
17 | 20 | use blake2b_simd::{blake2b, Params as Blake2bVariable};
|
18 | 21 | use blake2s_simd::{blake2s, Params as Blake2sVariable};
|
19 |
| -use sha2::Digest; |
20 |
| -use tiny_keccak::Keccak; |
| 22 | +use digest::Digest; |
21 | 23 | use unsigned_varint::{decode, encode};
|
22 | 24 |
|
23 |
| -pub use errors::{DecodeError, DecodeOwnedError, EncodeError}; |
24 |
| -pub use hashes::Hash; |
25 |
| -use std::{cmp, fmt}; |
26 |
| -use storage::Storage; |
| 25 | +pub use self::errors::{DecodeError, DecodeOwnedError, EncodeError}; |
| 26 | +pub use self::hashes::Hash; |
| 27 | +use self::storage::Storage; |
27 | 28 |
|
28 |
| -// Helper macro for encoding input into output using sha1, sha2, tiny_keccak, or blake2 |
| 29 | +// Helper macro for encoding input into output using sha1, sha2, sha3, or blake2 |
29 | 30 | macro_rules! encode {
|
30 |
| - (sha1, Sha1, $input:expr, $output:expr) => {{ |
31 |
| - let mut hasher = sha1::Sha1::new(); |
32 |
| - hasher.update($input); |
33 |
| - $output.copy_from_slice(&hasher.digest().bytes()); |
| 31 | + (sha1, $algorithm:ident, $input:expr, $output:expr) => {{ |
| 32 | + let mut hasher = sha1::$algorithm::default(); |
| 33 | + hasher.input($input); |
| 34 | + $output.copy_from_slice(&hasher.result().as_ref()); |
34 | 35 | }};
|
35 | 36 | (sha2, $algorithm:ident, $input:expr, $output:expr) => {{
|
36 | 37 | let mut hasher = sha2::$algorithm::default();
|
37 | 38 | hasher.input($input);
|
38 | 39 | $output.copy_from_slice(hasher.result().as_ref());
|
39 | 40 | }};
|
40 |
| - (tiny, $constructor:ident, $input:expr, $output:expr) => {{ |
41 |
| - let mut kec = Keccak::$constructor(); |
42 |
| - kec.update($input); |
43 |
| - kec.finalize($output); |
| 41 | + (sha3, $algorithm:ident, $input:expr, $output:expr) => {{ |
| 42 | + let mut hasher = sha3::$algorithm::default(); |
| 43 | + hasher.input($input); |
| 44 | + $output.copy_from_slice(hasher.result().as_ref()); |
44 | 45 | }};
|
45 | 46 | (blake2, $algorithm:ident, $input:expr, $output:expr) => {{
|
46 | 47 | let hash = $algorithm($input);
|
@@ -117,14 +118,14 @@ pub fn encode(hash: Hash, input: &[u8]) -> Result<Multihash, EncodeError> {
|
117 | 118 | SHA1 => sha1::Sha1,
|
118 | 119 | SHA2256 => sha2::Sha256,
|
119 | 120 | SHA2512 => sha2::Sha512,
|
120 |
| - SHA3224 => tiny::new_sha3_224, |
121 |
| - SHA3256 => tiny::new_sha3_256, |
122 |
| - SHA3384 => tiny::new_sha3_384, |
123 |
| - SHA3512 => tiny::new_sha3_512, |
124 |
| - Keccak224 => tiny::new_keccak224, |
125 |
| - Keccak256 => tiny::new_keccak256, |
126 |
| - Keccak384 => tiny::new_keccak384, |
127 |
| - Keccak512 => tiny::new_keccak512, |
| 121 | + SHA3224 => sha3::Sha3_224, |
| 122 | + SHA3256 => sha3::Sha3_256, |
| 123 | + SHA3384 => sha3::Sha3_384, |
| 124 | + SHA3512 => sha3::Sha3_512, |
| 125 | + Keccak224 => sha3::Keccak224, |
| 126 | + Keccak256 => sha3::Keccak256, |
| 127 | + Keccak384 => sha3::Keccak384, |
| 128 | + Keccak512 => sha3::Keccak512, |
128 | 129 | Blake2b512 => blake2::blake2b,
|
129 | 130 | Blake2b256 => blake2_256::Blake2bVariable,
|
130 | 131 | Blake2s256 => blake2::blake2s,
|
|
0 commit comments