Skip to main content

stateset_crypto/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during VES cryptographic operations
4#[derive(Debug, Clone, PartialEq, Eq, Error)]
5#[non_exhaustive]
6pub enum CryptoError {
7    /// JCS does not support Infinity or `NaN` values
8    #[error("JCS does not support Infinity or NaN")]
9    JcsInvalidNumber,
10    /// Cannot canonicalize the given type
11    #[error("Cannot canonicalize type")]
12    JcsUnsupportedType,
13    /// The provided UUID string is invalid
14    #[error("Invalid UUID: {0}")]
15    InvalidUuid(String),
16    /// Invalid hex string
17    #[error("Invalid hex: {0}")]
18    InvalidHex(String),
19    /// Salt must be exactly 16 bytes
20    #[error("Salt must be 16 bytes")]
21    InvalidSalt,
22    /// At least one recipient is required for encryption
23    #[error("At least one recipient required")]
24    NoRecipients,
25    /// The specified recipient was not found in the encrypted payload
26    #[error("Recipient {0} not found")]
27    RecipientNotFound(u32),
28    /// The computed payload hash does not match the expected hash
29    #[error("Payload hash mismatch")]
30    PayloadHashMismatch,
31    /// Ed25519 signature verification failed
32    #[error("Signature verification failed: {0}")]
33    SignatureError(String),
34    /// AES-256-GCM encryption failed
35    #[error("Encryption error: {0}")]
36    EncryptionError(String),
37    /// AES-256-GCM decryption failed
38    #[error("Decryption error: {0}")]
39    DecryptionError(String),
40    /// X25519 ECDH key wrapping failed
41    #[error("Key wrapping error: {0}")]
42    KeyWrapError(String),
43    /// JSON serialization or canonicalization failed
44    #[error("Serialization error: {0}")]
45    SerializationError(String),
46}