Skip to main content

ps_cypher/
error.rs

1#![allow(clippy::module_name_repetitions)]
2
3use ps_compress::{CompressionError, DecompressionError};
4use ps_ecc::{DecodeError, EncodeError};
5use ps_hash::HashError;
6use thiserror::Error;
7
8/// Errors returned by [`encrypt`](crate::encrypt).
9#[derive(Clone, Debug, Error)]
10#[non_exhaustive]
11pub enum EncryptionError {
12    /// Returned if ChaCha20-Poly1305 encryption fails.
13    #[error("encryption failed (chacha20poly1305)")]
14    ChaCha(#[source] chacha20poly1305::Error),
15    /// Returned if compression fails.
16    #[error("compression failed: {0}")]
17    Compression(#[from] CompressionError),
18    /// Returned if ECC encoding fails.
19    #[error("ECC encoding failed: {0}")]
20    Ecc(#[from] EncodeError),
21    /// Returned if hashing fails.
22    #[error("hashing failed: {0}")]
23    Hash(#[from] HashError),
24}
25
26/// Errors returned by [`decrypt`](crate::decrypt).
27#[derive(Clone, Debug, Error)]
28#[non_exhaustive]
29pub enum DecryptionError {
30    /// Returned if ChaCha20-Poly1305 rejects the ciphertext or key.
31    #[error("decryption failed (chacha20poly1305)")]
32    ChaCha(#[source] chacha20poly1305::Error),
33    /// Returned if decompression fails or the output would exceed the key's length bound.
34    #[error("decompression failed: {0}")]
35    Decompression(#[from] DecompressionError),
36    /// Returned if ECC decoding fails.
37    #[error("ECC decoding failed: {0}")]
38    Ecc(#[from] DecodeError),
39    /// Returned if hashing the decrypted data fails.
40    #[error("hashing failed: {0}")]
41    Hash(#[from] HashError),
42    /// Returned if the decrypted data does not hash to the decryption key.
43    #[error("decrypted data does not hash to the decryption key")]
44    KeyMismatch,
45}