From c820e4b0bb1aeab59d65f9024301f468159e2337 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 30 Aug 2019 21:48:32 +0200 Subject: [PATCH] core: Don't store a reference in CoreCertManager Storing references violates all sorts of Best Practices, and also prevents the compiler from implicitly declaring a copy assignment operator. Store a pointer instead, and clean up the API a bit. --- src/core/coreidentity.cpp | 16 ++++++++-------- src/core/coreidentity.h | 14 ++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/core/coreidentity.cpp b/src/core/coreidentity.cpp index 5cdd3ca6..5671ae80 100644 --- a/src/core/coreidentity.cpp +++ b/src/core/coreidentity.cpp @@ -25,7 +25,7 @@ CoreIdentity::CoreIdentity(IdentityId id, QObject* parent) : Identity(id, parent) #ifdef HAVE_SSL - , _certManager(*this) + , _certManager(this) #endif { #ifdef HAVE_SSL @@ -37,7 +37,7 @@ CoreIdentity::CoreIdentity(IdentityId id, QObject* parent) CoreIdentity::CoreIdentity(const Identity& other, QObject* parent) : Identity(other, parent) #ifdef HAVE_SSL - , _certManager(*this) + , _certManager(this) #endif { #ifdef HAVE_SSL @@ -51,7 +51,7 @@ CoreIdentity::CoreIdentity(const CoreIdentity& other, QObject* parent) #ifdef HAVE_SSL , _sslKey(other._sslKey) , _sslCert(other._sslCert) - , _certManager(*this) + , _certManager(this) #endif { #ifdef HAVE_SSL @@ -91,9 +91,9 @@ void CoreIdentity::setSslCert(const QByteArray& encoded) // CoreCertManager // ======================================== -CoreCertManager::CoreCertManager(CoreIdentity& identity) - : CertManager(identity.id()) - , identity(identity) +CoreCertManager::CoreCertManager(CoreIdentity* identity) + : CertManager(identity->id()) + , _identity(identity) { setAllowClientUpdates(true); } @@ -105,13 +105,13 @@ void CoreCertManager::setId(IdentityId id) void CoreCertManager::setSslKey(const QByteArray& encoded) { - identity.setSslKey(encoded); + _identity->setSslKey(encoded); CertManager::setSslKey(encoded); } void CoreCertManager::setSslCert(const QByteArray& encoded) { - identity.setSslCert(encoded); + _identity->setSslCert(encoded); CertManager::setSslCert(encoded); } diff --git a/src/core/coreidentity.h b/src/core/coreidentity.h index bb11ff51..573f9c57 100644 --- a/src/core/coreidentity.h +++ b/src/core/coreidentity.h @@ -20,6 +20,8 @@ #pragma once +#include "core-export.h" + #include "identity.h" #ifdef HAVE_SSL @@ -34,12 +36,12 @@ class SignalProxy; // ======================================== #ifdef HAVE_SSL class CoreIdentity; -class CoreCertManager : public CertManager +class CORE_EXPORT CoreCertManager : public CertManager { Q_OBJECT public: - CoreCertManager(CoreIdentity& identity); + CoreCertManager(CoreIdentity* identity); # ifdef HAVE_SSL const QSslKey& sslKey() const override; @@ -53,7 +55,7 @@ public slots: void setId(IdentityId id); private: - CoreIdentity& identity; + CoreIdentity* _identity{nullptr}; }; #endif // HAVE_SSL @@ -61,7 +63,7 @@ private: // ========================================= // CoreIdentity // ========================================= -class CoreIdentity : public Identity +class CORE_EXPORT CoreIdentity : public Identity { Q_OBJECT @@ -93,12 +95,12 @@ private: #ifdef HAVE_SSL inline const QSslKey& CoreCertManager::sslKey() const { - return identity.sslKey(); + return _identity->sslKey(); } inline const QSslCertificate& CoreCertManager::sslCert() const { - return identity.sslCert(); + return _identity->sslCert(); } #endif -- 2.20.1