use core::fmt;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum Reason {
Malformed,
Unsupported,
AuthFailed,
EmptyMandate,
BadTid,
MissingClause,
Expired,
AudienceMismatch,
NonCanonical,
BadType,
UnknownReservedKey,
}
#[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,
BadTid,
UnsupportedAlg(Alg),
AppNotMap,
ReservedKey,
Nan,
Serialization(String),
}
use crate::types::Alg;
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::BadTid => {
f.write_str("obsigil mint: `tid` must be a UUIDv7 (version 7, RFC 4122 variant)")
}
MintError::UnsupportedAlg(a) => {
write!(f, "obsigil mint: algorithm `{}` not enabled", a.code())
}
MintError::AppNotMap => {
f.write_str("obsigil mint: application value must serialize to a CBOR map")
}
MintError::ReservedKey => {
f.write_str("obsigil mint: application field used a reserved negative key")
}
MintError::Nan => f.write_str("obsigil mint: application field must not be NaN"),
MintError::Serialization(msg) => write!(f, "obsigil mint: serialization failed: {msg}"),
}
}
}
impl std::error::Error for MintError {}