From 8e28e86cafa2ccc66e54786df072fe47c063750a Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Wed, 26 Apr 2017 17:36:42 +0200
Subject: [PATCH] python: improve wrapper for crypto::Certificate

Add Certificate issuer, getName and revoke
---
 python/opendht.pyx     | 13 +++++++++++--
 python/opendht_cpp.pxd |  3 +++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/python/opendht.pyx b/python/opendht.pyx
index f87a24da..0eefcb42 100644
--- a/python/opendht.pyx
+++ b/python/opendht.pyx
@@ -278,13 +278,22 @@ cdef class Certificate(_WithID):
         return h
     def toString(self):
         return self._cert.get().toString().decode()
+    def getName(self):
+        return self._cert.get().getName()
+    def revoke(self, PrivateKey k, Certificate c):
+        self._cert.get().revoke(k._key, deref(c._cert.get()));
+    def __bytes__(self):
+        return self._cert.get().toString() if self._cert else b''
+    property issuer:
+        def __get__(self):
+            c = Certificate()
+            c._cert = self._cert.get().issuer
+            return c;
     @staticmethod
     def generate(PrivateKey k, str name, Identity i = Identity(), bool is_ca = False):
         c = Certificate()
         c._cert = cpp.make_shared[cpp.Certificate](cpp.Certificate.generate(k._key, name.encode(), i._id, is_ca))
         return c
-    def __bytes__(self):
-        return self._cert.get().toString() if self._cert else b''
 
 cdef class ListenToken(object):
     cdef cpp.InfoHash _h
diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd
index 4ae8130e..1b62f436 100644
--- a/python/opendht_cpp.pxd
+++ b/python/opendht_cpp.pxd
@@ -96,8 +96,11 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
         Certificate(string pem)
         InfoHash getId() const
         string toString() const
+        string getName() const
+        void revoke(PrivateKey key, Certificate cert)
         @staticmethod
         Certificate generate(PrivateKey key, string name, Identity ca, bool is_ca)
+        shared_ptr[Certificate] issuer
 
 cdef extern from "opendht/value.h" namespace "dht":
     cdef cppclass Value:
-- 
GitLab