1use snafu::Snafu;
16use tibba_error::Error as BaseError;
17
18#[derive(Debug, Snafu)]
19pub enum Error {
20 #[snafu(display("hmac sha256 error: {source}"))]
22 HmacSha256 { source: hmac::digest::InvalidLength },
23
24 #[snafu(display("key grip empty"))]
26 KeyGripEmpty,
27
28 #[snafu(display("argon2 hash error: {source}"))]
30 Argon2Hash {
31 source: argon2::password_hash::Error,
32 },
33
34 #[snafu(display("argon2 parse error: {source}"))]
36 Argon2Parse {
37 source: argon2::password_hash::Error,
38 },
39}
40
41impl From<Error> for BaseError {
42 fn from(val: Error) -> Self {
43 let err = match val {
44 Error::HmacSha256 { source } => BaseError::new(source).with_sub_category("hmac_sha256"),
45 Error::KeyGripEmpty => BaseError::new("key grip empty")
46 .with_sub_category("key_grip")
47 .with_status(500)
48 .with_exception(true),
49 Error::Argon2Hash { source } => BaseError::new(source)
50 .with_sub_category("argon2_hash")
51 .with_status(500)
52 .with_exception(true),
53 Error::Argon2Parse { source } => BaseError::new(source)
54 .with_sub_category("argon2_parse")
55 .with_status(500)
56 .with_exception(true),
57 };
58 err.with_category("crypto")
59 }
60}
61
62mod key_grip;
63mod password;
64
65pub use key_grip::*;
66pub use password::*;