amebazii/
error.rs

1use hex::FromHexError;
2use openssl::error::ErrorStack;
3use std::{io};
4use std::string::FromUtf8Error;
5
6#[derive(Debug)]
7pub enum Error {
8    UnknownImageType(u8),
9    UnknownSectionType(String),
10    InvalidEnumValue(String),
11    IOError(io::Error),
12    OpenSSLError(ErrorStack),
13    Utf8Error(FromUtf8Error),
14    UnsupportedHashAlgo(u8),
15    NotImplemented(String),
16    InvalidState(String),
17    SerdeJSONError(serde_json::Error),
18    UnknownNVDMType(String),
19
20    // REVISIT: must be reworked
21    // individual parsing errors
22    MalformedKeyblock(String),
23    MalformedImageHeader(String),
24    MalfromedPartTab(String),
25}
26
27impl From<io::Error> for Error {
28    fn from(err: io::Error) -> Self {
29        Error::IOError(err)
30    }
31}
32
33impl From<ErrorStack> for Error {
34    fn from(err: ErrorStack) -> Self {
35        Error::OpenSSLError(err)
36    }
37}
38
39impl From<serde_json::Error> for Error {
40    fn from(err: serde_json::Error) -> Self {
41        Error::SerdeJSONError(err)
42    }
43}
44
45impl From<FromHexError> for Error {
46    fn from(err: FromHexError) -> Self {
47        Error::InvalidState(err.to_string())
48    }
49}
50
51impl From<FromUtf8Error> for Error {
52    fn from(value: FromUtf8Error) -> Self {
53        Error::Utf8Error(value)
54    }
55}
56
57impl std::fmt::Display for Error {
58    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59        write!(f, "{:?}", self)
60    }
61}