summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-05-21 11:28:40 +0200
committerMarc Mutz <[email protected]>2024-05-29 14:24:30 +0200
commitfa8256bb5a36aa18480bc603d538bf07c8464ec7 (patch)
tree16fba36b0a45ef6b70539415b8813424fd959f0f /src/corelib/plugin
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 <[email protected]>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r--src/corelib/plugin/quuid.cpp14
-rw-r--r--src/corelib/plugin/quuid.h4
2 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 8c3b758aaca..99f8ee30b0d 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -116,12 +116,12 @@ static QUuid _q_uuidFromHex(const char *src)
return QUuid();
}
-static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
+static QUuid createFromName(QUuid ns, QByteArrayView baseData, QCryptographicHash::Algorithm algorithm, int version) noexcept
{
- QCryptographicHash hash(algorithm);
- hash.addData(QByteArrayView{ns.toBytes()});
- hash.addData(baseData);
- QByteArrayView hashResult = hash.resultView();
+ std::byte buffer[20];
+ Q_ASSERT(sizeof buffer >= size_t(QCryptographicHash::hashLength(algorithm)));
+ QByteArrayView hashResult
+ = QCryptographicHash::hashInto(buffer, {QByteArrayView{ns.toBytes()}, baseData}, algorithm);
Q_ASSERT(hashResult.size() >= 16);
hashResult.truncate(16); // Sha1 will be too long
@@ -570,13 +570,13 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept
\sa variant(), version(), createUuidV3()
*/
#ifndef QT_BOOTSTRAPPED
-QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData)
+QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData) noexcept
{
return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
}
#endif
-QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData)
+QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) noexcept
{
return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
}
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
index 14029f1abc9..580784723c7 100644
--- a/src/corelib/plugin/quuid.h
+++ b/src/corelib/plugin/quuid.h
@@ -221,9 +221,9 @@ public:
public:
static QUuid createUuid();
#ifndef QT_BOOTSTRAPPED
- static QUuid createUuidV3(const QUuid &ns, const QByteArray &baseData);
+ static QUuid createUuidV3(const QUuid &ns, const QByteArray &baseData) noexcept;
#endif
- static QUuid createUuidV5(const QUuid &ns, const QByteArray &baseData);
+ static QUuid createUuidV5(const QUuid &ns, const QByteArray &baseData) noexcept;
#ifndef QT_BOOTSTRAPPED
static inline QUuid createUuidV3(const QUuid &ns, const QString &baseData)
{