use alloc::string::String;
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Json(String),
Jcs(String),
Cose(&'static str),
Signature,
Header(&'static str),
Validation(&'static str),
NonCanonicalPayload,
Receipt(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Json(message) => write!(formatter, "JSON error: {message}"),
Self::Jcs(message) => write!(formatter, "JCS error: {message}"),
Self::Cose(message) => write!(formatter, "COSE error: {message}"),
Self::Signature => formatter.write_str("signature error"),
Self::Header(message) => write!(formatter, "protected-header error: {message}"),
Self::Validation(message) => write!(formatter, "payload validation error: {message}"),
Self::NonCanonicalPayload => formatter.write_str("payload is not JCS canonical"),
Self::Receipt(message) => write!(formatter, "attached receipt error: {message}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;