From b1919f01c8cc8e10ec65829400e54e99a7fae8cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 Feb 2023 11:27:08 +0100 Subject: [PATCH] QCryptographicHash: move EVP members into a struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... 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 --- src/corelib/tools/qcryptographichash.cpp | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 9445b4fad36..9443fdfe170 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -327,13 +327,15 @@ public: }; using EVP_MD_CTX_ptr = std::unique_ptr; using EVP_MD_ptr = std::unique_ptr; - EVP_MD_ptr algorithm; - EVP_MD_CTX_ptr context; - bool initializationFailed = false; + struct EVP { + EVP_MD_ptr algorithm; + EVP_MD_CTX_ptr context; + bool initializationFailed = false; - void evp_init(); - void evp_reset() noexcept; - void evp_finalizeUnchecked() noexcept; + void init(QCryptographicHash::Algorithm method); + void reset() noexcept; + void finalizeUnchecked(HashResult &result) noexcept; + } evp; #endif union { @@ -548,11 +550,11 @@ void QCryptographicHashPrivate::init() method == QCryptographicHash::Blake2s_224) { new (&blake2sContext) blake2s_state; } else { - evp_init(); + evp.init(method); } } -void QCryptographicHashPrivate::evp_init() +void QCryptographicHashPrivate::EVP::init(QCryptographicHash::Algorithm method) { Q_ASSERT(!context); @@ -664,11 +666,11 @@ void QCryptographicHashPrivate::reset() noexcept method == QCryptographicHash::Blake2s_224) { blake2s_init(&blake2sContext, hashLengthInternal(method)); } else { - evp_reset(); + evp.reset(); } } -void QCryptographicHashPrivate::evp_reset() noexcept +void QCryptographicHashPrivate::EVP::reset() noexcept { if (!initializationFailed) { Q_ASSERT(context); @@ -785,8 +787,8 @@ void QCryptographicHashPrivate::addData(QByteArrayView bytes) noexcept method == QCryptographicHash::Blake2s_160 || method == QCryptographicHash::Blake2s_224) { blake2s_update(&blake2sContext, reinterpret_cast(data), length); - } else if (!initializationFailed) { - EVP_DigestUpdate(context.get(), (const unsigned char *)data, length); + } else if (!evp.initializationFailed) { + EVP_DigestUpdate(evp.context.get(), (const unsigned char *)data, length); } } result.clear(); @@ -961,11 +963,11 @@ void QCryptographicHashPrivate::finalizeUnchecked() noexcept result.resizeForOverwrite(length); blake2s_final(©, result.data(), length); } else { - evp_finalizeUnchecked(); + evp.finalizeUnchecked(result); } } -void QCryptographicHashPrivate::evp_finalizeUnchecked() noexcept +void QCryptographicHashPrivate::EVP::finalizeUnchecked(HashResult &result) noexcept { if (!initializationFailed) { EVP_MD_CTX_ptr copy = EVP_MD_CTX_ptr(EVP_MD_CTX_new());