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 Change-Id: I3d0c0cd2a37c2bbeb60974307ff138e26b82bf69 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit ac9d25340aec5c165db5e58a3d8b869967c5ff97) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2e94481c51
commit
d1a7e9f493
@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user