use snafu::Snafu;
use tibba_error::Error as BaseError;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("hmac sha256 error: {source}"))]
HmacSha256 { source: hmac::digest::InvalidLength },
#[snafu(display("key grip empty"))]
KeyGripEmpty,
#[snafu(display("argon2 hash error: {source}"))]
Argon2Hash {
source: argon2::password_hash::Error,
},
#[snafu(display("argon2 parse error: {source}"))]
Argon2Parse {
source: argon2::password_hash::Error,
},
}
impl From<Error> for BaseError {
fn from(val: Error) -> Self {
let err = match val {
Error::HmacSha256 { source } => BaseError::new(source).with_sub_category("hmac_sha256"),
Error::KeyGripEmpty => BaseError::new("key grip empty")
.with_sub_category("key_grip")
.with_status(500)
.with_exception(true),
Error::Argon2Hash { source } => BaseError::new(source)
.with_sub_category("argon2_hash")
.with_status(500)
.with_exception(true),
Error::Argon2Parse { source } => BaseError::new(source)
.with_sub_category("argon2_parse")
.with_status(500)
.with_exception(true),
};
err.with_category("crypto")
}
}
mod key_grip;
mod password;
pub use key_grip::*;
pub use password::*;