Skip to main content

age_otp/
error.rs

1use thiserror::Error;
2#[derive(Debug, Error)]
3pub enum Error {
4    #[error("Key error: {0}")]
5    Key(#[from] KeyError),
6    #[error("Generation error: {0}")]
7    Generation(#[from] GenerationError),
8    #[error("Verification error: {0}")]
9    Verification(#[from] VerificationError),
10}
11pub type Result<T> = std::result::Result<T, Error>;
12#[derive(Debug, Error)]
13pub enum KeyError {
14    #[error("Key is empty")]
15    Empty,
16    #[error("Invalid prefix: expected 'age1', got '{0}'")]
17    InvalidPrefix(String),
18    #[error("Bech32 decode failed: {0}")]
19    Bech32Decode(String),
20    #[error("Invalid decoded length: expected 32 bytes, got {0}")]
21    InvalidDecodedLength(usize),
22}
23#[derive(Debug, Error)]
24pub enum GenerationError {
25    #[error("HMAC failed")]
26    HmacFailed,
27    #[error("Truncation failed: {0}")]
28    TruncateFailed(String),
29    #[error("Invalid length: {0}")]
30    InvalidLength(String),
31    #[error("Overflow computing born time")]
32    Overflow,
33}
34#[derive(Debug, Error)]
35pub enum VerificationError {
36    #[error("Code mismatch")]
37    Mismatch,
38    #[error("Expired at {0}, current {1}")]
39    Expired(u64, u64),
40    #[error("Invalid format: {0}")]
41    InvalidFormat(String),
42}