use std::fmt::Debug;
use crate::identity::{
claim_aggregation::w3c_vc::{did::InvalidDid, did_web::DidWebError},
ValidationError,
};
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum IcaValidationError {
#[error("COSE decoding error ({0})")]
CoseDecodeError(String),
#[error("unsupported COSE signature algorithm ({0})")]
UnsupportedSignatureType(String),
#[error("COSE signature did not specify a signature algorithm")]
SignatureTypeMissing,
#[error("unsupported COSE content type ({0})")]
UnsupportedContentType(String),
#[error("COSE signature did not specify a content type")]
ContentTypeMissing,
#[error("COSE signature did not include the credential payload")]
CredentialPayloadMissing,
#[error("JSON decoding error ({0})")]
JsonDecodeError(String),
#[error("unsupported issuer DID ({0})")]
UnsupportedIssuerDid(String),
#[error("DID could not be resolved ({0})")]
DidResolutionError(String),
#[error(
"the DID document could not be parsed or did not contain usable public key material ({0})"
)]
InvalidDidDocument(String),
#[error("the RFC 3161 time stamp was not valid for this credential")]
InvalidTimeStamp,
#[error("credential does not have a validFrom date")]
MissingValidFromDate,
#[error("credential's validFrom date is unacceptable ({0})")]
InvalidValidFromDate(String),
#[error("credential's validUntil date is unacceptable ({0})")]
InvalidValidUntilDate(String),
#[error("c2paAsset does not match signer_payload")]
SignerPayloadMismatch,
}
impl From<coset::CoseError> for ValidationError<IcaValidationError> {
fn from(err: coset::CoseError) -> Self {
Self::SignatureError(IcaValidationError::CoseDecodeError(err.to_string()))
}
}
impl From<serde_json::Error> for ValidationError<IcaValidationError> {
fn from(err: serde_json::Error) -> Self {
Self::SignatureError(IcaValidationError::JsonDecodeError(err.to_string()))
}
}
impl From<InvalidDid> for ValidationError<IcaValidationError> {
fn from(err: InvalidDid) -> Self {
Self::SignatureError(IcaValidationError::UnsupportedIssuerDid(err.to_string()))
}
}
impl From<DidWebError> for ValidationError<IcaValidationError> {
fn from(err: DidWebError) -> Self {
match err {
DidWebError::Client(_) => Self::InternalError(err.to_string()),
_ => Self::SignatureError(IcaValidationError::DidResolutionError(err.to_string())),
}
}
}