mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
crypto: add Certificate::toString
This commit is contained in:
1 parent
13902b0f19
commit
6e01255bc0
2 files changed
+20
-1
No files matched your search
@@ -107,7 +107,7 @@ struct PrivateKey
|
||||
/**
|
||||
* Generate a new RSA key pair
|
||||
* @param key_length : size of the modulus in bits
|
||||
* Recommended values: 2048, 4096, 8192
|
||||
* Recommended values: 4096, 8192
|
||||
*/
|
||||
static PrivateKey generate(unsigned key_length = 4096);
|
||||
|
||||
@@ -139,6 +139,11 @@ struct Certificate : public Serializable {
|
||||
|
||||
std::string getUID() const;
|
||||
|
||||
/**
|
||||
* PEM encoded certificate
|
||||
*/
|
||||
std::string toString() const;
|
||||
|
||||
gnutls_x509_crt_t cert {};
|
||||
private:
|
||||
Certificate(const Certificate&) = delete;
|
||||
|
||||
@@ -416,6 +416,20 @@ Certificate::getUID() const
|
||||
return uid;
|
||||
}
|
||||
|
||||
std::string
|
||||
Certificate::toString() const
|
||||
{
|
||||
std::string str;
|
||||
size_t buf_sz = 8192;
|
||||
str.resize(buf_sz);
|
||||
int err = gnutls_x509_crt_export(cert, GNUTLS_X509_FMT_PEM, &(*str.begin()), &buf_sz);
|
||||
if (err != GNUTLS_E_SUCCESS) {
|
||||
std::cerr << "Could not export certificate - " << gnutls_strerror(err) << std::endl;
|
||||
}
|
||||
str.resize(buf_sz);
|
||||
return str;
|
||||
}
|
||||
|
||||
PrivateKey
|
||||
PrivateKey::generate(unsigned key_length)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user