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    /// Algorithm is not supported
30    ///
31    /// This may be due to a disabled crate feature
32    /// Or the algorithm is not supported at all.
33    UnsupportedAlgorithm {
34        /// OID of unsupported algorithm
35        oid: ObjectIdentifier,
36    },
37}
38
39impl fmt::Display for Error {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Error::AlgorithmParametersInvalid { oid } => {
43                write!(f, "PKCS#5 parameters for algorithm {} are invalid", oid)
44            }
45            Error::DecryptFailed => f.write_str("PKCS#5 decryption failed"),
46            Error::EncryptFailed => f.write_str("PKCS#5 encryption failed"),
47            #[cfg(feature = "pbes2")]
48            Error::NoPbes1CryptSupport => {
49                f.write_str("PKCS#5 encryption/decryption unsupported for PBES1 (won't fix)")
50            }
51            Error::UnsupportedAlgorithm { oid } => {
52                write!(f, "PKCS#5 algorithm {} is unsupported", oid)
53            }
54        }
55    }
56}