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