Skip to main content

crypto_seal/
error.rs

1use core::array::TryFromSliceError;
2use ed25519_dalek::SignatureError;
3#[cfg(feature = "std")]
4use std::io;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum Error {
9    #[error("Method provided is not supported")]
10    Unsupported,
11    #[error("Unable to encrypt data provided")]
12    EncryptionError,
13    #[error("Unable to decrypt data provided")]
14    DecryptionError,
15    #[error("Unable to encrypt data stream")]
16    EncryptionStreamError,
17    #[error("Unable to decrypt data stream")]
18    DecryptionStreamError,
19    #[error("Invalid Signature")]
20    InvalidSignature,
21    #[error("Invalid public key")]
22    InvalidPublicKey,
23    #[error("Invalid private key")]
24    InvalidPrivateKey,
25    #[error("Recipients was not set or available")]
26    RecipientsNotAvailable,
27    #[error("Unable to convert slice: {0}")]
28    InvalidLength(#[from] TryFromSliceError),
29    #[error("{0}")]
30    SignatureError(SignatureError),
31    #[cfg(feature = "std")]
32    #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
33    #[error(transparent)]
34    IoError(#[from] io::Error),
35    #[cfg(feature = "json")]
36    #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
37    #[error("{0}")]
38    SerdeJsonError(serde_json::Error),
39    #[error(transparent)]
40    PostcardError(#[from] postcard::Error),
41}
42
43impl From<SignatureError> for Error {
44    fn from(value: SignatureError) -> Self {
45        Error::SignatureError(value)
46    }
47}
48
49#[cfg(feature = "json")]
50impl From<serde_json::Error> for Error {
51    fn from(value: serde_json::Error) -> Self {
52        Error::SerdeJsonError(value)
53    }
54}