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 <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2023-02-25 16:49:14 +01:00
parent ec2c27d596
commit 54a4d4bf76

View File

@ -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)