|
1 | 1 | use ethereum_types::H256;
|
2 |
| -use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, structs::Encoder}; |
| 2 | +use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, error::RLPDecodeError, structs::Encoder}; |
3 | 3 | #[cfg(feature = "libmdbx")]
|
4 | 4 | use libmdbx::orm::{Decodable, Encodable};
|
5 | 5 | use sha3::{Digest, Keccak256};
|
@@ -36,7 +36,7 @@ impl NodeHash {
|
36 | 36 | }
|
37 | 37 |
|
38 | 38 | /// Converts a slice of an already hashed data (in case it's not inlineable) to a NodeHash.
|
39 |
| - /// |
| 39 | + /// Panics if the slice is over 32 bytes |
40 | 40 | /// If you need to hash it in case its len >= 32 see `from_encoded_raw`
|
41 | 41 | pub(crate) fn from_slice(slice: &[u8]) -> NodeHash {
|
42 | 42 | match slice.len() {
|
@@ -103,12 +103,6 @@ impl NodeHash {
|
103 | 103 | }
|
104 | 104 | }
|
105 | 105 |
|
106 |
| -impl From<Vec<u8>> for NodeHash { |
107 |
| - fn from(value: Vec<u8>) -> Self { |
108 |
| - NodeHash::from_slice(&value) |
109 |
| - } |
110 |
| -} |
111 |
| - |
112 | 106 | impl From<H256> for NodeHash {
|
113 | 107 | fn from(value: H256) -> Self {
|
114 | 108 | NodeHash::Hashed(value)
|
@@ -160,7 +154,10 @@ impl RLPDecode for NodeHash {
|
160 | 154 | fn decode_unfinished(rlp: &[u8]) -> Result<(Self, &[u8]), ethrex_rlp::error::RLPDecodeError> {
|
161 | 155 | let (hash, rest): (Vec<u8>, &[u8]);
|
162 | 156 | (hash, rest) = RLPDecode::decode_unfinished(rlp)?;
|
163 |
| - let hash = NodeHash::from(hash); |
| 157 | + if hash.len() > 32 { |
| 158 | + return Err(RLPDecodeError::InvalidLength); |
| 159 | + } |
| 160 | + let hash = NodeHash::from_slice(&hash); |
164 | 161 | Ok((hash, rest))
|
165 | 162 | }
|
166 | 163 | }
|
0 commit comments