use aes_gcm::Error as AesError;
use core::fmt;
use dusk_bytes::{BadLength, Error as DuskBytesError, InvalidChar};
#[allow(missing_docs)]
#[derive(Debug, Clone)]
pub enum Error {
InvalidNoteType(u8),
MissingViewKey,
InvalidEncryption,
InvalidData,
BadLength(usize, usize),
InvalidChar(char, usize),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Phoenix-Core Error: {:?}", &self)
}
}
impl From<AesError> for Error {
fn from(aes_error: AesError) -> Self {
match aes_error {
AesError => Self::InvalidEncryption,
}
}
}
impl From<DuskBytesError> for Error {
fn from(err: DuskBytesError) -> Self {
match err {
DuskBytesError::InvalidData => Error::InvalidData,
DuskBytesError::BadLength { found, expected } => {
Error::BadLength(found, expected)
}
DuskBytesError::InvalidChar { ch, index } => {
Error::InvalidChar(ch, index)
}
}
}
}
impl From<Error> for DuskBytesError {
fn from(err: Error) -> Self {
match err {
Error::InvalidData => DuskBytesError::InvalidData,
Error::BadLength(found, expected) => {
DuskBytesError::BadLength { found, expected }
}
Error::InvalidChar(ch, index) => {
DuskBytesError::InvalidChar { ch, index }
}
_ => unreachable!(),
}
}
}
impl BadLength for Error {
fn bad_length(found: usize, expected: usize) -> Self {
Error::BadLength(found, expected)
}
}
impl InvalidChar for Error {
fn invalid_char(ch: char, index: usize) -> Self {
Error::InvalidChar(ch, index)
}
}