#![forbid(unsafe_code)]
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChioMobileError {
InvalidJson { message: String },
InvalidHex { message: String },
WeakEntropy { message: String },
InvalidCapability { message: String },
InvalidPassport { message: String },
AttestationUnavailable { message: String },
AttestationRejected { message: String },
KernelKeyMismatch { message: String },
SigningFailed { message: String },
EvaluationDenied { message: String },
Internal { message: String },
}
impl ChioMobileError {
pub fn message(&self) -> &str {
match self {
ChioMobileError::InvalidJson { message }
| ChioMobileError::InvalidHex { message }
| ChioMobileError::WeakEntropy { message }
| ChioMobileError::InvalidCapability { message }
| ChioMobileError::InvalidPassport { message }
| ChioMobileError::AttestationUnavailable { message }
| ChioMobileError::AttestationRejected { message }
| ChioMobileError::KernelKeyMismatch { message }
| ChioMobileError::SigningFailed { message }
| ChioMobileError::EvaluationDenied { message }
| ChioMobileError::Internal { message } => message.as_str(),
}
}
}
impl fmt::Display for ChioMobileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let tag = match self {
ChioMobileError::InvalidJson { .. } => "invalid json",
ChioMobileError::InvalidHex { .. } => "invalid hex",
ChioMobileError::WeakEntropy { .. } => "weak entropy",
ChioMobileError::InvalidCapability { .. } => "invalid capability",
ChioMobileError::InvalidPassport { .. } => "invalid passport",
ChioMobileError::AttestationUnavailable { .. } => "attestation unavailable",
ChioMobileError::AttestationRejected { .. } => "attestation rejected",
ChioMobileError::KernelKeyMismatch { .. } => "kernel key mismatch",
ChioMobileError::SigningFailed { .. } => "signing failed",
ChioMobileError::EvaluationDenied { .. } => "evaluation denied",
ChioMobileError::Internal { .. } => "internal",
};
write!(f, "{tag}: {}", self.message())
}
}
impl std::error::Error for ChioMobileError {}