aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-12-21 11:35:51 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2015-12-21 11:35:51 -0500
commita04e032be907759af8d5b838fc94d581c49b484a (patch)
tree8410ea4591acccad1ce1f810c13c350279ea82d1 /tests
parent394cca58a7dbd7e34d111f8c78a8f2dabda3a4b3 (diff)
parent2c91858de5fca63ee56b342d44fee73ed220d547 (diff)
downloadcryptography-a04e032be907759af8d5b838fc94d581c49b484a.tar.gz
cryptography-a04e032be907759af8d5b838fc94d581c49b484a.tar.bz2
cryptography-a04e032be907759af8d5b838fc94d581c49b484a.zip
Merge pull request #2541 from reaperhulk/crl-serialization
add a CRL public_bytes method
Diffstat (limited to 'tests')
-rw-r--r--tests/test_x509.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_x509.py b/tests/test_x509.py
index 511aac6b..27ce21e2 100644
--- a/tests/test_x509.py
+++ b/tests/test_x509.py
@@ -222,6 +222,72 @@ class TestCertificateRevocationList(object):
verifier.update(crl.tbs_certlist_bytes)
verifier.verify()
+ def test_public_bytes_pem(self, backend):
+ crl = _load_cert(
+ os.path.join("x509", "custom", "crl_empty.pem"),
+ x509.load_pem_x509_crl,
+ backend
+ )
+
+ # Encode it to PEM and load it back.
+ crl = x509.load_pem_x509_crl(crl.public_bytes(
+ encoding=serialization.Encoding.PEM,
+ ), backend)
+
+ assert len(crl) == 0
+ assert crl.last_update == datetime.datetime(2015, 12, 20, 23, 44, 47)
+ assert crl.next_update == datetime.datetime(2015, 12, 28, 0, 44, 47)
+
+ def test_public_bytes_der(self, backend):
+ crl = _load_cert(
+ os.path.join("x509", "custom", "crl_all_reasons.pem"),
+ x509.load_pem_x509_crl,
+ backend
+ )
+
+ # Encode it to DER and load it back.
+ crl = x509.load_der_x509_crl(crl.public_bytes(
+ encoding=serialization.Encoding.DER,
+ ), backend)
+
+ assert len(crl) == 12
+ assert crl.last_update == datetime.datetime(2015, 1, 1, 0, 0, 0)
+ assert crl.next_update == datetime.datetime(2016, 1, 1, 0, 0, 0)
+
+ @pytest.mark.parametrize(
+ ("cert_path", "loader_func", "encoding"),
+ [
+ (
+ os.path.join("x509", "custom", "crl_all_reasons.pem"),
+ x509.load_pem_x509_crl,
+ serialization.Encoding.PEM,
+ ),
+ (
+ os.path.join("x509", "PKITS_data", "crls", "GoodCACRL.crl"),
+ x509.load_der_x509_crl,
+ serialization.Encoding.DER,
+ ),
+ ]
+ )
+ def test_public_bytes_match(self, cert_path, loader_func, encoding,
+ backend):
+ crl_bytes = load_vectors_from_file(
+ cert_path, lambda pemfile: pemfile.read(), mode="rb"
+ )
+ crl = loader_func(crl_bytes, backend)
+ serialized = crl.public_bytes(encoding)
+ assert serialized == crl_bytes
+
+ def test_public_bytes_invalid_encoding(self, backend):
+ crl = _load_cert(
+ os.path.join("x509", "custom", "crl_empty.pem"),
+ x509.load_pem_x509_crl,
+ backend
+ )
+
+ with pytest.raises(TypeError):
+ crl.public_bytes('NotAnEncoding')
+
@pytest.mark.requires_backend_interface(interface=X509Backend)
class TestRevokedCertificate(object):