From bdb13a1b3111bccc52941becaad1f3c14cbb640d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 Feb 2023 18:14:57 +0100 Subject: [PATCH] QSmallByteArray: add sufficient API to make conversion to QByteArrayView implicit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iterators were missing. Provide a const data() overload to implement the iterator functions in their natural form. Pick-to: 6.5 Change-Id: I906013e55fce2effbedba0d283fb4cea3b512fdd Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Thiago Macieira --- src/corelib/tools/qcryptographichash.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 9b2022020b4..55763a4d447 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -130,6 +130,7 @@ class QSmallByteArray public: // all SMFs are ok! quint8 *data() noexcept { return m_data.data(); } + const quint8 *data() const noexcept { return m_data.data(); } qsizetype size() const noexcept { return qsizetype{m_size}; } quint8 &operator[](qsizetype n) { @@ -144,8 +145,22 @@ public: Q_ASSERT(size_t(s) <= N); m_size = std::uint8_t(s); } + void resize(qsizetype s, quint8 v) + { + const auto oldSize = size(); + resizeForOverwrite(s); + if (s > oldSize) + memset(data() + oldSize, v, size() - oldSize); + } QByteArrayView toByteArrayView() const noexcept - { return QByteArrayView{m_data.data(), size()}; } + { return *this; } + + auto begin() noexcept { return data(); } + auto begin() const noexcept { return data(); } + auto cbegin() const noexcept { return begin(); } + auto end() noexcept { return data() + size(); } + auto end() const noexcept { return data() + size(); } + auto cend() const noexcept { return end(); } }; static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) noexcept @@ -1260,8 +1275,8 @@ void QMessageAuthenticationCodePrivate::finalizeUnchecked() noexcept oKeyPad[i] = keyData[i] ^ 0x5c; messageHash.reset(); - messageHash.addData(oKeyPad.toByteArrayView()); - messageHash.addData(hashedMessage.toByteArrayView()); + messageHash.addData(oKeyPad); + messageHash.addData(hashedMessage); messageHash.finalizeUnchecked(); result = messageHash.result;