Skip to main content

herolib_crypt/keys/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum KeyError {
5    #[error("Invalid hex encoding: {0}")]
6    InvalidHex(String),
7
8    #[error("Invalid base64 encoding: {0}")]
9    InvalidBase64(String),
10
11    #[error("Invalid key size: expected {expected}, got {actual}")]
12    InvalidKeySize { expected: usize, actual: usize },
13
14    #[error("Invalid key format")]
15    InvalidKeyFormat,
16
17    #[error("Invalid signature size: expected {expected}, got {actual}")]
18    InvalidSignatureSize { expected: usize, actual: usize },
19
20    #[error("Signature verification failed")]
21    VerificationFailed,
22
23    #[error("Signing operation failed")]
24    SigningFailed,
25
26    #[error("Random generation failed")]
27    RandomGenerationFailed,
28}
29
30impl From<hex::FromHexError> for KeyError {
31    fn from(err: hex::FromHexError) -> Self {
32        KeyError::InvalidHex(err.to_string())
33    }
34}
35
36impl From<base64::DecodeError> for KeyError {
37    fn from(err: base64::DecodeError) -> Self {
38        KeyError::InvalidBase64(err.to_string())
39    }
40}
41
42impl From<ed25519_dalek::SignatureError> for KeyError {
43    fn from(_err: ed25519_dalek::SignatureError) -> Self {
44        KeyError::VerificationFailed
45    }
46}