From aa5b8b84a8ba11f065fb53a37b14f4aa7142f50e Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Thu, 27 Apr 2017 03:21:57 +0200
Subject: [PATCH] python: add TrustList wrapper

---
 python/opendht.pyx     | 18 ++++++++++++++++++
 python/opendht_cpp.pxd | 12 ++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/python/opendht.pyx b/python/opendht.pyx
index d5aa9617..1ffbb03c 100644
--- a/python/opendht.pyx
+++ b/python/opendht.pyx
@@ -318,6 +318,24 @@ cdef class Certificate(_WithID):
         c._cert = cpp.make_shared[cpp.Certificate](cpp.Certificate.generate(deref(k._key.get()), name.encode(), i._id, is_ca))
         return c
 
+cdef class VerifyResult(object):
+    cdef cpp.TrustListVerifyResult _result
+    def __bool__(self):
+        return self._result.isValid()
+    def __str(self):
+        return self._result.toString()
+
+cdef class TrustList(object):
+    cdef cpp.TrustList _trust
+    def add(self, Certificate cert):
+        self._trust.add(deref(cert._cert.get()))
+    def remove(self, Certificate cert):
+        self._trust.remove(deref(cert._cert.get()))
+    def verify(self, Certificate cert):
+        r = VerifyResult()
+        r._result = self._trust.verify(deref(cert._cert.get()))
+        return r
+
 cdef class ListenToken(object):
     cdef cpp.InfoHash _h
     cdef cpp.shared_future[size_t] _t
diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd
index 60c23dad..0b6cbf09 100644
--- a/python/opendht_cpp.pxd
+++ b/python/opendht_cpp.pxd
@@ -108,6 +108,18 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
         Certificate generate(PrivateKey key, string name, Identity ca, bool is_ca)
         shared_ptr[Certificate] issuer
 
+    cdef cppclass TrustList:
+        cppclass VerifyResult:
+            bool operator bool() const
+            bool isValid() const
+            string toString() const
+        TrustList()
+        void add(Certificate)
+        void remove(Certificate)
+        VerifyResult verify(Certificate);
+
+ctypedef TrustList.VerifyResult TrustListVerifyResult
+
 cdef extern from "opendht/value.h" namespace "dht":
     cdef cppclass Value:
         Value() except +
-- 
GitLab