summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-02-21 09:11:34 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-02-22 19:24:16 +0100
commitac9d25340aec5c165db5e58a3d8b869967c5ff97 (patch)
tree581b575fb4834492ecbbfdb1815bdd470b988202
parent05f913d57d6557d1c540894651cc83a5b1ec7cf7 (diff)
QMessageAuthenticationCode: Extract Methods finalize{,Unchecked}() from result()
This brings the code in line with its sibling code in QCryptographicHash and prepares for a static hash() optimization and the fixing of the result() re-entrancy issue (QTBUG-111347). Task-number: QTBUG-111347 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I3d0c0cd2a37c2bbeb60974307ff138e26b82bf69 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/tools/qmessageauthenticationcode.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/corelib/tools/qmessageauthenticationcode.cpp b/src/corelib/tools/qmessageauthenticationcode.cpp
index 4ff48fc822..8f131e45a0 100644
--- a/src/corelib/tools/qmessageauthenticationcode.cpp
+++ b/src/corelib/tools/qmessageauthenticationcode.cpp
@@ -75,6 +75,9 @@ public:
bool messageHashInited;
void initMessageHash();
+ void finalize();
+
+ void finalizeUnchecked();
};
void QMessageAuthenticationCodePrivate::initMessageHash()
@@ -208,27 +211,35 @@ bool QMessageAuthenticationCode::addData(QIODevice *device)
*/
QByteArray QMessageAuthenticationCode::result() const
{
- if (!d->result.isEmpty())
- return d->result;
+ d->finalize();
+ return d->result;
+}
- d->initMessageHash();
+void QMessageAuthenticationCodePrivate::finalize()
+{
+ if (!result.isEmpty())
+ return;
+ initMessageHash();
+ finalizeUnchecked();
+}
- const int blockSize = qt_hash_block_size(d->method);
+void QMessageAuthenticationCodePrivate::finalizeUnchecked()
+{
+ const int blockSize = qt_hash_block_size(method);
- QByteArrayView hashedMessage = d->messageHash.resultView();
+ QByteArrayView hashedMessage = messageHash.resultView();
QVarLengthArray<char> oKeyPad(blockSize);
- const char * const keyData = d->key.constData();
+ const char * const keyData = key.constData();
for (int i = 0; i < blockSize; ++i)
oKeyPad[i] = keyData[i] ^ 0x5c;
- QCryptographicHash hash(d->method);
+ QCryptographicHash hash(method);
hash.addData(oKeyPad);
hash.addData(hashedMessage);
- d->result = hash.result();
- return d->result;
+ result = hash.result();
}
/*!