Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Handle RLP to string UTF-8 decoding errors (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and tomusdrw committed Sep 21, 2016
1 parent df61b1b commit 8dd0220
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion util/src/rlp/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ pub enum FromBytesError {
DataIsTooLong,
/// Integer-representation is non-canonically prefixed with zero byte(s).
ZeroPrefixedInt,
/// String representation is not utf-8
InvalidUtf8,
}

impl StdError for FromBytesError {
Expand All @@ -199,7 +201,7 @@ pub trait FromBytes: Sized {

impl FromBytes for String {
fn from_bytes(bytes: &[u8]) -> FromBytesResult<String> {
Ok(::std::str::from_utf8(bytes).unwrap().to_owned())
::std::str::from_utf8(bytes).map(|s| s.to_owned()).map_err(|_| FromBytesError::InvalidUtf8)
}
}

Expand Down

0 comments on commit 8dd0220

Please sign in to comment.