Skip to content
Snippets Groups Projects
Commit 6e01255b authored by Adrien Béraud's avatar Adrien Béraud
Browse files

crypto: add Certificate::toString

parent 13902b0f
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,7 @@ struct PrivateKey ...@@ -107,7 +107,7 @@ struct PrivateKey
/** /**
* Generate a new RSA key pair * Generate a new RSA key pair
* @param key_length : size of the modulus in bits * @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); static PrivateKey generate(unsigned key_length = 4096);
...@@ -139,6 +139,11 @@ struct Certificate : public Serializable { ...@@ -139,6 +139,11 @@ struct Certificate : public Serializable {
std::string getUID() const; std::string getUID() const;
/**
* PEM encoded certificate
*/
std::string toString() const;
gnutls_x509_crt_t cert {}; gnutls_x509_crt_t cert {};
private: private:
Certificate(const Certificate&) = delete; Certificate(const Certificate&) = delete;
......
...@@ -416,6 +416,20 @@ Certificate::getUID() const ...@@ -416,6 +416,20 @@ Certificate::getUID() const
return uid; 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
PrivateKey::generate(unsigned key_length) PrivateKey::generate(unsigned key_length)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment