use ockam_core::Error;
#[derive(Clone, Copy, Debug)]
pub enum CredentialError {
MismatchedAttributesAndClaims,
MismatchedAttributeClaimType,
InvalidCredentialAttribute,
InvalidCredentialSchema,
InvalidCredentialOffer,
InvalidPresentationManifest,
InvalidPresentationChallenge,
InvalidCredentialPresentation(u32),
InvalidPublicKey,
MismatchedPresentationAndManifests,
}
impl CredentialError {
pub const DOMAIN_CODE: u32 = 33_000;
#[cfg(feature = "alloc")]
pub const DOMAIN_NAME: &'static str = "OCKAM_CREDENTIAL";
pub(crate) const fn as_u32(self) -> u32 {
match self {
CredentialError::MismatchedAttributesAndClaims => 100,
CredentialError::MismatchedAttributeClaimType => 200,
CredentialError::InvalidCredentialAttribute => 300,
CredentialError::InvalidCredentialSchema => 400,
CredentialError::InvalidCredentialOffer => 500,
CredentialError::InvalidPresentationManifest => 600,
CredentialError::InvalidPresentationChallenge => 700,
CredentialError::InvalidCredentialPresentation(i) => 800u32 + i,
CredentialError::InvalidPublicKey => 900,
CredentialError::MismatchedPresentationAndManifests => 1000,
}
}
}
#[cfg(feature = "alloc")]
impl From<CredentialError> for Error {
fn from(v: CredentialError) -> Error {
let t = v.as_u32();
Error::new(
CredentialError::DOMAIN_CODE + t,
CredentialError::DOMAIN_NAME,
)
}
}
#[cfg(not(feature = "alloc"))]
impl From<CredentialError> for Error {
fn from(v: CredentialError) -> Error {
Error::new(CredentialError::DOMAIN_CODE + v.as_u32())
}
}