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.
This commit is contained in:
Tobias Junghans 2021-05-10 09:48:10 +02:00 committed by Albert Astals Cid
parent 040d7d6348
commit 974f8ec8d0
4 changed files with 23 additions and 36 deletions

View File

@ -22,7 +22,6 @@
#include <QDebug>
#include <QElapsedTimer>
#include <QScopedPointer>
#include <QtCrypto>
#include <QtPlugin>
#include <qcaprovider.h>
@ -1606,32 +1605,28 @@ public:
#ifndef OPENSSL_FIPS
namespace {
struct DsaDeleter
{
static inline void cleanup(void *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, DsaDeleter> dsa(DSA_new());
std::unique_ptr<DSA, decltype(DsaDeleter)> 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)
{
static const auto RsaDeleter = [](RSA *pointer) {
if (pointer)
RSA_free((RSA *)pointer);
}
};
struct BnDeleter
{
static inline void cleanup(void *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, RsaDeleter> rsa(RSA_new());
std::unique_ptr<RSA, decltype(RsaDeleter)> rsa(RSA_new(), RsaDeleter);
if (!rsa)
return;
QScopedPointer<BIGNUM, BnDeleter> e(BN_new());
std::unique_ptr<BIGNUM, decltype(BnDeleter)> 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()

View File

@ -140,7 +140,7 @@ void KeyBundleTest::privKey()
}
void KeyBundleTest::createBundle()
{
QScopedPointer<QCA::KeyBundle> newBundle(new QCA::KeyBundle);
std::unique_ptr<QCA::KeyBundle> newBundle(new QCA::KeyBundle);
QVERIFY(newBundle->isNull());

View File

@ -167,7 +167,7 @@ void PipeUnitTest::readWriteSecure()
void PipeUnitTest::signalTests()
{
QScopedPointer<QCA::QPipe> pipe(new QCA::QPipe);
std::unique_ptr<QCA::QPipe> pipe(new QCA::QPipe);
pipe->create();
QVERIFY(pipe->writeEnd().isValid());
@ -214,7 +214,7 @@ void PipeUnitTest::signalTests()
void PipeUnitTest::signalTestsSecure()
{
QScopedPointer<QCA::QPipe> pipe(new QCA::QPipe);
std::unique_ptr<QCA::QPipe> pipe(new QCA::QPipe);
pipe->create(true);
QVERIFY(pipe->writeEnd().isValid());

View File

@ -58,7 +58,7 @@ void TLSUnitTest::testCipherList()
if (!QCA::isSupported("tls", QStringLiteral("qca-ossl")))
QWARN("TLS not supported for qca-ossl");
else {
QScopedPointer<QCA::TLS> tls(new QCA::TLS(QCA::TLS::Stream, nullptr, QStringLiteral("qca-ossl")));
std::unique_ptr<QCA::TLS> 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")));