jwt_lab/
errors.rs

1use thiserror::Error;
2
3/// Errors that can occur during JWT operations
4#[derive(Debug, Error)]
5pub enum Error {
6    /// The JWT token is malformed (not 3 parts separated by dots)
7    #[error("malformed token")]
8    Malformed,
9    /// Base64URL decoding failed
10    #[error("base64url decode failed: {0}")]
11    Base64(String),
12    /// JSON parsing failed
13    #[error("json parse failed: {0}")]
14    Json(String),
15    /// The algorithm is unsupported or disabled via feature flags
16    #[error("unsupported or disabled algorithm: {0}")]
17    DisabledAlg(&'static str),
18    /// The JWT header is missing the required `kid` field
19    #[error("missing kid in header")]
20    MissingKid,
21    /// The `kid` from the JWT header was not found in the JWKS
22    #[error("kid not found in JWKS")]
23    KidNotFound,
24    /// Invalid key material provided
25    #[error("invalid key material: {0}")]
26    Key(String),
27    /// Signature verification failed
28    #[error("signature verification failed: {0}")]
29    Signature(String),
30    /// JWT claim validation failed
31    #[error("claim validation failed: {0}")]
32    Claims(String),
33    /// Internal error (should not occur in normal usage)
34    #[error("internal: {0}")]
35    Internal(String),
36}
37
38/// Result type alias for JWT operations
39pub type Result<T> = std::result::Result<T, Error>;