use std::fmt::{self, Display, Formatter};
#[derive(Debug, PartialEq)]
pub struct Error {
pub msg: &'static str,
pub typ: Type,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}: {}", self.typ, self.msg)
}
}
impl std::error::Error for Error {}
#[derive(Debug, PartialEq)]
pub enum Type {
Invalid,
Expired,
Early,
Certificate,
Key,
Connection,
Header,
Payload,
Signature,
Internal,
}
#[macro_export]
macro_rules! err {
( $typ:ident, $msg:expr ) => {{
Error {
msg: $msg,
typ: Type::$typ,
}
}};
}