diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2017-06-25 16:28:24 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2017-06-25 10:28:24 -1000 |
commit | 9939ba1658868b68654501aac24c97db8d9335ae (patch) | |
tree | 46d036201c23060762b1044f89289f32e7e10c0d /tests | |
parent | f8022d6a1d315ebcfe6cc25ae07dd8d3bd0cf1b4 (diff) | |
download | pyopenssl-git-9939ba1658868b68654501aac24c97db8d9335ae.tar.gz |
Added an API for converting X509 to/from cryptography (#640)
* Added an API for converting X509 to/from cryptography
* changelog
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_crypto.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 5efb904..2bcc933 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -17,6 +17,7 @@ import pytest from six import binary_type +from cryptography import x509 from cryptography.hazmat.backends.openssl.backend import backend from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa @@ -1922,6 +1923,26 @@ tgI5 with pytest.raises(TypeError): cert.sign(object(), b"sha256") + def test_convert_from_cryptography(self): + crypto_cert = x509.load_pem_x509_certificate( + intermediate_cert_pem, backend + ) + cert = X509.from_cryptography(crypto_cert) + + assert isinstance(cert, X509) + assert cert.get_version() == crypto_cert.version.value + + def test_convert_from_cryptography_unsupported_type(self): + with pytest.raises(TypeError): + X509.from_cryptography(object()) + + def test_convert_to_cryptography_key(self): + cert = load_certificate(FILETYPE_PEM, intermediate_cert_pem) + crypto_cert = cert.to_cryptography() + + assert isinstance(crypto_cert, x509.Certificate) + assert crypto_cert.version.value == cert.get_version() + class TestX509Store(object): """ |