Skip to main content

astrid_crypto/
error.rs

1//! Cryptographic error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during cryptographic operations.
6#[derive(Debug, Error)]
7pub enum CryptoError {
8    /// Invalid key length.
9    #[error("invalid key length: expected {expected}, got {actual}")]
10    InvalidKeyLength {
11        /// Expected length in bytes.
12        expected: usize,
13        /// Actual length in bytes.
14        actual: usize,
15    },
16
17    /// Invalid signature length.
18    #[error("invalid signature length: expected {expected}, got {actual}")]
19    InvalidSignatureLength {
20        /// Expected length in bytes.
21        expected: usize,
22        /// Actual length in bytes.
23        actual: usize,
24    },
25
26    /// Invalid public key.
27    #[error("invalid public key: {0}")]
28    InvalidPublicKey(String),
29
30    /// Signature verification failed.
31    #[error("signature verification failed")]
32    SignatureVerificationFailed,
33
34    /// Invalid hex encoding.
35    #[error("invalid hex encoding")]
36    InvalidHexEncoding,
37
38    /// Invalid base64 encoding.
39    #[error("invalid base64 encoding")]
40    InvalidBase64Encoding,
41
42    /// I/O error (e.g. reading/writing key files).
43    #[error("I/O error: {0}")]
44    IoError(String),
45}
46
47/// Result type for cryptographic operations.
48pub type CryptoResult<T> = Result<T, CryptoError>;