use core::fmt;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum Reason {
Malformed,
Unsupported,
AuthFailed,
EmptyMandate,
BadTid,
MissingClause,
Expired,
AudienceMismatch,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Error(Reason);
impl Error {
pub(crate) fn new(reason: Reason) -> Self {
Error(reason)
}
pub fn reason(&self) -> Reason {
self.0
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("obsigil: token rejected")
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Error").field(&self.0).finish()
}
}
impl std::error::Error for Error {}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum KeyError {
IsManifestKey,
AllZero,
}
impl fmt::Display for KeyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
KeyError::IsManifestKey => {
f.write_str("mandate key must not be the public manifest key")
}
KeyError::AllZero => f.write_str("mandate key must not be all zero"),
}
}
}
impl std::error::Error for KeyError {}
#[derive(Debug)]
#[non_exhaustive]
pub enum MintError {
Missing(&'static str),
EmptyAudience,
UnsupportedAlg(Alg),
UnsupportedFormat(Format),
Serialization(String),
}
use crate::types::{Alg, Format};
impl fmt::Display for MintError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MintError::Missing(field) => {
write!(f, "obsigil mint: missing required field `{field}`")
}
MintError::EmptyAudience => {
f.write_str("obsigil mint: `aud` must be a non-empty array")
}
MintError::UnsupportedAlg(a) => {
write!(f, "obsigil mint: algorithm `{}` not enabled", a.code())
}
MintError::UnsupportedFormat(fmt) => {
write!(
f,
"obsigil mint: serialization `{}` not enabled",
fmt.tag() as char
)
}
MintError::Serialization(msg) => write!(f, "obsigil mint: serialization failed: {msg}"),
}
}
}
impl std::error::Error for MintError {}