jwks_client_update/
error.rs

1use std::fmt::{Display, Formatter};
2use std::fmt;
3
4#[derive(Debug, PartialEq)]
5pub struct Error {
6    /// Debug message associated with error
7    pub msg: &'static str,
8    pub typ: Type,
9}
10
11impl Display for Error {
12    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
13        write!(f, "{:?}: {}", self.typ, self.msg)
14    }
15}
16
17impl std::error::Error for Error {
18}
19
20/// Type of error encountered
21#[derive(Debug, PartialEq)]
22pub enum Type {
23    /// Token is invalid
24    /// For example, the format of the token is not "HEADER.PAYLOAD.SIGNATURE"
25    Invalid,
26    /// Token has expired
27    Expired,
28    /// Not Before (nbf) is set and it's too early to use the token
29    Early,
30    /// Problem with certificate
31    Certificate,
32    /// Problem with key
33    Key,
34    /// Could not download key set
35    Connection,
36    /// Problem with JWT header
37    Header,
38    /// Problem with JWT payload
39    Payload,
40    /// Problem with JWT signature
41    Signature,
42    /// Internal problem (Signals a serious bug or fatal error)
43    Internal,
44}
45
46pub(crate) fn err(msg: &'static str, typ: Type) -> Error {
47    Error { msg, typ }
48}
49
50pub(crate) fn err_inv(msg: &'static str) -> Error {
51    err(msg, Type::Invalid)
52}
53
54pub(crate) fn err_exp(msg: &'static str) -> Error {
55    err(msg, Type::Expired)
56}
57
58pub(crate) fn err_nbf(msg: &'static str) -> Error {
59    err(msg, Type::Early)
60}
61
62pub(crate) fn err_cer(msg: &'static str) -> Error {
63    err(msg, Type::Certificate)
64}
65
66pub(crate) fn err_key(msg: &'static str) -> Error {
67    err(msg, Type::Key)
68}
69
70pub(crate) fn err_con(msg: &'static str) -> Error {
71    err(msg, Type::Connection)
72}
73
74pub(crate) fn err_hea(msg: &'static str) -> Error {
75    err(msg, Type::Header)
76}
77
78pub(crate) fn err_pay(msg: &'static str) -> Error {
79    err(msg, Type::Payload)
80}
81
82pub(crate) fn err_sig(msg: &'static str) -> Error {
83    err(msg, Type::Signature)
84}
85
86pub(crate) fn err_int(msg: &'static str) -> Error {
87    err(msg, Type::Internal)
88}
89
90#[cfg(test)]
91mod tests {}