1use hex::FromHexError;
2use hopr_crypto_types::errors::CryptoError;
3use hopr_platform::error::PlatformError;
4use serde_json::Error as JsonError;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum KeyPairError {
9 #[error("file system error: {0}")]
10 FileSystemError(#[from] PlatformError),
11
12 #[error("cryptography error: {0}")]
13 CryptographyError(#[from] CryptoError),
14
15 #[error("JSON error: {0}")]
16 JsonError(#[from] JsonError),
17
18 #[error("hex parsing ")]
19 HexParsingError(#[from] FromHexError),
20
21 #[error("key derivation error {0}")]
22 KeyDerivationError(String),
23
24 #[error("crypto error: macs do not match. Key store may have been altered.")]
25 MacMismatch,
26
27 #[error("decoding error: invalid encrypted key length {actual} but expected {expected}")]
28 InvalidEncryptedKeyLength { actual: usize, expected: usize },
29
30 #[error("invalid version")]
31 InvalidVersion { actual: usize, expected: usize },
32
33 #[error("cryptographic parameter '{name:?}' must be {expected:?} bytes")]
34 InvalidParameterSize { name: String, expected: usize },
35
36 #[error("Invalid private key size {actual} but expected {expected}")]
37 InvalidPrivateKeySize { actual: usize, expected: usize },
38
39 #[error("{0}")]
40 GeneralError(String),
41}
42
43pub type Result<T> = core::result::Result<T, KeyPairError>;