Skip to main content

ave_identity/
error.rs

1//! Error types returned by `ave-identity`.
2//!
3//! The enum keeps parsing, serialization and cryptographic failures under a
4//! single type so callers can propagate or match them without depending on the
5//! implementation details of each algorithm.
6
7use thiserror::Error;
8
9/// Errors returned by hashing, key handling and signature operations.
10#[derive(Error, Debug, Clone)]
11pub enum CryptoError {
12    /// The identifier prefix does not match any supported algorithm.
13    #[error("Unknown algorithm identifier: {0}")]
14    UnknownAlgorithm(String),
15
16    /// A digest cannot be parsed or does not match the expected layout.
17    #[error("Invalid hash format: {0}")]
18    InvalidHashFormat(String),
19
20    /// A signature cannot be parsed or does not match the expected layout.
21    #[error("Invalid signature format: {0}")]
22    InvalidSignatureFormat(String),
23
24    /// Signature verification failed.
25    #[error("Signature verification failed")]
26    SignatureVerificationFailed,
27
28    /// A public key is malformed or has an unexpected size.
29    #[error("Invalid public key: {0}")]
30    InvalidPublicKey(String),
31
32    /// A secret key is malformed, missing data or cannot be decrypted.
33    #[error("Invalid secret key: {0}")]
34    InvalidSecretKey(String),
35
36    /// Signing was requested from a verification-only value.
37    #[error("No secret key available for signing (verification-only instance)")]
38    MissingSecretKey,
39
40    /// Base64 decoding failed.
41    #[error("Base64 decode error: {0}")]
42    Base64DecodeError(String),
43
44    /// The input size does not match the size required by the algorithm.
45    #[error("Invalid data length: expected {expected}, got {actual}")]
46    InvalidDataLength { expected: usize, actual: usize },
47
48    /// Borsh serialization or deserialization failed.
49    #[error("Serialization error: {0}")]
50    SerializationError(String),
51
52    /// Hash computation or hash comparison failed.
53    #[error("Hash computation failed: {0}")]
54    HashError(String),
55
56    /// A signing operation could not be completed.
57    #[error("Signing failed: {0}")]
58    SigningError(String),
59
60    /// The algorithm is recognized but not implemented by this crate.
61    #[error("Unsupported algorithm: {0}")]
62    UnsupportedAlgorithm(String),
63
64    /// PKCS#8 DER parsing failed.
65    #[error("Invalid PKCS#8 DER format: {0}")]
66    InvalidDerFormat(String),
67}