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>bb10
parent
05f913d57d
commit
ac9d25340a
|
|
@ -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…
Reference in New Issue