QCryptographicHash: move EVP members into a struct
... and move the evp_{init,reset,finalizeUnchecked}() functions into it as new members without the evp_ prefix. Need to pass QCHPrivate members as function arguments now. This is in preparation of moving these members into the union. Pick-to: 6.5 Change-Id: I64805d8aac91f777fbc5c13b1a08b37e5227169a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
51b1a9963d
commit
b1919f01c8
@ -327,13 +327,15 @@ public:
|
|||||||
};
|
};
|
||||||
using EVP_MD_CTX_ptr = std::unique_ptr<EVP_MD_CTX, EVP_MD_CTX_deleter>;
|
using EVP_MD_CTX_ptr = std::unique_ptr<EVP_MD_CTX, EVP_MD_CTX_deleter>;
|
||||||
using EVP_MD_ptr = std::unique_ptr<EVP_MD, EVP_MD_deleter>;
|
using EVP_MD_ptr = std::unique_ptr<EVP_MD, EVP_MD_deleter>;
|
||||||
EVP_MD_ptr algorithm;
|
struct EVP {
|
||||||
EVP_MD_CTX_ptr context;
|
EVP_MD_ptr algorithm;
|
||||||
bool initializationFailed = false;
|
EVP_MD_CTX_ptr context;
|
||||||
|
bool initializationFailed = false;
|
||||||
|
|
||||||
void evp_init();
|
void init(QCryptographicHash::Algorithm method);
|
||||||
void evp_reset() noexcept;
|
void reset() noexcept;
|
||||||
void evp_finalizeUnchecked() noexcept;
|
void finalizeUnchecked(HashResult &result) noexcept;
|
||||||
|
} evp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
union {
|
union {
|
||||||
@ -548,11 +550,11 @@ void QCryptographicHashPrivate::init()
|
|||||||
method == QCryptographicHash::Blake2s_224) {
|
method == QCryptographicHash::Blake2s_224) {
|
||||||
new (&blake2sContext) blake2s_state;
|
new (&blake2sContext) blake2s_state;
|
||||||
} else {
|
} else {
|
||||||
evp_init();
|
evp.init(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCryptographicHashPrivate::evp_init()
|
void QCryptographicHashPrivate::EVP::init(QCryptographicHash::Algorithm method)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!context);
|
Q_ASSERT(!context);
|
||||||
|
|
||||||
@ -664,11 +666,11 @@ void QCryptographicHashPrivate::reset() noexcept
|
|||||||
method == QCryptographicHash::Blake2s_224) {
|
method == QCryptographicHash::Blake2s_224) {
|
||||||
blake2s_init(&blake2sContext, hashLengthInternal(method));
|
blake2s_init(&blake2sContext, hashLengthInternal(method));
|
||||||
} else {
|
} else {
|
||||||
evp_reset();
|
evp.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCryptographicHashPrivate::evp_reset() noexcept
|
void QCryptographicHashPrivate::EVP::reset() noexcept
|
||||||
{
|
{
|
||||||
if (!initializationFailed) {
|
if (!initializationFailed) {
|
||||||
Q_ASSERT(context);
|
Q_ASSERT(context);
|
||||||
@ -785,8 +787,8 @@ void QCryptographicHashPrivate::addData(QByteArrayView bytes) noexcept
|
|||||||
method == QCryptographicHash::Blake2s_160 ||
|
method == QCryptographicHash::Blake2s_160 ||
|
||||||
method == QCryptographicHash::Blake2s_224) {
|
method == QCryptographicHash::Blake2s_224) {
|
||||||
blake2s_update(&blake2sContext, reinterpret_cast<const uint8_t *>(data), length);
|
blake2s_update(&blake2sContext, reinterpret_cast<const uint8_t *>(data), length);
|
||||||
} else if (!initializationFailed) {
|
} else if (!evp.initializationFailed) {
|
||||||
EVP_DigestUpdate(context.get(), (const unsigned char *)data, length);
|
EVP_DigestUpdate(evp.context.get(), (const unsigned char *)data, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.clear();
|
result.clear();
|
||||||
@ -961,11 +963,11 @@ void QCryptographicHashPrivate::finalizeUnchecked() noexcept
|
|||||||
result.resizeForOverwrite(length);
|
result.resizeForOverwrite(length);
|
||||||
blake2s_final(©, result.data(), length);
|
blake2s_final(©, result.data(), length);
|
||||||
} else {
|
} else {
|
||||||
evp_finalizeUnchecked();
|
evp.finalizeUnchecked(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCryptographicHashPrivate::evp_finalizeUnchecked() noexcept
|
void QCryptographicHashPrivate::EVP::finalizeUnchecked(HashResult &result) noexcept
|
||||||
{
|
{
|
||||||
if (!initializationFailed) {
|
if (!initializationFailed) {
|
||||||
EVP_MD_CTX_ptr copy = EVP_MD_CTX_ptr(EVP_MD_CTX_new());
|
EVP_MD_CTX_ptr copy = EVP_MD_CTX_ptr(EVP_MD_CTX_new());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user