openethereum/util/src/rlp/rlperrors.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

2015-12-08 12:59:19 +01:00
use std::fmt;
use std::error::Error as StdError;
2016-01-29 13:59:29 +01:00
use rlp::bytes::FromBytesError;
2015-12-08 12:59:19 +01:00
#[derive(Debug, PartialEq, Eq)]
/// Error concerning the RLP decoder.
2015-12-08 12:59:19 +01:00
pub enum DecoderError {
/// Couldn't convert given bytes to an instance of required type.
2015-12-08 12:59:19 +01:00
FromBytesError(FromBytesError),
/// Data has additional bytes at the end of the valid RLP fragment.
RlpIsTooBig,
/// Data has too few bytes for valid RLP.
2015-12-08 12:59:19 +01:00
RlpIsTooShort,
/// Expect an encoded list, RLP was something else.
2015-12-08 12:59:19 +01:00
RlpExpectedToBeList,
/// Expect encoded data, RLP was something else.
2015-12-08 12:59:19 +01:00
RlpExpectedToBeData,
/// Expected a different size list.
RlpIncorrectListLen,
/// Data length number has a prefixed zero byte, invalid for numbers.
RlpDataLenWithZeroPrefix,
/// List length number has a prefixed zero byte, invalid for numbers.
RlpListLenWithZeroPrefix,
/// Non-canonical (longer than necessary) representation used for data or list.
RlpInvalidIndirection,
/// Declared length is inconsistent with data specified after.
2016-01-25 13:23:05 +01:00
RlpInconsistentLengthAndData
2015-12-08 12:59:19 +01:00
}
impl StdError for DecoderError {
fn description(&self) -> &str {
"builder error"
}
}
impl fmt::Display for DecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self, f)
}
}
impl From<FromBytesError> for DecoderError {
fn from(err: FromBytesError) -> DecoderError {
DecoderError::FromBytesError(err)
}
}