From cd37a773ca0ceb3718875295bd244fb462893a0d Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 10 Sep 2022 20:23:14 +0200 Subject: 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 Reviewed-by: Marc Mutz Reviewed-by: Qt CI Bot --- src/corelib/tools/qcryptographichash.cpp | 10 ++++++++++ src/corelib/tools/qcryptographichash.h | 1 + 2 files changed, 11 insertions(+) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 3f6075f2aa..b9984f0b01 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -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) { diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index 94fc82783b..5f9104fe9f 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -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") -- cgit v1.2.3