1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use std::collections::BTreeMap;
use std::fmt::Display;
#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
#[non_exhaustive]
pub enum ValidationError {
#[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: Box<dyn std::error::Error + Send + Sync + 'static>,
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] identity_credential::Error),
#[error("the presentation's structure is not semantically correct")]
PresentationStructure(#[source] identity_credential::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] identity_credential::Error),
#[error("invalid service")]
InvalidService(#[source] identity_did::Error),
#[error("credential has been revoked")]
Revoked,
}
#[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<ValidationError>,
}
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 {}
#[derive(Debug)]
pub struct CompoundPresentationValidationError {
pub credential_errors: BTreeMap<usize, CompoundCredentialValidationError>,
pub presentation_validation_errors: Vec<ValidationError>,
}
impl Display for CompoundPresentationValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let credential_error_formatter = |(position, reason): (&usize, &CompoundCredentialValidationError)| -> String {
format!("credential num. {} errors: {}", position, reason.to_string().as_str())
};
let error_string_iter = self
.presentation_validation_errors
.iter()
.map(|error| error.to_string())
.chain(self.credential_errors.iter().map(credential_error_formatter));
let detailed_information: String = itertools::intersperse(error_string_iter, "; ".to_string()).collect();
write!(f, "[{}]", detailed_information)
}
}
impl std::error::Error for CompoundPresentationValidationError {}