]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_crl.py
DER 2pass encoding
[pyderasn.git] / tests / test_crl.py
index fcfcb9e379ab92d001dad67ceacc235e5735b0aa..bb8748f4d97bfeb758f4d1b453faec88caddf38e 100644 (file)
@@ -17,7 +17,9 @@
 """CRL related schemas, just to test the performance with them
 """
 
+from io import BytesIO
 from os.path import exists
+from sys import getsizeof
 from time import time
 from unittest import skipIf
 from unittest import TestCase
@@ -76,7 +78,7 @@ CRL_PATH = "revoke.crl"
 
 @skipIf(not exists(CRL_PATH), "CACert's revoke.crl not found")
 class TestCACert(TestCase):
-    def test_cer(self):
+    def test_cer_and_2pass(self):
         with open(CRL_PATH, "rb") as fd:
             raw = fd.read()
         print("DER read")
@@ -84,16 +86,23 @@ class TestCACert(TestCase):
         crl1 = CertificateList().decod(raw)
         print("DER decoded", time() - start)
         start = time()
+        der_raw = crl1.encode()
+        print("DER encoded", time() - start)
+        self.assertSequenceEqual(der_raw, raw)
+        buf = BytesIO()
+        start = time()
+        _, state = crl1.encode1st()
+        print("1st pass state size", getsizeof(state))
+        crl1.encode2nd(buf.write, iter(state))
+        print("DER 2pass encoded", time() - start)
+        self.assertSequenceEqual(buf.getvalue(), raw)
+        start = time()
         cer_raw = encode_cer(crl1)
         print("CER encoded", time() - start)
         start = time()
         crl2 = CertificateList().decod(cer_raw, ctx={"bered": True})
         print("CER decoded", time() - start)
         self.assertEqual(crl2, crl1)
-        start = time()
-        der_raw = crl2.encode()
-        print("DER encoded", time() - start)
-        self.assertSequenceEqual(der_raw, raw)
 
     @skipIf(PY2, "Py27 mmap does not implement buffer protocol")
     def test_mmaped(self):