1use crate::IngressECIESValue;
2use std::fmt;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub struct ECIESError {
8 inner: Box<ECIESErrorImpl>,
9}
10
11impl ECIESError {
12 pub fn into_inner(self) -> ECIESErrorImpl {
14 *self.inner
15 }
16
17 pub const fn inner(&self) -> &ECIESErrorImpl {
19 &self.inner
20 }
21}
22
23impl fmt::Display for ECIESError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 fmt::Display::fmt(&*self.inner, f)
26 }
27}
28
29#[derive(Debug, Error)]
31pub enum ECIESErrorImpl {
32 #[error(transparent)]
34 IO(std::io::Error),
35 #[error("tag check failure in read_header")]
37 TagCheckDecryptFailed,
38 #[error("tag check failure in read_header")]
40 TagCheckHeaderFailed,
41 #[error("tag check failure in read_body")]
43 TagCheckBodyFailed,
44 #[error("invalid auth data")]
46 InvalidAuthData,
47 #[error("invalid ack data")]
49 InvalidAckData,
50 #[error("invalid body data")]
52 InvalidHeader,
53 #[error(transparent)]
55 Secp256k1(secp256k1::Error),
56 #[error(transparent)]
58 RLPDecoding(alloy_rlp::Error),
59 #[error(transparent)]
61 FromInt(std::num::TryFromIntError),
62 #[error("encrypted data is not large enough for all fields")]
64 EncryptedDataTooSmall,
65 #[error("initial header body is {body_size} but the max is {max_body_size}")]
67 InitialHeaderBodyTooLarge {
68 body_size: usize,
70 max_body_size: usize,
72 },
73 #[error("requested {idx} but array len is {len}")]
75 OutOfBounds {
76 idx: usize,
78 len: usize,
80 },
81 #[error("invalid handshake: expected {expected:?}, got {msg:?} instead")]
83 InvalidHandshake {
84 expected: IngressECIESValue,
86 msg: Option<IngressECIESValue>,
88 },
89 #[error("stream closed due to not being readable")]
96 UnreadableStream,
97 #[error("never received data from remote peer")]
99 StreamTimeout,
100}
101
102impl From<ECIESErrorImpl> for ECIESError {
103 fn from(source: ECIESErrorImpl) -> Self {
104 Self { inner: Box::new(source) }
105 }
106}
107
108impl From<std::io::Error> for ECIESError {
109 fn from(source: std::io::Error) -> Self {
110 ECIESErrorImpl::IO(source).into()
111 }
112}
113
114impl From<secp256k1::Error> for ECIESError {
115 fn from(source: secp256k1::Error) -> Self {
116 ECIESErrorImpl::Secp256k1(source).into()
117 }
118}
119
120impl From<alloy_rlp::Error> for ECIESError {
121 fn from(source: alloy_rlp::Error) -> Self {
122 ECIESErrorImpl::RLPDecoding(source).into()
123 }
124}
125
126impl From<std::num::TryFromIntError> for ECIESError {
127 fn from(source: std::num::TryFromIntError) -> Self {
128 ECIESErrorImpl::FromInt(source).into()
129 }
130}