identity_kit/vc/error.rs
1//! `CredentialError`: what is wrong with a credential or presentation as data.
2
3/// Why a credential or presentation is not well-formed, or cannot be mapped to or from the
4/// claims of a JWT.
5#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
6#[non_exhaustive]
7pub enum CredentialError {
8 /// The first `@context` is not the base context of the data model.
9 #[error("the first `@context` must be `{expected}`")]
10 InvalidContext {
11 /// The base context required.
12 expected: &'static str,
13 },
14 /// `type` lacks the type the data model requires.
15 #[error("`type` must include `{0}`")]
16 MissingType(&'static str),
17 /// `credentialSubject` is an empty list.
18 #[error("`credentialSubject` is empty")]
19 NoSubject,
20 /// The validity period ends before it starts.
21 #[error("`{until}` precedes `{from}`")]
22 InvalidValidity {
23 /// The property naming the start, `issuanceDate` or `validFrom`.
24 from: &'static str,
25 /// The property naming the end, `expirationDate` or `validUntil`.
26 until: &'static str,
27 },
28 /// A JWT carries one `sub`, so a credential with several subjects has no JWT form.
29 #[error("a JWT encodes one subject; the credential has {0}")]
30 MultipleSubjects(usize),
31 /// The JWT claims set lacks the claim the profile requires.
32 #[error("JWT claim `{0}` is missing")]
33 MissingClaim(&'static str),
34 /// A JWT claim has the wrong shape or an invalid value.
35 #[error("JWT claim `{claim}` is invalid: {reason}")]
36 InvalidClaim {
37 /// The claim.
38 claim: &'static str,
39 /// What is wrong with it.
40 reason: String,
41 },
42 /// A JWT claim and the property it duplicates disagree.
43 #[error("JWT claim `{claim}` does not match `{property}`")]
44 ClaimMismatch {
45 /// The claim.
46 claim: &'static str,
47 /// The property of the credential or presentation.
48 property: &'static str,
49 },
50 /// The enveloped credential or presentation is not in a form this crate reads.
51 #[error("enveloped {kind} has media type `{media_type}`, not `{expected}`")]
52 UnsupportedMediaType {
53 /// `credential` or `presentation`.
54 kind: &'static str,
55 /// The media type of the `data:` URL.
56 media_type: String,
57 /// The media type this crate reads.
58 expected: &'static str,
59 },
60 /// An enveloped credential or presentation does not hold a `data:` URL.
61 #[error("`{0}` is not a `data:` URL")]
62 NotDataUrl(String),
63}