Skip to main content

idprova_core/
error.rs

1use thiserror::Error;
2
3/// Result type alias for IDProva operations.
4pub type Result<T> = std::result::Result<T, IdprovaError>;
5
6/// Errors that can occur in IDProva operations.
7#[derive(Debug, Error)]
8pub enum IdprovaError {
9    // Crypto errors
10    #[error("key generation failed: {0}")]
11    KeyGeneration(String),
12
13    #[error("signing failed: {0}")]
14    Signing(String),
15
16    #[error("signature verification failed: {0}")]
17    VerificationFailed(String),
18
19    #[error("invalid key material: {0}")]
20    InvalidKey(String),
21
22    // AID errors
23    #[error("invalid AID identifier: {0}")]
24    InvalidAid(String),
25
26    #[error("AID document validation failed: {0}")]
27    AidValidation(String),
28
29    #[error("AID not found: {0}")]
30    AidNotFound(String),
31
32    // DAT errors
33    #[error("invalid DAT: {0}")]
34    InvalidDat(String),
35
36    #[error("DAT expired")]
37    DatExpired,
38
39    #[error("DAT not yet valid")]
40    DatNotYetValid,
41
42    #[error("DAT revoked: {0}")]
43    DatRevoked(String),
44
45    #[error("scope not permitted: {0}")]
46    ScopeNotPermitted(String),
47
48    #[error("constraint violated: {0}")]
49    ConstraintViolated(String),
50
51    #[error("delegation chain invalid: {0}")]
52    InvalidDelegationChain(String),
53
54    // Receipt errors
55    #[error("receipt chain integrity violation at sequence {0}")]
56    ReceiptChainBroken(u64),
57
58    #[error("invalid receipt: {0}")]
59    InvalidReceipt(String),
60
61    // Trust errors
62    #[error("trust verification failed for level {0}: {1}")]
63    TrustVerification(String, String),
64
65    // Serialization
66    #[error("serialization error: {0}")]
67    Serialization(#[from] serde_json::Error),
68
69    // Base64
70    #[error("base64 decode error: {0}")]
71    Base64(#[from] base64::DecodeError),
72
73    // Generic
74    #[error("{0}")]
75    Other(String),
76}