secured_enclave/
errors.rs

1use std::fmt::{Display, Formatter, Result};
2
3use secured_cipher::CipherError;
4
5#[derive(Debug)]
6pub enum EnclaveError {
7  Serialization(String),
8  Deserialization(String),
9  Generic(String),
10}
11
12impl Display for EnclaveError {
13  fn fmt(&self, f: &mut Formatter) -> Result {
14    match self {
15      EnclaveError::Serialization(message) => write!(f, "Unable to serialize safe > {}", message),
16      EnclaveError::Deserialization(message) => {
17        write!(f, "Unable to deserialize safe > {}", message)
18      }
19      EnclaveError::Generic(message) => write!(f, "Enclave error > {}", message),
20    }
21  }
22}
23
24impl From<CipherError> for EnclaveError {
25  fn from(error: CipherError) -> Self {
26    match error {
27      CipherError::AuthenticationFailed => {
28        EnclaveError::Deserialization("authentication failed".to_string())
29      }
30    }
31  }
32}
33
34impl From<String> for EnclaveError {
35  fn from(error: String) -> Self {
36    EnclaveError::Generic(error)
37  }
38}