diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-06-22 12:00:03 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-06-22 13:13:14 +0200 |
commit | a027eae2820485b565209e0221a0671e6707036c (patch) | |
tree | b8ce83baae46e63484ddd71256419638aca7b5d7 /openpgp/src/crypto | |
parent | a72b2ac161af29aba4d4a280e65f78fc7b4794fb (diff) |
openpgp: Match hash algorithms exhaustively.
Diffstat (limited to 'openpgp/src/crypto')
-rw-r--r-- | openpgp/src/crypto/backend/cng/hash.rs | 13 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/openssl/hash.rs | 3 |
2 files changed, 13 insertions, 3 deletions
diff --git a/openpgp/src/crypto/backend/cng/hash.rs b/openpgp/src/crypto/backend/cng/hash.rs index 6254d12d..301ac0c6 100644 --- a/openpgp/src/crypto/backend/cng/hash.rs +++ b/openpgp/src/crypto/backend/cng/hash.rs @@ -83,7 +83,12 @@ impl TryFrom<HashAlgorithm> for cng::HashAlgorithmId { HashAlgorithm::SHA384 => cng::HashAlgorithmId::Sha384, HashAlgorithm::SHA512 => cng::HashAlgorithmId::Sha512, HashAlgorithm::MD5 => cng::HashAlgorithmId::Md5, - algo => Err(Error::UnsupportedHashAlgorithm(algo))?, + + HashAlgorithm::SHA224 | + HashAlgorithm::RipeMD | + HashAlgorithm::Private(_) | + HashAlgorithm::Unknown(_) => + return Err(Error::UnsupportedHashAlgorithm(value)), }) } } @@ -113,7 +118,11 @@ impl HashAlgorithm { HashAlgorithm::SHA384 => true, HashAlgorithm::SHA512 => true, HashAlgorithm::MD5 => true, - _ => false, + + HashAlgorithm::SHA224 | + HashAlgorithm::RipeMD | + HashAlgorithm::Private(_) | + HashAlgorithm::Unknown(_) => false, } } diff --git a/openpgp/src/crypto/backend/openssl/hash.rs b/openpgp/src/crypto/backend/openssl/hash.rs index 7dc9b5d1..b4f6d816 100644 --- a/openpgp/src/crypto/backend/openssl/hash.rs +++ b/openpgp/src/crypto/backend/openssl/hash.rs @@ -73,7 +73,8 @@ fn get_md(algo: HashAlgorithm) -> Option<MessageDigest> { SHA384 => Nid::SHA384, SHA512 => Nid::SHA512, SHA224 => Nid::SHA224, - _ => return None, + HashAlgorithm::Private(_) | + HashAlgorithm::Unknown(_) => return None, }; MessageDigest::from_nid(nid) } |