identity_credential/validator/sd_jwt/
error.rs1use std::borrow::Cow;
5use std::fmt::Display;
6
7use crate::validator::JwtValidationError;
8
9#[derive(Debug)]
11pub struct UnexpectedValue {
12 pub expected: Option<Cow<'static, str>>,
14 pub found: Box<str>,
16}
17
18impl Display for UnexpectedValue {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 if let Some(expected) = &self.expected {
21 write!(f, "expected \"{expected}\", but found \"{}\"", self.found)
22 } else {
23 write!(f, "unexpected \"{}\"", self.found)
24 }
25 }
26}
27
28impl std::error::Error for UnexpectedValue {}
29
30#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
32#[non_exhaustive]
33pub enum KeyBindingJwtError {
34 #[error("KB-JWT is invalid")]
36 JwtValidationError(
37 #[source]
38 #[from]
39 JwtValidationError,
40 ),
41
42 #[error("Deserialization error")]
44 DeserializationError(#[source] Box<dyn std::error::Error + Send + Sync>),
45
46 #[error(transparent)]
48 SdJwtError(#[from] sd_jwt::Error),
49
50 #[error("unsupported 'cnf' value")]
54 UnsupportedCnfMethod,
55
56 #[error("invalid KB-JWT 'sd_hash' value")]
58 InvalidDigest(#[source] UnexpectedValue),
59
60 #[error("invalid KB-JWT 'nonce' value")]
62 InvalidNonce(#[source] UnexpectedValue),
63
64 #[error("invalid KB-JWT 'aud' value")]
66 AudienceMismatch(#[source] UnexpectedValue),
67
68 #[error("invalid KB-JWT 'iat' value, {0}")]
70 IssuanceDate(String),
71
72 #[error("SD-JWT token requires a KB-JWT, but none was found")]
74 MissingKeyBindingJwt,
75
76 #[error("invalid KB-JWT header 'typ' value")]
78 InvalidHeaderTypValue(#[source] UnexpectedValue),
79}