jwt_compact_preview/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum ParseError {
6 #[error("Invalid token structure")]
11 InvalidTokenStructure,
12
13 #[error("base64 decoding error: {}", _0)]
15 Base64(#[from] base64::DecodeError),
16
17 #[error("Malformed token header: {}", _0)]
19 MalformedHeader(#[source] serde_json::Error),
20
21 #[error("Unsupported content type: {}", _0)]
27 UnsupportedContentType(String),
28}
29
30#[derive(Debug, Error)]
32pub enum ValidationError {
33 #[error("Token algorithm differs from the expected one")]
35 AlgorithmMismatch,
36
37 #[error("Malformed token signature: {}", _0)]
39 MalformedSignature(#[source] anyhow::Error),
40
41 #[error("Signature has failed verification")]
43 InvalidSignature,
44
45 #[error("Cannot deserialize claims: {}", _0)]
47 MalformedClaims(#[source] serde_json::Error),
48
49 #[error("Cannot deserialize claims: {}", _0)]
51 MalformedCborClaims(#[source] serde_cbor::error::Error),
52
53 #[error("Claim requested during validation is not present in the token")]
55 NoClaim,
56
57 #[error("Token has expired")]
59 Expired,
60
61 #[error("Token is not yet ready")]
63 NotMature,
64}
65
66#[derive(Debug, Error)]
68pub enum CreationError {
69 #[error("Cannot serialize header: {}", _0)]
71 Header(#[source] serde_json::Error),
72
73 #[error("Cannot serialize claims: {}", _0)]
75 Claims(#[source] serde_json::Error),
76
77 #[error("Cannot serialize claims into CBOR: {}", _0)]
79 CborClaims(#[source] serde_cbor::error::Error),
80}