hopr-types 1.8.0

Complete collection of Rust types used in Hoprnet and other related projects
Documentation
use crate::crypto::errors::CryptoError;
use hex::FromHexError;
use serde_json::Error as JsonError;
use thiserror::Error;

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

    #[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>;