newton-core 0.4.16

newton protocol core sdk
//! Error types for the privacy cryptography module.

use thiserror::Error;

/// Errors that can occur during privacy-layer cryptographic operations.
#[derive(Debug, Error)]
pub enum CryptoError {
    /// HPKE encryption failed.
    #[error("HPKE encryption failed: {0}")]
    HpkeEncrypt(String),

    /// HPKE decryption failed.
    #[error("HPKE decryption failed: {0}")]
    HpkeDecrypt(String),

    /// The provided public key is invalid.
    #[error("invalid public key: {reason}")]
    InvalidPublicKey {
        /// Description of why the key is invalid.
        reason: String,
    },

    /// The provided private key is invalid.
    #[error("invalid private key: {reason}")]
    InvalidPrivateKey {
        /// Description of why the key is invalid.
        reason: String,
    },

    /// Ed25519 signing operation failed.
    #[error("Ed25519 signing failed: {0}")]
    SigningFailed(String),

    /// Ed25519 signature verification failed.
    #[error("Ed25519 verification failed: {0}")]
    VerificationFailed(String),

    /// Key derivation (HKDF or curve conversion) failed.
    #[error("key derivation failed: {0}")]
    KeyDerivation(String),

    /// Serialization of an envelope or cryptographic structure failed.
    #[error("envelope serialization failed: {0}")]
    Serialization(String),

    /// Deserialization of an envelope or cryptographic structure failed.
    #[error("envelope deserialization failed: {0}")]
    Deserialization(String),

    /// Threshold decryption (post-DH HPKE operations) failed.
    #[error("threshold decryption failed: {0}")]
    ThresholdDecrypt(String),

    /// Keystore encryption failed.
    #[error("keystore encryption failed: {0}")]
    KeystoreEncrypt(String),

    /// Keystore decryption failed.
    #[error("keystore decryption failed: {0}")]
    KeystoreDecrypt(String),
}