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
//! `CredentialError`: what is wrong with a credential or presentation as data.
/// Why a credential or presentation is not well-formed, or cannot be mapped to or from the
/// claims of a JWT.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum CredentialError {
/// The first `@context` is not the base context of the data model.
#[error("the first `@context` must be `{expected}`")]
InvalidContext {
/// The base context required.
expected: &'static str,
},
/// `type` lacks the type the data model requires.
#[error("`type` must include `{0}`")]
MissingType(&'static str),
/// `credentialSubject` is an empty list.
#[error("`credentialSubject` is empty")]
NoSubject,
/// The validity period ends before it starts.
#[error("`{until}` precedes `{from}`")]
InvalidValidity {
/// The property naming the start, `issuanceDate` or `validFrom`.
from: &'static str,
/// The property naming the end, `expirationDate` or `validUntil`.
until: &'static str,
},
/// A JWT carries one `sub`, so a credential with several subjects has no JWT form.
#[error("a JWT encodes one subject; the credential has {0}")]
MultipleSubjects(usize),
/// The JWT claims set lacks the claim the profile requires.
#[error("JWT claim `{0}` is missing")]
MissingClaim(&'static str),
/// A JWT claim has the wrong shape or an invalid value.
#[error("JWT claim `{claim}` is invalid: {reason}")]
InvalidClaim {
/// The claim.
claim: &'static str,
/// What is wrong with it.
reason: String,
},
/// A JWT claim and the property it duplicates disagree.
#[error("JWT claim `{claim}` does not match `{property}`")]
ClaimMismatch {
/// The claim.
claim: &'static str,
/// The property of the credential or presentation.
property: &'static str,
},
/// The enveloped credential or presentation is not in a form this crate reads.
#[error("enveloped {kind} has media type `{media_type}`, not `{expected}`")]
UnsupportedMediaType {
/// `credential` or `presentation`.
kind: &'static str,
/// The media type of the `data:` URL.
media_type: String,
/// The media type this crate reads.
expected: &'static str,
},
/// An enveloped credential or presentation does not hold a `data:` URL.
#[error("`{0}` is not a `data:` URL")]
NotDataUrl(String),
}