ps_cypher/
error.rs

1#![allow(clippy::module_name_repetitions)]
2
3use std::{array::TryFromSliceError, num::TryFromIntError};
4
5use ps_deflate::PsDeflateError;
6use ps_ecc::DecodeError;
7use ps_hash::HashError;
8use thiserror::Error;
9
10#[derive(Clone, Copy, Debug, Error)]
11pub enum ParseKeyError {
12    #[error("Key length of {0} is insufficient.")]
13    InsufficientKeyLength(u8),
14    #[error(transparent)]
15    TryFromIntError(#[from] TryFromIntError),
16    #[error(transparent)]
17    TryFromSliceError(#[from] TryFromSliceError),
18}
19
20#[derive(Clone, Debug, Error)]
21pub enum EncryptionError {
22    #[error("Encryption/Decryption failure (from chacha20poly1305)")]
23    ChaChaError,
24    #[error(transparent)]
25    EccError(#[from] ps_ecc::EncodeError),
26    #[error(transparent)]
27    HashError(#[from] HashError),
28    #[error(transparent)]
29    ParseKeyError(#[from] ParseKeyError),
30    #[error(transparent)]
31    PsDeflateError(#[from] PsDeflateError),
32}
33
34#[derive(Clone, Debug, Error)]
35pub enum DecryptionError {
36    #[error("Encryption/Decryption failure (from chacha20poly1305)")]
37    ChaChaError,
38    #[error(transparent)]
39    EccError(#[from] DecodeError),
40    #[error(transparent)]
41    ParseKeyError(#[from] ParseKeyError),
42    #[error(transparent)]
43    PsDeflateError(#[from] PsDeflateError),
44}
45
46#[derive(Error, Debug, Clone)]
47pub enum PsCypherError {
48    #[error(transparent)]
49    DecryptionError(#[from] DecryptionError),
50    #[error(transparent)]
51    EncryptionError(#[from] EncryptionError),
52}
53
54impl From<chacha20poly1305::Error> for EncryptionError {
55    fn from(_error: chacha20poly1305::Error) -> Self {
56        Self::ChaChaError
57    }
58}
59
60impl From<chacha20poly1305::Error> for DecryptionError {
61    fn from(_error: chacha20poly1305::Error) -> Self {
62        Self::ChaChaError
63    }
64}