Skip to main content

typesec_integrations/did/
error.rs

1//! DID integration error type.
2
3/// DID integration errors.
4#[derive(Debug, thiserror::Error)]
5pub enum DidError {
6    /// DID syntax is invalid.
7    #[error("invalid DID: {0}")]
8    InvalidDid(String),
9    /// DID could not be resolved.
10    #[error("unresolved DID: {0}")]
11    Unresolved(String),
12    /// No private key is available for a local DID.
13    #[error("missing private key for DID: {0}")]
14    MissingPrivateKey(String),
15    /// DID document did not contain an authentication key.
16    #[error("DID document has no authentication key")]
17    MissingAuthentication,
18    /// DID document did not contain a key agreement key.
19    #[error("DID document has no key agreement key")]
20    MissingKeyAgreement,
21    /// Referenced verification method is absent.
22    #[error("missing verification method: {0}")]
23    MissingVerificationMethod(String),
24    /// Referenced key version is absent.
25    #[error("missing key version {version} for DID {did}")]
26    MissingKeyVersion {
27        /// DID whose key version was requested.
28        did: String,
29        /// Missing key version.
30        version: u64,
31    },
32    /// Active key versions cannot be retired.
33    #[error("cannot retire active key version {version} for DID {did}")]
34    CannotRetireActiveKey {
35        /// DID whose active key would have been retired.
36        did: String,
37        /// Active key version.
38        version: u64,
39    },
40    /// Referenced key has been retired.
41    #[error("retired verification method: {0}")]
42    RetiredKey(String),
43    /// Envelope signature did not verify.
44    #[error("invalid DID envelope signature")]
45    InvalidSignature,
46    /// Envelope recipient does not match this gateway.
47    #[error("DID envelope was not addressed to {0}")]
48    WrongRecipient(String),
49    /// Envelope has expired.
50    #[error("DID envelope has expired")]
51    Expired,
52    /// Envelope is dated too far in the future (beyond the clock-skew tolerance).
53    #[error("DID envelope is not yet valid (created {created}, now {now})")]
54    NotYetValid {
55        /// Envelope `created_time` (unix seconds).
56        created: u64,
57        /// Current time (unix seconds).
58        now: u64,
59    },
60    /// Envelope was already seen — a likely replay.
61    #[error("DID envelope replay detected for message {0}")]
62    Replayed(String),
63    /// Payload exceeds the negotiated `max_payload_bytes` limit.
64    #[error("DID payload too large: {size} bytes exceeds limit of {max}")]
65    PayloadTooLarge {
66        /// Actual payload size in bytes.
67        size: usize,
68        /// Negotiated maximum.
69        max: usize,
70    },
71    /// Key material has the wrong size or encoding.
72    #[error("invalid key material: {0}")]
73    InvalidKey(String),
74    /// AEAD nonce must be exactly 12 bytes.
75    #[error("invalid nonce: expected 12 bytes")]
76    InvalidNonce,
77    /// Payload encryption failed.
78    #[error("DID payload encryption failed")]
79    EncryptionFailed,
80    /// Payload decryption or authentication failed.
81    #[error("DID payload decryption failed")]
82    DecryptionFailed,
83    /// Operating system RNG was unavailable.
84    #[error("key generation failed: {0}")]
85    KeyGen(String),
86    /// A typed capability did not cover the protected payload's resource.
87    #[error("capability does not cover this payload: {0}")]
88    Capability(#[from] typesec_core::secure_value::SecureAccessError),
89    /// Hex input is malformed.
90    #[error("invalid hex encoding")]
91    InvalidHex,
92    /// Decrypted payload is not UTF-8.
93    #[error("decrypted DID payload is not valid UTF-8")]
94    InvalidUtf8,
95    /// HTTP request failed.
96    #[error("DID HTTP integration failed: {0}")]
97    Http(Box<dyn std::error::Error + Send + Sync>),
98    /// Ollama response did not contain an assistant message.
99    #[error("Ollama response did not contain message.content")]
100    MissingOllamaReply,
101    /// A TypeDID envelope did not include TypeDID metadata.
102    #[error("DID envelope is missing TypeDID metadata")]
103    MissingTypeDidMetadata,
104    /// Local and remote TypeDID profiles did not overlap.
105    #[error("no compatible TypeDID profile")]
106    NoCompatibleTypeDidProfile,
107}