summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcryptographichash.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-05-21 11:28:40 +0200
committerMarc Mutz <marc.mutz@qt.io>2024-05-29 14:24:30 +0200
commitfa8256bb5a36aa18480bc603d538bf07c8464ec7 (patch)
tree16fba36b0a45ef6b70539415b8813424fd959f0f /src/corelib/tools/qcryptographichash.cpp
parentc70c81b371993ca865d523bb5f37eac4eb8a972b (diff)
QCryptographicHash: extend hashInto to more than one piece of data
This allows use of the noexcept static function in cases where more than one piece of data needs to be hashed, and concatenation of said data would have to allocate memory. Port QUuid to use the new function, allowing to mark the V3 and V5 create functions noexcept. As a drive-by, take QUuid by value in the internal helper function, fixing a Clazy warning. Task-number: QTBUG-125431 Change-Id: I17938f0be44c91085e2aaa5574953f8dceacc990 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qcryptographichash.cpp')
-rw-r--r--src/corelib/tools/qcryptographichash.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 3807e32a723..f64f11ee44c 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -1166,22 +1166,29 @@ QByteArray QCryptographicHash::hash(QByteArrayView data, Algorithm method)
/*!
\since 6.8
+ \fn QCryptographicHash::hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, Algorithm method);
+ \fn QCryptographicHash::hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, Algorithm method);
+ \fn QCryptographicHash::hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, Algorithm method);
\fn QCryptographicHash::hashInto(QSpan<char> buffer, QByteArrayView data, Algorithm method);
\fn QCryptographicHash::hashInto(QSpan<uchar> buffer, QByteArrayView data, Algorithm method);
\fn QCryptographicHash::hashInto(QSpan<std::byte> buffer, QByteArrayView data, Algorithm method);
Returns the hash of \a data using \a method, using \a buffer to store the result.
+ If \a data is a span, adds all the byte array views to the hash, in the order given.
+
The return value will be a sub-span of \a buffer, unless \a buffer is of
insufficient size, in which case a null QByteArrayView is returned.
\sa hash()
*/
-QByteArrayView QCryptographicHash::hashInto(QSpan<std::byte> buffer, QByteArrayView data,
+QByteArrayView QCryptographicHash::hashInto(QSpan<std::byte> buffer,
+ QSpan<const QByteArrayView> data,
Algorithm method) noexcept
{
QCryptographicHashPrivate hash(method);
- hash.addData(data);
+ for (QByteArrayView part : data)
+ hash.addData(part);
hash.finalizeUnchecked(); // no mutex needed: no-one but us has access to 'hash'
auto result = hash.resultView();
if (buffer.size() < result.size())