mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
crypto: add PublicKey::toString()
This commit is contained in:
1 parent
b3119cce13
commit
4176302a03
2 files changed
+18
No files matched your search
@@ -90,6 +90,8 @@ struct OPENDHT_PUBLIC PublicKey
|
||||
void pack(Blob& b) const;
|
||||
void unpack(const uint8_t* dat, size_t dat_size);
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& p) const
|
||||
{
|
||||
|
||||
@@ -426,6 +426,22 @@ PublicKey::unpack(const uint8_t* data, size_t data_size)
|
||||
throw CryptoException(std::string("Could not read public key: ") + gnutls_strerror(err));
|
||||
}
|
||||
|
||||
std::string
|
||||
PublicKey::toString() const
|
||||
{
|
||||
std::string ret;
|
||||
size_t sz = ret.size();
|
||||
int err = gnutls_pubkey_export(pk, GNUTLS_X509_FMT_PEM, (void*)ret.data(), &sz);
|
||||
if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) {
|
||||
ret.resize(sz);
|
||||
int err = gnutls_pubkey_export(pk, GNUTLS_X509_FMT_PEM, (void*)ret.data(), &sz);
|
||||
if (err != GNUTLS_E_SUCCESS)
|
||||
throw CryptoException(std::string("Could not print public key: ") + gnutls_strerror(err));
|
||||
} else if (err != GNUTLS_E_SUCCESS)
|
||||
throw CryptoException(std::string("Could not print public key: ") + gnutls_strerror(err));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
PublicKey::msgpack_unpack(msgpack::object o)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user