Newer
Older
pub type CvfsResult<O> = Result<O, CvfsErrors>;
pub enum CvfsErrors {
KeyManagementError(multi_key_manager::errors::KeyManagementError),
/// An error occured inside ring, but this was the specific action
LeafDecryptionError,
/// Maybe the main Cvfs was dropped or the specific File deleted before?
FileHandlerNotFound(crate::metadata::FileTag),
/// Std::io::Error with a reason
ContextIO(&'static str, String),
/// A constant time error occured in the `ring` crate
Stefan Schindler
committed
/// A serialisation error occured
RmpEncode(String),
/// A deserialisation error occured
RmpDecode(String),
pub fn specify_io_error<O>(r: Result<O, std::io::Error>, reason: &'static str) -> CvfsResult<O> {
r.map_err(|e| CvfsErrors::ContextIO(reason, format!("{e:?}")))
}
pub fn specify_kme_error<O>(
r: Result<O, multi_key_manager::errors::KeyManagementError>,
reason: &'static str,
) -> CvfsResult<O> {
r.map_err(|e| CvfsErrors::ContextIO(reason, format!("{e:?}")))
}
impl From<std::io::Error> for CvfsErrors {
fn from(e: std::io::Error) -> Self {
CvfsErrors::GeneralIO(format!("{e:?}"))
}
}
impl From<multi_key_manager::errors::KeyManagementError> for CvfsErrors {
fn from(e: multi_key_manager::errors::KeyManagementError) -> Self {
CvfsErrors::KeyManagementError(e)
}
}
impl From<ring::error::Unspecified> for CvfsErrors {
fn from(_: ring::error::Unspecified) -> Self {
CvfsErrors::GeneralRingEncryptionError
impl<T> From<std::sync::PoisonError<T>> for CvfsErrors {
fn from(e: std::sync::PoisonError<T>) -> Self {
CvfsErrors::MutexUnlockError(format!("{e:?}"))
}
}
Stefan Schindler
committed
impl From<rmp_serde::encode::Error> for CvfsErrors {
fn from(e: rmp_serde::encode::Error) -> Self {
CvfsErrors::RmpEncode(format!("{e:?}"))
}
}
impl From<rmp_serde::decode::Error> for CvfsErrors {
fn from(e: rmp_serde::decode::Error) -> Self {
CvfsErrors::RmpDecode(format!("{e:?}"))
}
}