chio_kernel_mobile/
errors.rs1#![forbid(unsafe_code)]
10
11use core::fmt;
12
13#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum ChioMobileError {
20 InvalidJson { message: String },
22 InvalidHex { message: String },
24 WeakEntropy { message: String },
26 InvalidCapability { message: String },
29 InvalidPassport { message: String },
31 AttestationUnavailable { message: String },
34 AttestationRejected { message: String },
36 KernelKeyMismatch { message: String },
41 SigningFailed { message: String },
43 EvaluationDenied { message: String },
46 Internal { message: String },
49}
50
51impl ChioMobileError {
52 pub fn message(&self) -> &str {
54 match self {
55 ChioMobileError::InvalidJson { message }
56 | ChioMobileError::InvalidHex { message }
57 | ChioMobileError::WeakEntropy { message }
58 | ChioMobileError::InvalidCapability { message }
59 | ChioMobileError::InvalidPassport { message }
60 | ChioMobileError::AttestationUnavailable { message }
61 | ChioMobileError::AttestationRejected { message }
62 | ChioMobileError::KernelKeyMismatch { message }
63 | ChioMobileError::SigningFailed { message }
64 | ChioMobileError::EvaluationDenied { message }
65 | ChioMobileError::Internal { message } => message.as_str(),
66 }
67 }
68}
69
70impl fmt::Display for ChioMobileError {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 let tag = match self {
73 ChioMobileError::InvalidJson { .. } => "invalid json",
74 ChioMobileError::InvalidHex { .. } => "invalid hex",
75 ChioMobileError::WeakEntropy { .. } => "weak entropy",
76 ChioMobileError::InvalidCapability { .. } => "invalid capability",
77 ChioMobileError::InvalidPassport { .. } => "invalid passport",
78 ChioMobileError::AttestationUnavailable { .. } => "attestation unavailable",
79 ChioMobileError::AttestationRejected { .. } => "attestation rejected",
80 ChioMobileError::KernelKeyMismatch { .. } => "kernel key mismatch",
81 ChioMobileError::SigningFailed { .. } => "signing failed",
82 ChioMobileError::EvaluationDenied { .. } => "evaluation denied",
83 ChioMobileError::Internal { .. } => "internal",
84 };
85 write!(f, "{tag}: {}", self.message())
86 }
87}
88
89impl std::error::Error for ChioMobileError {}