Skip to content

Commit

Permalink
remove TrailingBytes to avoid breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
Wollac committed Aug 5, 2024
1 parent 9a21052 commit 051ebf7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crates/rlp/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ pub fn decode_exact<T: Decodable>(bytes: impl AsRef<[u8]>) -> Result<T> {

// check if there are any remaining bytes after decoding
if !buf.is_empty() {
return Err(Error::TrailingBytes);
// TODO: introduce a new variant TrailingBytes to better distinguish this error
return Err(Error::UnexpectedLength);
}

Ok(out)
Expand Down Expand Up @@ -382,7 +383,7 @@ mod tests {
assert_eq!(decode_exact::<T>(&encoded), Ok(input));
assert_eq!(
decode_exact::<T>([encoded, vec![0x00]].concat()),
Err(Error::TrailingBytes)
Err(Error::UnexpectedLength)
);
}

Expand Down
3 changes: 0 additions & 3 deletions crates/rlp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub enum Error {
LeadingZero,
/// Overran input while decoding.
InputTooShort,
/// Additional trailing bytes found after decoding.
TrailingBytes,
/// Expected single byte, but got invalid value.
NonCanonicalSingleByte,
/// Expected size, but got invalid value.
Expand Down Expand Up @@ -44,7 +42,6 @@ impl fmt::Display for Error {
Self::Overflow => f.write_str("overflow"),
Self::LeadingZero => f.write_str("leading zero"),
Self::InputTooShort => f.write_str("input too short"),
Self::TrailingBytes => f.write_str("trailing bytes"),
Self::NonCanonicalSingleByte => f.write_str("non-canonical single byte"),
Self::NonCanonicalSize => f.write_str("non-canonical size"),
Self::UnexpectedLength => f.write_str("unexpected length"),
Expand Down

0 comments on commit 051ebf7

Please sign in to comment.