Skip to content

Commit d2c1268

Browse files
alexreaperhulk
authored andcommitted
Fixes pyca#4076 - simplify the implementation of int_from_bytes on python2 (pyca#4077)
* Fixes pyca#4076 - simplify the implementation of int_from_bytes on python2 * whitespace * Added a test
1 parent 038146f commit d2c1268

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/cryptography/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def int_from_bytes(data, byteorder, signed=False):
5757
assert byteorder == 'big'
5858
assert not signed
5959

60-
# call bytes() on data to allow the use of bytearrays
61-
return int(bytes(data).encode('hex'), 16)
60+
return int(binascii.hexlify(data), 16)
6261

6362

6463
if hasattr(int, "to_bytes"):

tests/test_cryptography_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
def test_int_from_bytes_bytearray():
1313
assert utils.int_from_bytes(bytearray(b"\x02\x10"), "big") == 528
14+
with pytest.raises(TypeError):
15+
utils.int_from_bytes(["list", "is", "not", "bytes"], "big")
1416

1517

1618
class TestCachedProperty(object):

0 commit comments

Comments
 (0)