|
14 | 14 | // You should have received a copy of the GNU Affero General Public License |
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 |
|
| 17 | +use digest::Digest; |
17 | 18 | use primitives::{H160, H256}; |
18 | | -use rcrypto::digest::Digest; |
19 | | -use rcrypto::ripemd160::Ripemd160; |
20 | | -use rcrypto::sha1::Sha1; |
21 | | -use rcrypto::sha2::Sha256; |
22 | | -use rcrypto::sha3::Sha3; |
| 19 | +use ripemd160::Ripemd160; |
| 20 | +use sha1::Sha1; |
| 21 | +use sha2::Sha256; |
| 22 | +use sha3::Keccak256; |
23 | 23 |
|
24 | 24 | /// RIPEMD160 |
25 | 25 | #[inline] |
26 | 26 | pub fn ripemd160<T: AsRef<[u8]>>(s: T) -> H160 { |
27 | 27 | let input = s.as_ref(); |
28 | | - let mut result = H160::default(); |
29 | 28 | let mut hasher = Ripemd160::new(); |
30 | 29 | hasher.input(input); |
31 | | - hasher.result(&mut *result); |
32 | | - result |
| 30 | + let mut array: [u8; 20] = [0; 20]; |
| 31 | + array.copy_from_slice(&hasher.result()); |
| 32 | + H160(array) |
33 | 33 | } |
34 | 34 |
|
35 | 35 | /// SHA-1 |
36 | 36 | #[inline] |
37 | 37 | pub fn sha1<T: AsRef<[u8]>>(s: T) -> H160 { |
38 | 38 | let input = s.as_ref(); |
39 | | - let mut result = H160::default(); |
40 | 39 | let mut hasher = Sha1::new(); |
41 | 40 | hasher.input(input); |
42 | | - hasher.result(&mut *result); |
43 | | - result |
| 41 | + let mut array: [u8; 20] = [0; 20]; |
| 42 | + array.copy_from_slice(&hasher.result()); |
| 43 | + H160(array) |
44 | 44 | } |
45 | 45 |
|
46 | 46 | /// SHA-256 |
47 | 47 | #[inline] |
48 | 48 | pub fn sha256<T: AsRef<[u8]>>(s: T) -> H256 { |
49 | 49 | let input = s.as_ref(); |
50 | | - let mut result = H256::default(); |
51 | 50 | let mut hasher = Sha256::new(); |
52 | 51 | hasher.input(input); |
53 | | - hasher.result(&mut *result); |
54 | | - result |
| 52 | + let mut array: [u8; 32] = [0; 32]; |
| 53 | + array.copy_from_slice(&hasher.result()); |
| 54 | + H256(array) |
55 | 55 | } |
56 | 56 |
|
57 | 57 | /// KECCAK256 |
58 | 58 | #[inline] |
59 | 59 | pub fn keccak256<T: AsRef<[u8]>>(s: T) -> H256 { |
60 | 60 | let input = s.as_ref(); |
61 | | - let mut result = H256::default(); |
62 | | - let mut hasher = Sha3::keccak256(); |
| 61 | + let mut hasher = Keccak256::new(); |
63 | 62 | hasher.input(input); |
64 | | - hasher.result(&mut result); |
65 | | - result |
| 63 | + let mut array: [u8; 32] = [0; 32]; |
| 64 | + array.copy_from_slice(&hasher.result()); |
| 65 | + H256(array) |
66 | 66 | } |
67 | 67 |
|
68 | 68 | #[cfg(test)] |
|
0 commit comments