X-Git-Url: http://www.git.cypherpunks.ru/?p=pyderasn.git;a=blobdiff_plain;f=tests%2Ftest_cms.py;h=fb455803925ec43e01e8674b2ecde49862e42bd4;hp=51bdaf1cbf26adb3d2843d9481d8c36766032eb3;hb=HEAD;hpb=659eb0e090ad8c9209c4e5b030806125509844f9 diff --git a/tests/test_cms.py b/tests/test_cms.py index 51bdaf1..fb45580 100644 --- a/tests/test_cms.py +++ b/tests/test_cms.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-2024 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 @@ -31,8 +31,6 @@ from unittest import TestCase from hypothesis import given from hypothesis import settings from hypothesis.strategies import integers -from six import PY2 -from six.moves import xrange as six_xrange from pyderasn import agg_octet_string from pyderasn import Any @@ -83,7 +81,7 @@ class SignatureAlgorithmIdentifier(AlgorithmIdentifier): class SignedAttributes(SetOf): schema = Attribute() - bounds = (1, 32) + bounds = (1, float("+inf")) der_forced = True @@ -285,7 +283,7 @@ class TestSignedDataCERWithOpenSSL(TestCase): ci.encode_cer(fd.write) self.verify(cert_path, cms_path) fd = open(cms_path, "rb") - raw = memoryview(fd.read()) if PY2 else file_mmaped(fd) + raw = file_mmaped(fd) ctx = {"bered": True} for decode_path, obj, _ in ContentInfo().decode_evgen(raw, ctx=ctx): if decode_path == ("content",): @@ -294,19 +292,19 @@ class TestSignedDataCERWithOpenSSL(TestCase): buf = BytesIO() agg_octet_string(evgens, ("encapContentInfo", "eContent"), raw, buf.write) self.assertSequenceEqual(buf.getvalue(), data) + fd.close() def create_huge_file(self): rnd = urandom(1<<20) data_path = self.tmpfile() start = time() with open(data_path, "wb") as fd: - for _ in six_xrange(int(environ.get("PYDERASN_TEST_CMS_HUGE"))): + for _ in range(int(environ.get("PYDERASN_TEST_CMS_HUGE"))): # dgst.update(rnd) fd.write(rnd) print("data file written", time() - start) return file_mmaped(open(data_path, "rb")) - @skipIf(PY2, "no mmaped memoryview support in PY2") @skipIf("PYDERASN_TEST_CMS_HUGE" not in environ, "PYDERASN_TEST_CMS_HUGE is not set") def test_huge_cer(self): """Huge CMS test @@ -318,7 +316,7 @@ class TestSignedDataCERWithOpenSSL(TestCase): """ data_raw = self.create_huge_file() key_path, cert_path, cert, skid = self.keypair() - from sys import getallocatedblocks # PY2 does not have it + from sys import getallocatedblocks mem_start = getallocatedblocks() start = time() eci = EncapsulatedContentInfo(( @@ -382,8 +380,8 @@ class TestSignedDataCERWithOpenSSL(TestCase): ci.encode_cer(fd.write) print("CMS written", time() - start) self.verify(cert_path, cms_path) + eci_fd.close() - @skipIf(PY2, "no mmaped memoryview support in PY2") @skipIf("PYDERASN_TEST_CMS_HUGE" not in environ, "PYDERASN_TEST_CMS_HUGE is not set") def test_huge_der_2pass(self): """Same test as above, but 2pass DER encoder and just signature verification