jwks_client_update/
error.rs1use std::fmt::{Display, Formatter};
2use std::fmt;
3
4#[derive(Debug, PartialEq)]
5pub struct Error {
6 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#[derive(Debug, PartialEq)]
22pub enum Type {
23 Invalid,
26 Expired,
28 Early,
30 Certificate,
32 Key,
34 Connection,
36 Header,
38 Payload,
40 Signature,
42 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 {}