aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py12
-rw-r--r--src/cryptography/x509.py6
2 files changed, 18 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..e6d19ae7 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -1167,6 +1167,12 @@ class Certificate(object):
Checks not equal.
"""
+ @abc.abstractmethod
+ def public_bytes(self, encoding):
+ """
+ Serializes the certificate to PEM or DER format.
+ """
+
@six.add_metaclass(abc.ABCMeta)
class CertificateSigningRequest(object):