1use aes_gcm::Error as AesError;
8use core::fmt;
9use dusk_bytes::{BadLength, Error as DuskBytesError, InvalidChar};
10
11#[allow(missing_docs)]
13#[derive(Debug, Clone)]
14pub enum Error {
15 InvalidNoteType(u8),
17 MissingViewKey,
19 InvalidEncryption,
21 InvalidData,
23 BadLength(usize, usize),
25 InvalidChar(char, usize),
27}
28
29impl fmt::Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "Phoenix-Core Error: {:?}", &self)
32 }
33}
34
35impl From<AesError> for Error {
36 fn from(aes_error: AesError) -> Self {
37 match aes_error {
38 AesError => Self::InvalidEncryption,
39 }
40 }
41}
42
43impl From<DuskBytesError> for Error {
44 fn from(err: DuskBytesError) -> Self {
45 match err {
46 DuskBytesError::InvalidData => Error::InvalidData,
47 DuskBytesError::BadLength { found, expected } => {
48 Error::BadLength(found, expected)
49 }
50 DuskBytesError::InvalidChar { ch, index } => {
51 Error::InvalidChar(ch, index)
52 }
53 }
54 }
55}
56
57impl From<Error> for DuskBytesError {
58 fn from(err: Error) -> Self {
59 match err {
60 Error::InvalidData => DuskBytesError::InvalidData,
61 Error::BadLength(found, expected) => {
62 DuskBytesError::BadLength { found, expected }
63 }
64 Error::InvalidChar(ch, index) => {
65 DuskBytesError::InvalidChar { ch, index }
66 }
67 _ => unreachable!(),
68 }
69 }
70}
71
72impl BadLength for Error {
73 fn bad_length(found: usize, expected: usize) -> Self {
74 Error::BadLength(found, expected)
75 }
76}
77
78impl InvalidChar for Error {
79 fn invalid_char(ch: char, index: usize) -> Self {
80 Error::InvalidChar(ch, index)
81 }
82}