1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ParseError {
#[error("Invalid token structure")]
InvalidTokenStructure,
#[error("base64 decoding error: {}", _0)]
Base64(#[from] base64::DecodeError),
#[error("Malformed token header: {}", _0)]
MalformedHeader(#[source] serde_json::Error),
#[error("Unsupported content type: {}", _0)]
UnsupportedContentType(String),
}
#[derive(Debug, Error)]
pub enum ValidationError {
#[error("Token algorithm differs from the expected one")]
AlgorithmMismatch,
#[error("Malformed token signature: {}", _0)]
MalformedSignature(#[source] anyhow::Error),
#[error("Signature has failed verification")]
InvalidSignature,
#[error("Cannot deserialize claims: {}", _0)]
MalformedClaims(#[source] serde_json::Error),
#[error("Cannot deserialize claims: {}", _0)]
MalformedCborClaims(#[source] serde_cbor::error::Error),
#[error("Claim requested during validation is not present in the token")]
NoClaim,
#[error("Token has expired")]
Expired,
#[error("Token is not yet ready")]
NotMature,
#[error("Invalid public key")]
InvalidPublicKey,
}
#[derive(Debug, Error)]
pub enum CreationError {
#[error("Cannot serialize header: {}", _0)]
Header(#[source] serde_json::Error),
#[error("Cannot serialize claims: {}", _0)]
Claims(#[source] serde_json::Error),
#[error("Cannot serialize claims into CBOR: {}", _0)]
CborClaims(#[source] serde_cbor::error::Error),
}