identity_credential/domain_linkage/
error.rs1use std::error::Error;
5
6pub(crate) type DomainLinkageValidationResult = Result<(), DomainLinkageValidationError>;
7
8#[derive(Debug, thiserror::Error)]
10pub struct DomainLinkageValidationError {
11 pub cause: DomainLinkageValidationErrorCause,
13 pub source: Option<Box<dyn Error + Send + Sync + 'static>>,
15}
16
17#[derive(Debug, thiserror::Error)]
19pub struct DomainLinkageValidationErrorList {
20 pub errors: Vec<DomainLinkageValidationError>,
22}
23
24impl DomainLinkageValidationErrorList {
26 pub fn new(errors: Vec<DomainLinkageValidationError>) -> Self {
28 Self { errors }
29 }
30}
31
32impl std::fmt::Display for DomainLinkageValidationErrorList {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{:?}", self.errors)
36 }
37}
38
39impl std::fmt::Display for DomainLinkageValidationError {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(f, "{}", self.cause)
42 }
43}
44
45impl From<DomainLinkageValidationError> for &str {
46 fn from(value: DomainLinkageValidationError) -> Self {
47 value.cause.into()
48 }
49}
50
51#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
53#[non_exhaustive]
54pub enum DomainLinkageValidationErrorCause {
55 #[error("invalid credential")]
57 CredentialValidationError,
58 #[error("invalid JWT")]
60 InvalidJwt,
61 #[error("the expiration date is missing")]
63 MissingExpirationDate,
64 #[error("id property is not allowed")]
66 ImpermissibleIdProperty,
67 #[error("issuer DID does not match the subject")]
69 IssuerSubjectMismatch,
70 #[error("subject id is invalid")]
72 InvalidSubjectId,
73 #[error("credential contains multiple subjects")]
75 MultipleCredentialSubjects,
76 #[error("invalid issuer DID")]
78 InvalidIssuer,
79 #[error("subject id property is missing")]
81 MissingSubjectId,
82 #[error("credential type is invalid")]
84 InvalidTypeProperty,
85 #[error("the subject's origin does not match the provided domain origin")]
87 OriginMismatch,
88 #[error("the subject's origin property is either invalid or missing")]
90 InvalidSubjectOrigin,
91 #[error("invalid semantic structure of the domain linkage configuration")]
93 InvalidStructure,
94 #[error("one or more validations failed")]
96 List,
97}