interactsh_rs/crypto/
errors.rs

1pub(crate) use errors_to_reexport::crypto_error;
2pub use errors_to_reexport::CryptoError;
3
4
5mod errors_to_reexport {
6    use snafu::prelude::*;
7    #[cfg(feature = "openssl")]
8    use snafu::Backtrace;
9
10
11    cfg_if::cfg_if! {
12        if #[cfg(feature = "rustcrypto")] {
13            pub use RustCryptoError as CryptoError;
14        } else if #[cfg(feature = "openssl")] {
15            pub use OpensslError as CryptoError;
16        }
17    }
18
19    cfg_if::cfg_if! {
20        if #[cfg(feature = "rustcrypto")] {
21            pub use rustcrypto_error as crypto_error;
22        } else if #[cfg(feature = "openssl")] {
23            pub use openssl_error as crypto_error;
24        }
25    }
26
27
28    /// Errors returned for cryptography operations
29    #[cfg(feature = "rustcrypto")]
30    #[derive(Debug, Snafu)]
31    #[snafu(module(rustcrypto_error), context(suffix(false)), visibility(pub))]
32    pub enum RustCryptoError {
33        #[snafu(display("Failed to decode the data using base 64 encoding"))]
34        Base64DecodeAes { source: base64::DecodeError },
35
36        #[snafu(display("Failed to encode the RSA public key as a base 64 string"))]
37        Base64EncodeRsaPub { source: rsa::pkcs8::spki::Error },
38
39        #[snafu(display("Failed to generate the RSA private key"))]
40        RsaGen { source: rsa::errors::Error },
41
42        #[snafu(display("Failed to decrypt the data with the provided RSA private key"))]
43        RsaDecrypt { source: rsa::errors::Error },
44    }
45
46
47    /// Errors returned for cryptography operations
48    #[cfg(feature = "openssl")]
49    #[derive(Debug, Snafu)]
50    #[snafu(module, context(suffix(false)), visibility(pub))]
51    pub enum OpensslError {
52        #[snafu(display("Unable to decrypt data with provided AES key"))]
53        AesDecrypt { source: openssl::error::ErrorStack },
54
55        #[snafu(display("Failed to decode the data using base 64 encoding"))]
56        Base64DecodeAes { source: base64::DecodeError },
57
58        #[snafu(display("Failed to encode the RSA public key as a base 64 string"))]
59        Base64EncodeRsaPub { source: openssl::error::ErrorStack },
60
61        #[snafu(display("Failed to generate the RSA private key"))]
62        RsaGen { source: openssl::error::ErrorStack },
63
64        #[snafu(display("Requested RSA key bit size is too large (bitsize: {bitsize})"))]
65        RsaBitSize {
66            bitsize: usize,
67            backtrace: Backtrace,
68        },
69
70        #[snafu(display("Failed to decrypt the data with the provided RSA private key"))]
71        RsaDecrypt { source: openssl::error::ErrorStack },
72
73        #[snafu(display("Failed to extract the RSA public key from the RSA private key"))]
74        RsaGetPubKey { source: openssl::error::ErrorStack },
75    }
76}