summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2020-02-15 16:10:52 +0300
committerSergey Matveev <stargrave@stargrave.org>2020-02-16 21:25:49 +0300
commite22c7873e381492d705af5d880bf84296d03707f (patch)
tree6054eba6991d78e37028a37aa468b1d37d33ed8a
parente83a585f513b694f5f953fab15e5419e837dda7b (diff)
downloadpyderasn-e22c7873e381492d705af5d880bf84296d03707f.tar.xz
Check for evgen upto mode
-rw-r--r--tests/test_crl.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/test_crl.py b/tests/test_crl.py
index 7069230..a5c7183 100644
--- a/tests/test_crl.py
+++ b/tests/test_crl.py
@@ -70,10 +70,14 @@ class CertificateList(Sequence):
("signatureValue", BitString()),
)
-@skipIf(not exists("revoke.crl"), "CACert's revoke.crl not found")
+
+CRL_PATH = "revoke.crl"
+
+
+@skipIf(not exists(CRL_PATH), "CACert's revoke.crl not found")
class TestCACert(TestCase):
def test_cer(self):
- with open("revoke.crl", "rb") as fd:
+ with open(CRL_PATH, "rb") as fd:
raw = fd.read()
print("DER read")
start = time()
@@ -93,7 +97,36 @@ class TestCACert(TestCase):
@skipIf(PY2, "Py27 mmap does not implement buffer protocol")
def test_mmaped(self):
- fd = open("revoke.crl", "rb")
+ fd = open(CRL_PATH, "rb")
start = time()
CertificateList().decod(file_mmaped(fd))
print("DER decoded", time() - start)
+
+ def test_evgens(self):
+ fd = open(CRL_PATH, "rb")
+ raw = memoryview(fd.read()) if PY2 else file_mmaped(fd)
+ print("CRL opened")
+ evgens_count = 0
+ revoked_certs_count = 0
+ start = time()
+ for decode_path, _, _ in CertificateList().decode_evgen(raw):
+ evgens_count += 1
+ if (
+ len(decode_path) == 3 and
+ decode_path[:2] == ("tbsCertList", "revokedCertificates")
+ ):
+ revoked_certs_count += 1
+ print("CRL parsed", time() - start)
+ evgens_upto_count = 0
+ start = time()
+ for decode_path, _, _ in CertificateList().decode_evgen(raw, ctx={
+ "evgen_mode_upto": (
+ (("tbsCertList", "revokedCertificates", any), True),
+ ),
+ }):
+ evgens_upto_count += 1
+ print("CRL upto parsed", time() - start)
+ self.assertEqual(
+ float(evgens_count - evgens_upto_count) / revoked_certs_count,
+ 3,
+ )