From d9bced965bb6aef4cd5515873da0201519e759a9 Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Mon, 1 May 2017 16:26:12 -0400
Subject: [PATCH] crypto: add TrustList move operator, prevent copy

---
 include/opendht/crypto.h | 6 ++++++
 src/crypto.cpp           | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h
index 4d4cec72..a9ebe5bf 100644
--- a/include/opendht/crypto.h
+++ b/include/opendht/crypto.h
@@ -470,6 +470,10 @@ struct OPENDHT_PUBLIC TrustList
     };
 
     TrustList();
+    TrustList(TrustList&& o) : trust(std::move(o.trust)) {
+        o.trust = nullptr;
+    }
+    TrustList& operator=(TrustList&& o);
     ~TrustList();
     void add(const Certificate& crt);
     void add(const RevocationList& crl);
@@ -477,6 +481,8 @@ struct OPENDHT_PUBLIC TrustList
     VerifyResult verify(const Certificate& crt) const;
 
 private:
+    TrustList(const TrustList& o) = delete;
+    TrustList& operator=(const TrustList& o) = delete;
     gnutls_x509_trust_list_t trust;
 };
 
diff --git a/src/crypto.cpp b/src/crypto.cpp
index c74d0cb1..de50fb9b 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -1180,6 +1180,15 @@ TrustList::~TrustList() {
     gnutls_x509_trust_list_deinit(trust, 1);
 }
 
+TrustList&
+TrustList::operator=(TrustList&& o)
+{
+    if (trust)
+        gnutls_x509_trust_list_deinit(trust, true);
+    trust = std::move(o.trust);
+    o.trust = nullptr;
+}
+
 void TrustList::add(const Certificate& crt)
 {
     auto chain = crt.getChainWithRevocations(true);
-- 
GitLab