Skip to content

Commit 1a39ed5

Browse files
authored
pkcs8: add Error::Crypto variant (#305)
The `Error` enum is `non_exhaustive` so this is non-breaking
1 parent 91dbf42 commit 1a39ed5

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

pkcs8/src/document/private_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl PrivateKeyDocument {
112112
let pbkdf2_iterations = 10_000;
113113
let pbes2_params =
114114
pbes2::Parameters::pbkdf2_sha256_aes256cbc(pbkdf2_iterations, &salt, &iv)
115-
.map_err(|_| Error::Encode)?; // TODO(tarcieri): add `pkcs8::Error::Crypto`
115+
.map_err(|_| Error::Crypto)?;
116116

117117
self.encrypt_with_params(pbes2_params, password)
118118
}

pkcs8/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub type Result<T> = core::result::Result<T, Error>;
1313
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1414
#[non_exhaustive]
1515
pub enum Error {
16+
/// Cryptographic errors
17+
Crypto,
18+
1619
/// Decoding errors
1720
Decode,
1821

@@ -38,6 +41,7 @@ pub enum Error {
3841
impl fmt::Display for Error {
3942
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4043
match self {
44+
Error::Crypto => f.write_str("PKCS#8 cryptographic error"),
4145
Error::Decode => f.write_str("PKCS#8 decoding error"),
4246
Error::Encode => f.write_str("PKCS#8 encoding error"),
4347
#[cfg(feature = "std")]

pkcs8/src/private_key_info/encrypted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a> EncryptedPrivateKeyInfo<'a> {
6262
pub fn decrypt(&self, password: impl AsRef<[u8]>) -> Result<PrivateKeyDocument> {
6363
self.encryption_algorithm
6464
.decrypt(password, &self.encrypted_data)
65-
.map_err(|_| Error::Decode) // TODO(tarcieri): add `pkcs8::Error::Crypto`
65+
.map_err(|_| Error::Crypto)
6666
.and_then(TryInto::try_into)
6767
}
6868

0 commit comments

Comments
 (0)