1use core::fmt;
4use der::asn1::ObjectIdentifier;
5
6pub type Result<T> = core::result::Result<T, Error>;
8
9#[derive(Copy, Clone, Debug, Eq, PartialEq)]
11#[non_exhaustive]
12pub enum Error {
13 AlgorithmParametersInvalid {
15 oid: ObjectIdentifier,
17 },
18
19 DecryptFailed,
21
22 EncryptFailed,
24
25 #[cfg(feature = "pbes2")]
27 NoPbes1CryptSupport,
28
29 #[cfg(feature = "rand_core")]
31 Rng,
32
33 UnsupportedAlgorithm {
38 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}