From bf9561c4afa1d431ba044c4a500d1778934a6006 Mon Sep 17 00:00:00 2001 From: Adrien Beraud Date: Sat, 30 Aug 2025 19:15:09 -0400 Subject: [PATCH] python: add binding for getLongId, getPublicKey --- python/opendht.pyx | 18 ++++++++++++++++++ python/opendht_cpp.pxd | 3 +++ 2 files changed, 21 insertions(+) diff --git a/python/opendht.pyx b/python/opendht.pyx index dd5949af..d2e32364 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -403,6 +403,10 @@ cdef class PublicKey(_WithID): h = InfoHash() h._infohash = self._key.get().getId() return h + def getLongId(self): + id = PkId() + id._pkid = self._key.get().getLongId() + return id def encrypt(self, bytes dat): cdef size_t d_len = len(dat) cdef cpp.uint8_t* d_ptr = dat @@ -423,6 +427,10 @@ cdef class Certificate(_WithID): if self._cert: h._infohash = self._cert.get().getId() return h + def getLongId(self): + id = PkId() + id._pkid = self._cert.get().getLongId() + return id def toString(self): return self._cert.get().toString().decode() def getName(self): @@ -555,6 +563,16 @@ cdef class DhtRunner(_WithID): if self.thisptr: h._infohash = self.thisptr.get().getId() return h + def getLongId(self): + h = PkId() + if self.thisptr: + h._pkid = self.thisptr.get().getPublicKey().get().getLongId() + return h + def getPublicKey(self): + pk = PublicKey() + if self.thisptr: + pk._key = self.thisptr.get().getPublicKey() + return pk def getNodeId(self): return self.thisptr.get().getNodeId().toString() def ping(self, SockAddr addr, done_cb=None): diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd index feff0b53..7c467c27 100644 --- a/python/opendht_cpp.pxd +++ b/python/opendht_cpp.pxd @@ -125,12 +125,14 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto": cdef cppclass PublicKey: PublicKey() InfoHash getId() const + PkId getLongId() const Blob encrypt(Blob data) const cdef cppclass Certificate: Certificate() Certificate(string pem) InfoHash getId() const + PkId getLongId() const string toString() const string getName() const void revoke(PrivateKey key, Certificate cert) @@ -271,6 +273,7 @@ cdef extern from "opendht/dhtrunner.h" namespace "dht": SockAddr bind6 InfoHash getId() const + shared_ptr[PublicKey] getPublicKey() const InfoHash getNodeId() const void bootstrap(const_char*, const_char*) void bootstrap(const SockAddr&, DoneCallbackSimple done_cb)