#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum ErrorCode {
Success = 0,
PasswordTooShort = 1,
PasswordTooLong = 2,
InvalidPasswordFormat = 10,
IncompatibleOption = 11,
NotEnoughSpace = 20,
NullPtr = 21,
InvalidKeyLen = 22,
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
pub enum Error {
#[cfg_attr(
feature = "thiserror",
error("Password was shorter than the minimal length (actual {actual}, min {min})")
)]
PasswordTooShort { min: usize, actual: usize },
#[cfg_attr(
feature = "thiserror",
error("Password was longer than the maximal length (actual {actual}, max {max})")
)]
PasswordTooLong { max: usize, actual: usize },
#[cfg_attr(
feature = "thiserror",
error("Input does not respect the storage format")
)]
InvalidPasswordFormat,
}
impl From<Error> for ErrorCode {
fn from(error: Error) -> Self {
match error {
Error::PasswordTooShort { min: _, actual: _ } => ErrorCode::PasswordTooShort,
Error::PasswordTooLong { max: _, actual: _ } => ErrorCode::PasswordTooLong,
Error::InvalidPasswordFormat => ErrorCode::InvalidPasswordFormat,
}
}
}
impl From<digest::InvalidLength> for ErrorCode {
fn from(_error: digest::InvalidLength) -> Self {
ErrorCode::InvalidPasswordFormat
}
}
impl From<hmac::digest::InvalidLength> for Error {
fn from(_error: hmac::digest::InvalidLength) -> Self {
Error::InvalidPasswordFormat
}
}