Skip to main content
This is unreleased documentation for the main (development) branch of crypto-glue.

pkcs5/
error.rs

1//! Error types
2
3use core::fmt;
4use der::asn1::ObjectIdentifier;
5
6/// Result type
7pub type Result<T> = core::result::Result<T, Error>;
8
9/// Error type
10#[derive(Copy, Clone, Debug, Eq, PartialEq)]
11#[non_exhaustive]
12pub enum Error {
13    /// Given parameters are invalid for this algorithm
14    AlgorithmParametersInvalid {
15        /// OID for algorithm for which the parameters were invalid
16        oid: ObjectIdentifier,
17    },
18
19    /// Decryption Failed
20    DecryptFailed,
21
22    /// Encryption Failed
23    EncryptFailed,
24
25    /// PBES1 support is limited to parsing; encryption/decryption is not supported (won't fix)
26    #[cfg(feature = "pbes2")]
27    NoPbes1CryptSupport,
28
29    /// Random number generation failure.
30    #[cfg(feature = "rand_core")]
31    Rng,
32
33    /// Algorithm is not supported
34    ///
35    /// This may be due to a disabled crate feature
36    /// Or the algorithm is not supported at all.
37    UnsupportedAlgorithm {
38        /// OID of unsupported algorithm
39        oid: ObjectIdentifier,
40    },
41}
42
43impl core::error::Error for Error {}
44
45impl fmt::Display for Error {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        match self {
48            Error::AlgorithmParametersInvalid { oid } => {
49                write!(f, "PKCS#5 parameters for algorithm {oid} are invalid")
50            }
51            Error::DecryptFailed => f.write_str("PKCS#5 decryption failed"),
52            Error::EncryptFailed => f.write_str("PKCS#5 encryption failed"),
53            #[cfg(feature = "pbes2")]
54            Error::NoPbes1CryptSupport => {
55                f.write_str("PKCS#5 encryption/decryption unsupported for PBES1 (won't fix)")
56            }
57            #[cfg(feature = "rand_core")]
58            Error::Rng => f.write_str("random number generation failure"),
59            Error::UnsupportedAlgorithm { oid } => {
60                write!(f, "PKCS#5 algorithm {oid} is unsupported")
61            }
62        }
63    }
64}