encrypted_message/error.rs
1//! Error types for the encryption & decryption operations.
2
3use thiserror::Error;
4
5/// Returned from [`EncryptedMessage`](crate::EncryptedMessage) encryption methods when an error occurs.
6#[derive(Debug, Error)]
7pub enum EncryptionError {
8 /// This error occurs when a payload could not be serialized into JSON.
9 #[error("The payload could not be serialized into JSON.")]
10 Serialization(#[from] serde_json::Error),
11}
12
13/// Returned from [`EncryptedMessage`](crate::EncryptedMessage) decryption methods when an error occurs.
14#[derive(Debug, Error)]
15pub enum DecryptionError {
16 /// This error occurs when a field in [`EncryptedMessage`](crate::EncryptedMessage) could not be base64-decoded.
17 #[error(transparent)]
18 Base64Decoding(#[from] base64::DecodeError),
19
20 /// This error occurs when a payload could not be decrypted with any of the available keys.
21 #[error("The payload could not be decrypted with any of the available keys.")]
22 Decryption,
23
24 /// This error occurs when a payload could not be deserialized into the expected type.
25 #[error("The payload could not be deserialized into the expected type.")]
26 Deserialization(#[from] serde_json::Error),
27}