From 31034a03227ebfe63f4025cd95137f116cd4236a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 11 Oct 2017 22:01:29 -0400 Subject: Inline calls to bit_length now that it's trivial (#3966) * Inline calls to bit_length now that it's trivial * unused imports * An comment --- tests/hazmat/backends/test_openssl.py | 6 +++--- tests/hazmat/primitives/test_dh.py | 4 ++-- tests/hazmat/primitives/test_dsa.py | 3 +-- tests/test_cryptography_utils.py | 5 +++++ tests/x509/test_x509.py | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 40e92853..e430e2d9 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -14,7 +14,7 @@ from pkg_resources import parse_version import pytest -from cryptography import utils, x509 +from cryptography import x509 from cryptography.exceptions import InternalError, _Reasons from cryptography.hazmat.backends.interfaces import DHBackend, RSABackend from cryptography.hazmat.backends.openssl.backend import ( @@ -141,10 +141,10 @@ class TestOpenSSL(object): def test_large_key_size_on_new_openssl(self): parameters = dsa.generate_parameters(2048, backend) param_num = parameters.parameter_numbers() - assert utils.bit_length(param_num.p) == 2048 + assert param_num.p.bit_length() == 2048 parameters = dsa.generate_parameters(3072, backend) param_num = parameters.parameter_numbers() - assert utils.bit_length(param_num.p) == 3072 + assert param_num.p.bit_length() == 3072 def test_int_to_bn(self): value = (2 ** 4242) - 4242 diff --git a/tests/hazmat/primitives/test_dh.py b/tests/hazmat/primitives/test_dh.py index 25be51c9..a70ae745 100644 --- a/tests/hazmat/primitives/test_dh.py +++ b/tests/hazmat/primitives/test_dh.py @@ -13,7 +13,7 @@ from cryptography.hazmat.backends.interfaces import ( DERSerializationBackend, DHBackend, PEMSerializationBackend) from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import dh -from cryptography.utils import bit_length, int_from_bytes +from cryptography.utils import int_from_bytes from ...doubles import DummyKeySerializationEncryption from ...utils import load_nist_vectors, load_vectors_from_file @@ -262,7 +262,7 @@ class TestDH(object): assert isinstance(parameters, dh.DHParametersWithSerialization) parameter_numbers = parameters.parameter_numbers() assert isinstance(parameter_numbers, dh.DHParameterNumbers) - assert bit_length(parameter_numbers.p) == key_size + assert parameter_numbers.p.bit_length() == key_size assert isinstance(public, dh.DHPublicKeyWithSerialization) assert isinstance(public.public_numbers(), dh.DHPublicNumbers) diff --git a/tests/hazmat/primitives/test_dsa.py b/tests/hazmat/primitives/test_dsa.py index 34197772..89303fed 100644 --- a/tests/hazmat/primitives/test_dsa.py +++ b/tests/hazmat/primitives/test_dsa.py @@ -18,7 +18,6 @@ from cryptography.hazmat.primitives.asymmetric import dsa from cryptography.hazmat.primitives.asymmetric.utils import ( Prehashed, encode_dss_signature ) -from cryptography.utils import bit_length from .fixtures_dsa import ( DSA_KEY_1024, DSA_KEY_2048, DSA_KEY_3072 @@ -82,7 +81,7 @@ class TestDSA(object): assert skey_parameters.p == vector['p'] assert skey_parameters.q == vector['q'] assert skey_parameters.g == vector['g'] - assert skey.key_size == bit_length(vector['p']) + assert skey.key_size == vector['p'].bit_length() assert pkey.key_size == skey.key_size public_numbers = pkey.public_numbers() assert numbers.public_numbers.y == public_numbers.y diff --git a/tests/test_cryptography_utils.py b/tests/test_cryptography_utils.py index 290e1612..320f7aa8 100644 --- a/tests/test_cryptography_utils.py +++ b/tests/test_cryptography_utils.py @@ -56,3 +56,8 @@ class TestCachedProperty(object): assert len(accesses) == 1 assert t.t == 14 assert len(accesses) == 1 + + +def test_bit_length(): + assert utils.bit_length(1) == 1 + assert utils.bit_length(11) == 4 diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index a07ffb3a..97b5a749 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -3981,4 +3981,4 @@ def test_random_serial_number(monkeypatch): assert ( serial_number == utils.int_from_bytes(sample_data, "big") >> 1 ) - assert utils.bit_length(serial_number) < 160 + assert serial_number.bit_length() < 160 -- cgit v1.2.3