QCryptographicHash: Add getter for algorithm()

This can be helpful when you calculate multiple hashes, store them in a
vector and you want to know which result belongs to which algorithm.

[ChangeLog][QtCore][QCryptographicHash] Added getter algorithm().

Change-Id: Ifcf78536f215619a6e2e3035a95598327d0ed733
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Linus Jahn 2022-09-10 20:23:14 +02:00
parent 358248b495
commit cd37a773ca
3 changed files with 13 additions and 0 deletions

View File

@ -364,6 +364,16 @@ void QCryptographicHash::reset() noexcept
d->reset();
}
/*!
Returns the algorithm used to generate the cryptographic hash.
\since 6.5
*/
QCryptographicHash::Algorithm QCryptographicHash::algorithm() const noexcept
{
return d->method;
}
void QCryptographicHashPrivate::reset() noexcept
{
switch (method) {

View File

@ -71,6 +71,7 @@ public:
void swap(QCryptographicHash &other) noexcept { qt_ptr_swap(d, other.d); }
void reset() noexcept;
[[nodiscard]] Algorithm algorithm() const noexcept;
#if QT_DEPRECATED_SINCE(6, 4)
QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead")

View File

@ -51,6 +51,8 @@ void tst_QCryptographicHash::repeated_result()
QCryptographicHash::Algorithm _algo = QCryptographicHash::Algorithm(algo);
QCryptographicHash hash(_algo);
QCOMPARE_EQ(hash.algorithm(), _algo);
QFETCH(QByteArray, first);
hash.addData(first);