mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(rlp): add comment on 0x80 decoding (#312)
* add comment on 0x80 decoding * decode 0x80 into zero explicitly * add explicit 0x80 decoding for ethereum types
This commit is contained in:
@ -185,6 +185,12 @@ macro_rules! decode_integer {
|
||||
if buf.remaining() < h.payload_length {
|
||||
return Err(DecodeError::InputTooShort)
|
||||
}
|
||||
// In the case of 0x80, the Header will be decoded, leaving h.payload_length to be
|
||||
// zero.
|
||||
// 0x80 is the canonical encoding of 0, so we return 0 here.
|
||||
if h.payload_length == 0 {
|
||||
return Ok(<$t>::from(0u8))
|
||||
}
|
||||
let v = <$t>::from_be_bytes(
|
||||
static_left_pad(&buf[..h.payload_length]).ok_or(DecodeError::LeadingZero)?,
|
||||
);
|
||||
@ -252,6 +258,12 @@ mod ethereum_types_support {
|
||||
if buf.remaining() < h.payload_length {
|
||||
return Err(DecodeError::InputTooShort)
|
||||
}
|
||||
// In the case of 0x80, the Header will be decoded, leaving h.payload_length to
|
||||
// be zero.
|
||||
// 0x80 is the canonical encoding of 0, so we return 0 here.
|
||||
if h.payload_length == 0 {
|
||||
return Ok(<$t>::from(0u8))
|
||||
}
|
||||
let n = <$t>::from_big_endian(
|
||||
&static_left_pad::<$n_bytes>(&buf[..h.payload_length])
|
||||
.ok_or(DecodeError::LeadingZero)?,
|
||||
|
||||
Reference in New Issue
Block a user