aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndre Caron <andre.l.caron@gmail.com>2015-05-19 20:11:57 -0400
committerAndre Caron <andre.l.caron@gmail.com>2015-05-19 21:20:58 -0400
commita8aded6346b8016d8f9e7e5d2ad75319dd69dcbb (patch)
tree4274562bc948423c2a77ff35f3f6cf4ef871d643 /src
parentc5db584e727c180b7d426bd13675a8e0d0980dd3 (diff)
downloadcryptography-a8aded6346b8016d8f9e7e5d2ad75319dd69dcbb.tar.gz
cryptography-a8aded6346b8016d8f9e7e5d2ad75319dd69dcbb.tar.bz2
cryptography-a8aded6346b8016d8f9e7e5d2ad75319dd69dcbb.zip
Adds certificate encoding to PEM and DER.
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py12
-rw-r--r--src/cryptography/x509.py4
2 files changed, 16 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 72041366..c7d2d154 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -311,6 +311,18 @@ class _Certificate(object):
return x509.Extensions(extensions)
+ def public_bytes(self, encoding):
+ if not isinstance(encoding, serialization.Encoding):
+ raise TypeError("encoding must be an item from the Encoding enum")
+
+ bio = self._backend._create_mem_bio()
+ if encoding is serialization.Encoding.PEM:
+ res = self._backend._lib.PEM_write_bio_X509(bio, self._x509)
+ elif encoding is serialization.Encoding.DER:
+ res = self._backend._lib.i2d_X509_bio(bio, self._x509)
+ assert res == 1
+ return self._backend._read_mem_bio(bio)
+
def _decode_certificate_policies(backend, ext):
cp = backend._ffi.cast(
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 9a3295ce..a786c705 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -1167,6 +1167,10 @@ class Certificate(object):
Checks not equal.
"""
+ @abc.abstractmethod
+ def public_bytes(self, encoding):
+ pass
+
@six.add_metaclass(abc.ABCMeta)
class CertificateSigningRequest(object):