From 974f8ec8d04c9426d6200043c26672ef7fbc126f Mon Sep 17 00:00:00 2001 From: Tobias Junghans Date: Mon, 10 May 2021 09:48:10 +0200 Subject: [PATCH] Migrate from QScopedPointer to std::unique_ptr QScopedPointer::take() is deprecated since Qt 6.1 so we can switch to std::unique_ptr everywhere to be consistent. --- plugins/qca-ossl/qca-ossl.cpp | 49 ++++++++++---------------- unittest/keybundle/keybundle.cpp | 2 +- unittest/pipeunittest/pipeunittest.cpp | 4 +-- unittest/tls/tlsunittest.cpp | 4 +-- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/plugins/qca-ossl/qca-ossl.cpp b/plugins/qca-ossl/qca-ossl.cpp index 77acbaa8..96549250 100644 --- a/plugins/qca-ossl/qca-ossl.cpp +++ b/plugins/qca-ossl/qca-ossl.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -1606,32 +1605,28 @@ public: #ifndef OPENSSL_FIPS namespace { -struct DsaDeleter -{ - static inline void cleanup(void *pointer) - { - if (pointer) - DSA_free((DSA *)pointer); - } +static const auto DsaDeleter = [](DSA *pointer) { + if (pointer) + DSA_free((DSA *)pointer); }; } // end of anonymous namespace static bool make_dlgroup(const QByteArray &seed, int bits, int counter, DLParams *params) { int ret_counter; - QScopedPointer dsa(DSA_new()); + std::unique_ptr dsa(DSA_new(), DsaDeleter); if (!dsa) return false; if (DSA_generate_parameters_ex( - dsa.data(), bits, (const unsigned char *)seed.data(), seed.size(), &ret_counter, nullptr, nullptr) != 1) + dsa.get(), bits, (const unsigned char *)seed.data(), seed.size(), &ret_counter, nullptr, nullptr) != 1) return false; if (ret_counter != counter) return false; const BIGNUM *bnp, *bnq, *bng; - DSA_get0_pqg(dsa.data(), &bnp, &bnq, &bng); + DSA_get0_pqg(dsa.get(), &bnp, &bnq, &bng); params->p = bn2bi(bnp); params->q = bn2bi(bnq); params->g = bn2bi(bng); @@ -1804,22 +1799,14 @@ private Q_SLOTS: // RSAKey //---------------------------------------------------------------------------- namespace { -struct RsaDeleter -{ - static inline void cleanup(void *pointer) - { - if (pointer) - RSA_free((RSA *)pointer); - } +static const auto RsaDeleter = [](RSA *pointer) { + if (pointer) + RSA_free((RSA *)pointer); }; -struct BnDeleter -{ - static inline void cleanup(void *pointer) - { - if (pointer) - BN_free((BIGNUM *)pointer); - } +static const auto BnDeleter = [](BIGNUM *pointer) { + if (pointer) + BN_free((BIGNUM *)pointer); }; } // end of anonymous namespace @@ -1847,22 +1834,22 @@ public: void run() override { - QScopedPointer rsa(RSA_new()); + std::unique_ptr rsa(RSA_new(), RsaDeleter); if (!rsa) return; - QScopedPointer e(BN_new()); + std::unique_ptr e(BN_new(), BnDeleter); if (!e) return; - BN_clear(e.data()); - if (BN_set_word(e.data(), exp) != 1) + BN_clear(e.get()); + if (BN_set_word(e.get(), exp) != 1) return; - if (RSA_generate_key_ex(rsa.data(), bits, e.data(), nullptr) == 0) + if (RSA_generate_key_ex(rsa.get(), bits, e.get(), nullptr) == 0) return; - result = rsa.take(); + result = rsa.release(); } RSA *takeResult() diff --git a/unittest/keybundle/keybundle.cpp b/unittest/keybundle/keybundle.cpp index 77c8075e..f624a36d 100644 --- a/unittest/keybundle/keybundle.cpp +++ b/unittest/keybundle/keybundle.cpp @@ -140,7 +140,7 @@ void KeyBundleTest::privKey() } void KeyBundleTest::createBundle() { - QScopedPointer newBundle(new QCA::KeyBundle); + std::unique_ptr newBundle(new QCA::KeyBundle); QVERIFY(newBundle->isNull()); diff --git a/unittest/pipeunittest/pipeunittest.cpp b/unittest/pipeunittest/pipeunittest.cpp index a5e30992..278931a9 100644 --- a/unittest/pipeunittest/pipeunittest.cpp +++ b/unittest/pipeunittest/pipeunittest.cpp @@ -167,7 +167,7 @@ void PipeUnitTest::readWriteSecure() void PipeUnitTest::signalTests() { - QScopedPointer pipe(new QCA::QPipe); + std::unique_ptr pipe(new QCA::QPipe); pipe->create(); QVERIFY(pipe->writeEnd().isValid()); @@ -214,7 +214,7 @@ void PipeUnitTest::signalTests() void PipeUnitTest::signalTestsSecure() { - QScopedPointer pipe(new QCA::QPipe); + std::unique_ptr pipe(new QCA::QPipe); pipe->create(true); QVERIFY(pipe->writeEnd().isValid()); diff --git a/unittest/tls/tlsunittest.cpp b/unittest/tls/tlsunittest.cpp index a00f5642..e7bbd06c 100644 --- a/unittest/tls/tlsunittest.cpp +++ b/unittest/tls/tlsunittest.cpp @@ -58,8 +58,8 @@ void TLSUnitTest::testCipherList() if (!QCA::isSupported("tls", QStringLiteral("qca-ossl"))) QWARN("TLS not supported for qca-ossl"); else { - QScopedPointer tls(new QCA::TLS(QCA::TLS::Stream, nullptr, QStringLiteral("qca-ossl"))); - QStringList cipherList = tls->supportedCipherSuites(QCA::TLS::TLS_v1); + std::unique_ptr tls(new QCA::TLS(QCA::TLS::Stream, nullptr, QStringLiteral("qca-ossl"))); + QStringList cipherList = tls->supportedCipherSuites(QCA::TLS::TLS_v1); QVERIFY(cipherList.contains(QStringLiteral("TLS_DHE_RSA_WITH_AES_256_CBC_SHA"))); QVERIFY(cipherList.contains(QStringLiteral("TLS_RSA_WITH_AES_256_CBC_SHA"))); QVERIFY(cipherList.contains(QStringLiteral("TLS_DHE_RSA_WITH_AES_128_CBC_SHA")));