Skip to main content

coldstar_signer/
error.rs

1//! Error types for the secure signer
2//!
3//! All errors are designed to be informative without leaking sensitive data.
4//! Merged from coldstar-rs and devsyrem secure_signer implementations.
5
6use thiserror::Error;
7
8/// Errors that can occur during signing operations
9#[derive(Debug, Error)]
10pub enum SignerError {
11    /// Memory locking failed - system may not support mlock or limit reached
12    #[error("Failed to lock memory: {0}")]
13    MemoryLockFailed(String),
14
15    /// Key derivation failed
16    #[error("Key derivation failed: {0}")]
17    KeyDerivationFailed(String),
18
19    /// Decryption failed - wrong passphrase or corrupted data
20    #[error("Decryption failed - invalid passphrase or corrupted container")]
21    DecryptionFailed,
22
23    /// Encryption failed
24    #[error("Encryption failed: {0}")]
25    EncryptionFailed(String),
26
27    /// Invalid key format (from devsyrem: expected 32 or 64 bytes)
28    #[error("Invalid key format: expected 32 or 64 bytes, got {0}")]
29    InvalidKeyFormat(usize),
30
31    /// Invalid key length (from coldstar-rs: generic expected vs got)
32    #[error("Invalid key length: expected {expected}, got {got}")]
33    InvalidKeyLength { expected: usize, got: usize },
34
35    /// Signing operation failed
36    #[error("Signing failed: {0}")]
37    SigningFailed(String),
38
39    /// Invalid transaction format
40    #[error("Invalid transaction format: {0}")]
41    InvalidTransaction(String),
42
43    /// Serialization error
44    #[error("Serialization error: {0}")]
45    SerializationError(String),
46
47    /// Base58 decoding error
48    #[error("Base58 decoding error: {0}")]
49    Base58Error(String),
50
51    /// Base64 decoding error
52    #[error("Base64 decoding error: {0}")]
53    Base64Error(String),
54
55    /// Container format error
56    #[error("Invalid container format: {0}")]
57    ContainerError(String),
58
59    /// I/O error
60    #[error("I/O error: {0}")]
61    IoError(String),
62}
63
64impl From<std::io::Error> for SignerError {
65    fn from(e: std::io::Error) -> Self {
66        SignerError::IoError(e.to_string())
67    }
68}
69
70impl From<base64::DecodeError> for SignerError {
71    fn from(e: base64::DecodeError) -> Self {
72        SignerError::Base64Error(e.to_string())
73    }
74}
75
76impl From<bs58::decode::Error> for SignerError {
77    fn from(e: bs58::decode::Error) -> Self {
78        SignerError::Base58Error(e.to_string())
79    }
80}
81
82impl From<serde_json::Error> for SignerError {
83    fn from(e: serde_json::Error) -> Self {
84        SignerError::SerializationError(e.to_string())
85    }
86}