QMessageAuthenticationCode: have setKey() call initMessageHash()

All callers of Private::setKey() follow the call with one to
initMessageHash(), so move the call into setKey(). We can't remove
initMessageHash(), because reset() still needs to call it without a
setKey().

Pick-to: 6.5
Change-Id: I1fc8cd5cda90f1595cedcc323a4cee8baa7ce6a5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2023-03-20 10:54:18 +01:00
parent bd7e304d48
commit c513d4fe31

View File

@ -1352,6 +1352,8 @@ void QMessageAuthenticationCodePrivate::setKey(QByteArrayView newKey) noexcept
if (key.size() < blockSize)
key.resize(blockSize, '\0');
initMessageHash();
}
/*!
@ -1414,7 +1416,6 @@ QMessageAuthenticationCode::QMessageAuthenticationCode(QCryptographicHash::Algor
: d(new QMessageAuthenticationCodePrivate(method))
{
d->setKey(key);
d->initMessageHash();
}
/*!
@ -1503,7 +1504,6 @@ void QMessageAuthenticationCode::setKey(QByteArrayView key) noexcept
{
d->messageHash.reset();
d->setKey(key);
d->initMessageHash();
}
/*!
@ -1594,7 +1594,6 @@ QByteArray QMessageAuthenticationCode::hash(QByteArrayView message, QByteArrayVi
{
QMessageAuthenticationCodePrivate mac(method);
mac.setKey(key);
mac.initMessageHash();
mac.messageHash.addData(message);
mac.finalizeUnchecked();
return mac.messageHash.resultView().toByteArray();