From 54a4d4bf7619c4c6acf9fb02c2297fefff94d6e9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 25 Feb 2023 16:49:14 +0100 Subject: QCryptographicHash: implement non-OpenSSL3 part of supportsAlgorithm() Unconditionally returning true is incorrect, not only just since NumAlgorithms was added in 0411d98192ede84b115618ece876579fd79252f8. The values may have gaps, we might be compiling with SHA1_ONLY, and, on a language-lawyer level, enums can legally contain values other than those explicitly enumerated, so give the right answer in all of these cases. Pick-to: 6.5 Change-Id: I705d4f759b2572b8b3d1cee18b7939939eedbbac Reviewed-by: Thiago Macieira --- src/corelib/tools/qcryptographichash.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qcryptographichash.cpp') diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 3ed2ebcab4..9b2022020b 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -952,9 +952,37 @@ bool QCryptographicHashPrivate::supportsAlgorithm(QCryptographicHash::Algorithm return algorithm != nullptr; #else - Q_UNUSED(method); - return true; + switch (method) { + case QCryptographicHash::Sha1: +#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 + case QCryptographicHash::Md4: + case QCryptographicHash::Md5: + case QCryptographicHash::Sha224: + case QCryptographicHash::Sha256: + case QCryptographicHash::Sha384: + case QCryptographicHash::Sha512: + case QCryptographicHash::RealSha3_224: + case QCryptographicHash::Keccak_224: + case QCryptographicHash::RealSha3_256: + case QCryptographicHash::Keccak_256: + case QCryptographicHash::RealSha3_384: + case QCryptographicHash::Keccak_384: + case QCryptographicHash::RealSha3_512: + case QCryptographicHash::Keccak_512: + case QCryptographicHash::Blake2b_160: + case QCryptographicHash::Blake2b_256: + case QCryptographicHash::Blake2b_384: + case QCryptographicHash::Blake2b_512: + case QCryptographicHash::Blake2s_128: + case QCryptographicHash::Blake2s_160: + case QCryptographicHash::Blake2s_224: + case QCryptographicHash::Blake2s_256: #endif + return true; + case QCryptographicHash::NumAlgorithms: ; + }; + return false; +#endif // !USING_OPENSSL3 } static constexpr int qt_hash_block_size(QCryptographicHash::Algorithm method) -- cgit v1.2.3