hoprd_keypair/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use hex::FromHexError;
use hopr_crypto_types::errors::CryptoError;
use hopr_platform::error::PlatformError;
use serde_json::Error as JsonError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum KeyPairError {
    #[error("file system error: {0}")]
    FileSystemError(#[from] PlatformError),

    #[error("cryptography error: {0}")]
    CryptographyError(#[from] CryptoError),

    #[error("JSON error: {0}")]
    JsonError(#[from] JsonError),

    #[error("hex parsing ")]
    HexParsingError(#[from] FromHexError),

    #[error("key derivation error {0}")]
    KeyDerivationError(String),

    #[error("crypto error: macs do not match. Key store may have been altered.")]
    MacMismatch,

    #[error("decoding error: invalid encrypted key length {actual} but expected {expected}")]
    InvalidEncryptedKeyLength { actual: usize, expected: usize },

    #[error("invalid version")]
    InvalidVersion { actual: usize, expected: usize },

    #[error("cryptographic parameter '{name:?}' must be {expected:?} bytes")]
    InvalidParameterSize { name: String, expected: usize },

    #[error("Invalid private key size {actual} but expected {expected}")]
    InvalidPrivateKeySize { actual: usize, expected: usize },

    #[error("{0}")]
    GeneralError(String),
}

pub type Result<T> = core::result::Result<T, KeyPairError>;