crypto: add Certificate::toString

This commit is contained in:
Adrien Béraud committed 2015-02-26 10:36:14 -05:00
1 parent 13902b0f19
commit 6e01255bc0
2 files changed
+20 -1

No files matched your search

+6 -1
View File
@@ -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;
+14
View File
@@ -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)
{