diff options
author | wbond <will@wbond.net> | 2020-07-25 10:50:19 -0400 |
---|---|---|
committer | wbond <will@wbond.net> | 2020-07-25 10:50:19 -0400 |
commit | c79ce16b194c5592ab2f45bb9f5052b614a607a1 (patch) | |
tree | d12da7e8ee7fa7656899bb69f5f85e5a2ccbc787 | |
parent | 704889494451461ffdb75d192c2a2db1258660db (diff) | |
download | asn1crypto-c79ce16b194c5592ab2f45bb9f5052b614a607a1.tar.gz |
Ensure keys.PublicKeyInfo.bit_size returns an int
-rw-r--r-- | asn1crypto/keys.py | 2 | ||||
-rw-r--r-- | tests/test_keys.py | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/asn1crypto/keys.py b/asn1crypto/keys.py index 599929f..96b763e 100644 --- a/asn1crypto/keys.py +++ b/asn1crypto/keys.py @@ -1216,7 +1216,7 @@ class PublicKeyInfo(Sequence): if self._bit_size is None: if self.algorithm == 'ec': - self._bit_size = ((len(self['public_key'].native) - 1) / 2) * 8 + self._bit_size = int(((len(self['public_key'].native) - 1) / 2) * 8) else: if self.algorithm == 'rsa': prime = self['public_key'].parsed['modulus'].native diff --git a/tests/test_keys.py b/tests/test_keys.py index 2f2856e..cfdfa0b 100644 --- a/tests/test_keys.py +++ b/tests/test_keys.py @@ -1,8 +1,9 @@ # coding: utf-8 from __future__ import unicode_literals, division, absolute_import, print_function -import unittest import os +import sys +import unittest from asn1crypto import keys, core, util @@ -11,6 +12,11 @@ from ._unittest_compat import patch patch() +if sys.version_info < (3,): + num_cls = long # noqa +else: + num_cls = int + tests_root = os.path.dirname(__file__) fixtures_dir = os.path.join(tests_root, 'fixtures') @@ -481,7 +487,9 @@ class KeysTests(unittest.TestCase): with open(os.path.join(fixtures_dir, public_key_file), 'rb') as f: public_key = keys.PublicKeyInfo.load(f.read()) + self.assertIsInstance(private_key.bit_size, num_cls) self.assertEqual(bit_size, private_key.bit_size) + self.assertIsInstance(public_key.bit_size, num_cls) self.assertEqual(bit_size, public_key.bit_size) @staticmethod |