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
use ockam_core::Error;
#[derive(Clone, Copy, Debug)]
pub enum CredentialError {
None,
MismatchedAttributesAndClaims,
MismatchedAttributeClaimType,
InvalidCredentialAttribute,
InvalidCredentialSchema,
InvalidCredentialOffer,
InvalidPresentationManifest,
InvalidPresentationChallenge,
InvalidCredentialPresentation(u32),
InvalidPublicKey,
MismatchedPresentationAndManifests,
}
impl CredentialError {
pub const DOMAIN_CODE: u32 = 33_000;
#[cfg(feature = "std")]
pub const DOMAIN_NAME: &'static str = "OCKAM_CREDENTIAL";
pub(crate) const fn as_u32(self) -> u32 {
match self {
CredentialError::None => 0,
CredentialError::MismatchedAttributesAndClaims => 100,
CredentialError::MismatchedAttributeClaimType => 200,
CredentialError::InvalidCredentialAttribute => 300,
CredentialError::InvalidCredentialSchema => 400,
CredentialError::InvalidCredentialOffer => 500,
CredentialError::InvalidPresentationManifest => 600,
CredentialError::InvalidPresentationChallenge => 700,
CredentialError::InvalidCredentialPresentation(i) => 800u32 + i,
CredentialError::InvalidPublicKey => 900,
CredentialError::MismatchedPresentationAndManifests => 1000,
}
}
}
#[cfg(feature = "std")]
impl From<CredentialError> for Error {
fn from(v: CredentialError) -> Error {
let t = v.as_u32();
Error::new(
CredentialError::DOMAIN_CODE + t,
CredentialError::DOMAIN_NAME,
)
}
}
#[cfg(not(feature = "std"))]
impl From<CredentialError> for Error {
fn from(v: CredentialError) -> Error {
Error::new(CredentialError::DOMAIN_CODE + v.as_u32())
}
}