use alloc::string::String;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum ErrorCode {
GeneralError = -1,
InvalidParameter = -2,
BufferTooSmall = -3,
NoSession = -100,
SessionExpired = -101,
AttestationFailed = -102,
NetworkError = -200,
Timeout = -203,
NotFound = -300,
ValidationFailed = -301,
}
impl ErrorCode {
pub const fn from_i32(value: i32) -> Option<ErrorCode> {
match value {
-1 => Some(ErrorCode::GeneralError),
-2 => Some(ErrorCode::InvalidParameter),
-3 => Some(ErrorCode::BufferTooSmall),
-100 => Some(ErrorCode::NoSession),
-101 => Some(ErrorCode::SessionExpired),
-102 => Some(ErrorCode::AttestationFailed),
-200 => Some(ErrorCode::NetworkError),
-203 => Some(ErrorCode::Timeout),
-300 => Some(ErrorCode::NotFound),
-301 => Some(ErrorCode::ValidationFailed),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoreError {
Parse(String),
Decode(String),
Validation(String),
}
impl core::fmt::Display for CoreError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
CoreError::Parse(m) => write!(f, "parse error: {m}"),
CoreError::Decode(m) => write!(f, "decode error: {m}"),
CoreError::Validation(m) => write!(f, "validation error: {m}"),
}
}
}