rlp/
error.rs

1// Copyright 2020 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
9use core::fmt;
10#[cfg(feature = "std")]
11use std::error::Error as StdError;
12
13#[derive(Debug, PartialEq, Eq, Clone)]
14/// Error concerning the RLP decoder.
15pub enum DecoderError {
16	/// Data has additional bytes at the end of the valid RLP fragment.
17	RlpIsTooBig,
18	/// Data has too few bytes for valid RLP.
19	RlpIsTooShort,
20	/// Expect an encoded list, RLP was something else.
21	RlpExpectedToBeList,
22	/// Expect encoded data, RLP was something else.
23	RlpExpectedToBeData,
24	/// Expected a different size list.
25	RlpIncorrectListLen,
26	/// Data length number has a prefixed zero byte, invalid for numbers.
27	RlpDataLenWithZeroPrefix,
28	/// List length number has a prefixed zero byte, invalid for numbers.
29	RlpListLenWithZeroPrefix,
30	/// Non-canonical (longer than necessary) representation used for data or list.
31	RlpInvalidIndirection,
32	/// Declared length is inconsistent with data specified after.
33	RlpInconsistentLengthAndData,
34	/// Declared length is invalid and results in overflow
35	RlpInvalidLength,
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}