1#[derive(Debug, thiserror::Error)]
3#[non_exhaustive]
4pub enum KeyError {
5 #[error("invalid algorithm for key type")]
6 InvalidAlgorithm,
7
8 #[error("invalid algorithm for {0} curve")]
9 InvalidAlgorithmForCurve(&'static str),
10
11 #[error("invalid coordinate length for {0}")]
12 InvalidCoordinateLength(&'static str),
13
14 #[error("invalid curve for {0} key")]
15 InvalidCurve(&'static str),
16
17 #[error("missing private key")]
18 MissingPrivateKey,
19
20 #[error("oct key secret must be at least {0} bytes")]
21 SecretTooShort(usize),
22
23 #[error("OCT key cannot be converted to public key")]
24 NoPublicKey,
25
26 #[error("key does not support verification")]
27 VerifyUnsupported,
28
29 #[error("key does not support signing")]
30 SignUnsupported,
31
32 #[error("cannot find signing key")]
33 NoSigningKey,
34
35 #[error("cannot find key with kid {0}")]
36 KeyNotFound(String),
37
38 #[error("missing kid in JWT header")]
39 MissingKid,
40
41 #[error("missing x() point in EC key")]
42 MissingEcX,
43
44 #[error("missing y() point in EC key")]
45 MissingEcY,
46}
47
48#[derive(Debug, thiserror::Error)]
50#[non_exhaustive]
51pub enum Error {
52 #[error(transparent)]
53 Key(#[from] KeyError),
54
55 #[error("no publish or subscribe allowed; token is useless")]
56 UselessToken,
57
58 #[error("path `{0}` does not overlap the token root")]
59 RootMismatch(String),
60
61 #[error("token grants no access to path `{0}`")]
62 NoAccess(String),
63
64 #[error("no publish or subscribe allowed; key scope is useless")]
65 UselessScope,
66
67 #[error("token capabilities exceed the key scope")]
68 ScopeExceeded,
69
70 #[error("invalid algorithm: {0}")]
71 InvalidAlgorithm(String),
72
73 #[error("token has expired")]
74 TokenExpired,
75
76 #[error(transparent)]
77 Json(#[from] serde_json::Error),
78
79 #[error(transparent)]
80 Io(#[from] std::io::Error),
81
82 #[error(transparent)]
83 Base64(#[from] base64::DecodeError),
84
85 #[error(transparent)]
86 Utf8(#[from] std::string::FromUtf8Error),
87
88 #[error(transparent)]
89 Jwt(#[from] jsonwebtoken::errors::Error),
90
91 #[error(transparent)]
92 Pkcs8(#[from] p256::elliptic_curve::pkcs8::Error),
93
94 #[error(transparent)]
95 EllipticCurve(#[from] p256::elliptic_curve::Error),
96
97 #[error(transparent)]
98 Rsa(#[from] rsa::Error),
99
100 #[error(transparent)]
101 RsaPkcs1(#[from] rsa::pkcs1::Error),
102
103 #[error(transparent)]
104 AwsUnspecified(#[from] aws_lc_rs::error::Unspecified),
105
106 #[error(transparent)]
107 AwsKeyRejected(#[from] aws_lc_rs::error::KeyRejected),
108
109 #[cfg(feature = "jwks-loader")]
110 #[error(transparent)]
111 Reqwest(#[from] reqwest::Error),
112
113 #[error("{0}")]
114 Other(String),
115}
116
117pub type Result<T> = std::result::Result<T, Error>;