pyrus_crypto/
error.rs

1use thiserror::Error;
2
3use crate::Fingerprint;
4use crate::message::MessageDesc;
5
6/// Error type used for all fallible operations.
7///
8/// It is recommended to use `anyhow`
9/// for easy error handling or error propagation.
10#[non_exhaustive]
11#[derive(Error, Debug)]
12pub enum CryptoError {
13    /// Base64 decoding error. See [`base64::DecodeError`] for more details.
14    #[error("Base64 decoding error.")]
15    DecodingError(#[from] base64::DecodeError),
16    /// Insufficient memory error.
17    #[error("Memory error. The available memory is insufficient or corrupted.")]
18    InsufficientMemory,
19    /// Not a recipient error, see [this example](crate#decrypt-and-verify-a-signed-message).
20    #[error("Certificate {0} is not a recipient of the message.")]
21    NotARecipient(Fingerprint),
22    /// The message is not decrypted, cannot verify the signature.
23    #[error("The message is not decrypted, cannot verify the signature.")]
24    NotDecrypted,
25    /// The certificate does not contain secret keys, but it should.
26    #[error("The certificate does not contain secret keys.")]
27    NotSecret,
28    /// The message parsing failed because the message is not of expected type.
29    #[error("The message is not {0}")]
30    NotType(MessageDesc),
31    /// Serialization error. See [`postcard::Error`] for more details.
32    #[error("Serialization error.")]
33    SerializationError(#[from] postcard::Error),
34    /// AAD authentication error. This would usually indicate that the message is not authentic.
35    #[error("Unauthentic cipher. AAD is not authentic, the message had been tampered with.")]
36    UnauthenticCipher,
37    /// Any other error for which there's no logical cause to happen.
38    #[error("Unknown error. Something wierd had to happen for this one.")]
39    Unknown,
40}
41
42/// [`Result<T, E>`](std::result::Result) type specialization.
43pub type Result<T> = std::result::Result<T, CryptoError>;