use std::fmt::Display;
use itertools;
#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
#[non_exhaustive]
pub enum JwtValidationError {
#[error("could not decode jws")]
JwsDecodingError(#[source] identity_verification::jose::error::Error),
#[error("could not verify jws")]
PresentationJwsError(#[source] identity_document::error::Error),
#[error("could not find verification material")]
MethodDataLookupError {
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
message: &'static str,
signer_ctx: SignerContext,
},
#[error("identifier mismatch")]
IdentifierMismatch {
signer_ctx: SignerContext,
},
#[error("the expiration date is in the past or earlier than required")]
ExpirationDate,
#[error("issuance date is in the future or later than required")]
IssuanceDate,
#[error("could not verify the {signer_ctx}'s signature")]
#[non_exhaustive]
Signature {
source: identity_verification::jose::error::Error,
signer_ctx: SignerContext,
},
#[error("{signer_ctx} URL is not a valid DID")]
#[non_exhaustive]
SignerUrl {
source: Box<dyn std::error::Error + Send + Sync + 'static>,
signer_ctx: SignerContext,
},
#[error("the {0}'s id does not match the provided DID Document(s)")]
#[non_exhaustive]
DocumentMismatch(SignerContext),
#[error("the credential's structure is not semantically correct")]
CredentialStructure(#[source] crate::Error),
#[error("the presentation's structure is not semantically correct")]
PresentationStructure(#[source] crate::Error),
#[error("expected holder = subject of the credential")]
#[non_exhaustive]
SubjectHolderRelationship,
#[error("the presentation has an empty holder property")]
MissingPresentationHolder,
#[error("invalid credential status")]
InvalidStatus(#[source] crate::Error),
#[error("service lookup error")]
#[non_exhaustive]
ServiceLookupError,
#[error("credential has been revoked")]
Revoked,
#[error("credential has been suspended")]
Suspended,
#[cfg(feature = "jpt-bbs-plus")]
#[error("timeframe interval not valid")]
OutsideTimeframe,
#[cfg(feature = "jpt-bbs-plus")]
#[error("could not decode jwp")]
JwpDecodingError(#[source] jsonprooftoken::errors::CustomError),
#[cfg(feature = "jpt-bbs-plus")]
#[error("could not verify jwp")]
JwpProofVerificationError(#[source] jsonprooftoken::errors::CustomError),
}
#[derive(Debug)]
#[non_exhaustive]
pub enum SignerContext {
Issuer,
Holder,
}
impl Display for SignerContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let context = match *self {
Self::Issuer => "issuer",
Self::Holder => "holder",
};
write!(f, "{context}")
}
}
#[derive(Debug)]
pub struct CompoundCredentialValidationError {
pub validation_errors: Vec<JwtValidationError>,
}
impl Display for CompoundCredentialValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let detailed_information: String = itertools::intersperse(
self.validation_errors.iter().map(|err| err.to_string()),
"; ".to_string(),
)
.collect();
write!(f, "[{detailed_information}]")
}
}
impl std::error::Error for CompoundCredentialValidationError {}