From c37f0083d3ac0f97c81504d09e0f04cdaed8c62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Fri, 30 Aug 2019 11:26:29 -0400 Subject: [PATCH] crypto: add CertificateRequest::toString --- include/opendht/crypto.h | 1 + src/crypto.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h index 6f66db26..208c1e57 100644 --- a/include/opendht/crypto.h +++ b/include/opendht/crypto.h @@ -283,6 +283,7 @@ public: bool verify() const; Blob pack() const; + std::string toString() const; gnutls_x509_crq_t get() const { return request; } private: diff --git a/src/crypto.cpp b/src/crypto.cpp index 5e0e92e9..cad426b2 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -703,6 +703,17 @@ CertificateRequest::pack() const return ret; } +std::string +CertificateRequest::toString() const +{ + gnutls_datum_t dat {nullptr, 0}; + if (auto err = gnutls_x509_crq_export2(request, GNUTLS_X509_FMT_PEM, &dat)) + throw CryptoException(std::string("Can't export certificate request: ") + gnutls_strerror(err)); + std::string ret(dat.data, dat.data + dat.size); + gnutls_free(dat.data); + return ret; +} + // Certificate static std::string -- GitLab