ps-cypher 0.1.0-29

Convergent encryption with ChaCha20-Poly1305, zstd, and Reed-Solomon ECC
Documentation
#![allow(clippy::module_name_repetitions)]

use ps_compress::{CompressionError, DecompressionError};
use ps_ecc::{DecodeError, EncodeError};
use ps_hash::HashError;
use thiserror::Error;

/// Errors returned by [`encrypt`](crate::encrypt).
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum EncryptionError {
    /// Returned if ChaCha20-Poly1305 encryption fails.
    #[error("encryption failed (chacha20poly1305)")]
    ChaCha(#[source] chacha20poly1305::Error),
    /// Returned if compression fails.
    #[error("compression failed: {0}")]
    Compression(#[from] CompressionError),
    /// Returned if ECC encoding fails.
    #[error("ECC encoding failed: {0}")]
    Ecc(#[from] EncodeError),
    /// Returned if hashing fails.
    #[error("hashing failed: {0}")]
    Hash(#[from] HashError),
}

/// Errors returned by [`decrypt`](crate::decrypt).
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum DecryptionError {
    /// Returned if ChaCha20-Poly1305 rejects the ciphertext or key.
    #[error("decryption failed (chacha20poly1305)")]
    ChaCha(#[source] chacha20poly1305::Error),
    /// Returned if decompression fails or the output would exceed the key's length bound.
    #[error("decompression failed: {0}")]
    Decompression(#[from] DecompressionError),
    /// Returned if ECC decoding fails.
    #[error("ECC decoding failed: {0}")]
    Ecc(#[from] DecodeError),
    /// Returned if hashing the decrypted data fails.
    #[error("hashing failed: {0}")]
    Hash(#[from] HashError),
    /// Returned if the decrypted data does not hash to the decryption key.
    #[error("decrypted data does not hash to the decryption key")]
    KeyMismatch,
}