rlp/
error.rs

1// Copyright 2015-2017 Parity Technologies
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#[cfg(feature = "std")] use std::fmt;
10#[cfg(not(feature = "std"))] use core::fmt;
11
12#[cfg(feature = "std")]
13use std::error::Error as StdError;
14
15#[derive(Debug, PartialEq, Eq)]
16/// Error concerning the RLP decoder.
17pub enum DecoderError {
18	/// Data has additional bytes at the end of the valid RLP fragment.
19	RlpIsTooBig,
20	/// Data has too few bytes for valid RLP.
21	RlpIsTooShort,
22	/// Expect an encoded list, RLP was something else.
23	RlpExpectedToBeList,
24	/// Expect encoded data, RLP was something else.
25	RlpExpectedToBeData,
26	/// Expected a different size list.
27	RlpIncorrectListLen,
28	/// Data length number has a prefixed zero byte, invalid for numbers.
29	RlpDataLenWithZeroPrefix,
30	/// List length number has a prefixed zero byte, invalid for numbers.
31	RlpListLenWithZeroPrefix,
32	/// Non-canonical (longer than necessary) representation used for data or list.
33	RlpInvalidIndirection,
34	/// Declared length is inconsistent with data specified after.
35	RlpInconsistentLengthAndData,
36	/// Custom rlp decoding error.
37	Custom(&'static str),
38}
39
40#[cfg(feature = "std")]
41impl StdError for DecoderError {
42	fn description(&self) -> &str {
43		"builder error"
44	}
45}
46
47impl fmt::Display for DecoderError {
48	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49		fmt::Debug::fmt(&self, f)
50	}
51}