diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-02-13 11:55:29 +0100 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-02-14 16:15:23 +0100 |
commit | d8cb8fc2451c0e78ff60465674ba80222b657402 (patch) | |
tree | 4c756bb286917f5e4833eb1788a59d6ccf29aeab /openpgp/src/crypto | |
parent | 852a4f79df24ede1cd6b2410f7d51a7bc82b673c (diff) |
openpgp: Fix hash algorithm detection.
- Hash algorithm detection previously checked only conversion to Nid.
- More thorough check which involves construction of the Hasher object
is needed.
- Adjust the code and add a comment.
- Fixes https://gitlab.com/sequoia-pgp/sequoia/-/issues/979
Diffstat (limited to 'openpgp/src/crypto')
-rw-r--r-- | openpgp/src/crypto/backend/openssl/hash.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/openpgp/src/crypto/backend/openssl/hash.rs b/openpgp/src/crypto/backend/openssl/hash.rs index c379ac2e..7dc9b5d1 100644 --- a/openpgp/src/crypto/backend/openssl/hash.rs +++ b/openpgp/src/crypto/backend/openssl/hash.rs @@ -81,7 +81,11 @@ fn get_md(algo: HashAlgorithm) -> Option<MessageDigest> { impl HashAlgorithm { /// Whether Sequoia supports this algorithm. pub fn is_supported(self) -> bool { - get_md(self).is_some() + // Try to construct a digest. This indirectly looks up + // digest's Nid and tries to initialize OpenSSL hasher. If + // all of that succeeds the algorithm is supported by the + // OpenSSL backend. + OpenSslDigest::new(self).is_ok() } /// Creates a new hash context for this algorithm. |