X-Git-Url: http://www.git.cypherpunks.ru/?p=pyderasn.git;a=blobdiff_plain;f=tests%2Ftest_crl.py;h=2779fd87cee183b1d0140adc412ec908f7c64b7a;hp=fcfcb9e379ab92d001dad67ceacc235e5735b0aa;hb=b54295efb44566cd7eb6b09a4d5366f82cb96441;hpb=42198ee69940c96930d81533ecf9cec87d34b27b diff --git a/tests/test_crl.py b/tests/test_crl.py index fcfcb9e..2779fd8 100644 --- a/tests/test_crl.py +++ b/tests/test_crl.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyDERASN -- Python ASN.1 DER/CER/BER codec with abstract structures -# Copyright (C) 2017-2020 Sergey Matveev +# Copyright (C) 2017-2022 Sergey Matveev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as @@ -17,13 +17,13 @@ """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 -from six import PY2 - from pyderasn import BitString from pyderasn import encode_cer from pyderasn import file_mmaped @@ -76,7 +76,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,18 +84,24 @@ 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): fd = open(CRL_PATH, "rb") start = time() @@ -104,7 +110,7 @@ class TestCACert(TestCase): def test_evgens(self): fd = open(CRL_PATH, "rb") - raw = memoryview(fd.read()) if PY2 else file_mmaped(fd) + raw = file_mmaped(fd) print("CRL opened") evgens_count = 0 revoked_certs_count = 0