#[derive(Debug)]
pub enum Error {
PlatformFailure(crate::platform::Error),
NoStorageAccess(crate::platform::Error),
NoEntry,
BadEncoding(Vec<u8>),
TooLong(String, u32),
WrongCredentialPlatform,
}
pub type Result<T> = std::result::Result<T, Error>;
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::WrongCredentialPlatform => {
write!(f, "CredentialMapper value doesn't match this platform")
}
Error::PlatformFailure(err) => write!(f, "Platform secure storage failure: {}", err),
Error::NoStorageAccess(err) => {
write!(f, "Couldn't access platform secure storage: {}", err)
}
Error::NoEntry => write!(f, "No matching entry found in secure storage"),
Error::BadEncoding(_) => write!(f, "Password cannot be UTF-8 encoded"),
Error::TooLong(name, len) => write!(
f,
"Attribute '{}' is longer than platform limit of {} chars",
name, len
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::PlatformFailure(err) => Some(err),
Error::NoStorageAccess(err) => Some(err),
_ => None,
}
}
}