summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp')
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp b/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
index 3f134e7..7f13f88 100644
--- a/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
+++ b/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
@@ -16,6 +16,25 @@
namespace Swift {
OpenSSLCertificate::OpenSSLCertificate(boost::shared_ptr<X509> cert) : cert(cert) {
+ parse();
+}
+
+
+OpenSSLCertificate::OpenSSLCertificate(const ByteArray& der) {
+ const unsigned char* p = reinterpret_cast<const unsigned char*>(der.getData());
+ cert = boost::shared_ptr<X509>(d2i_X509(NULL, &p, der.getSize()), X509_free);
+ parse();
+}
+
+ByteArray OpenSSLCertificate::toDER() const {
+ ByteArray result;
+ result.resize(i2d_X509(cert.get(), NULL));
+ unsigned char* p = reinterpret_cast<unsigned char*>(result.getData());
+ i2d_X509(cert.get(), &p);
+ return result;
+}
+
+void OpenSSLCertificate::parse() {
// Common name
X509_NAME* subjectName = X509_get_subject_name(cert.get());
if (subjectName) {