1use std::fmt::{self, Display, Formatter};
2
3#[derive(Debug, PartialEq)]
4pub struct Error {
5 pub msg: &'static str,
7 pub typ: Type,
8}
9
10impl Display for Error {
11 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
12 write!(f, "{:?}: {}", self.typ, self.msg)
13 }
14}
15
16impl std::error::Error for Error {}
17
18#[derive(Debug, PartialEq)]
20pub enum Type {
21 Invalid,
23 Expired,
25 Early,
27 Certificate,
29 Key,
31 Connection,
33 Header,
35 Payload,
37 Signature,
39 Internal,
41}
42
43#[macro_export]
44macro_rules! err {
45 ( $typ:ident, $msg:expr ) => {{
46 Error {
47 msg: $msg,
48 typ: Type::$typ,
49 }
50 }};
51}