aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/utils.py
diff options
context:
space:
mode:
authorOfek Lev <ofekmeister@gmail.com>2016-12-02 23:37:55 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2016-12-02 23:37:55 -0500
commit56aae486666c552dc8e0b3a864387b535807c3a7 (patch)
tree5833f219c0bc7270bc76a7aee4b109a39f1d8cea /src/cryptography/utils.py
parentf7e12193e92ca491af5d5a26e3f503770c4c346a (diff)
downloadcryptography-56aae486666c552dc8e0b3a864387b535807c3a7.tar.gz
cryptography-56aae486666c552dc8e0b3a864387b535807c3a7.tar.bz2
cryptography-56aae486666c552dc8e0b3a864387b535807c3a7.zip
clean up int_from_bytes (#3295)
* clean up int_from_bytes 7x speed-up and code is more readable * remove unused import * rely on py2 built-in codecs
Diffstat (limited to 'src/cryptography/utils.py')
-rw-r--r--src/cryptography/utils.py14
1 files changed, 1 insertions, 13 deletions
diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py
index 159d1ded..6fda2cc1 100644
--- a/src/cryptography/utils.py
+++ b/src/cryptography/utils.py
@@ -7,7 +7,6 @@ from __future__ import absolute_import, division, print_function
import abc
import binascii
import inspect
-import struct
import sys
import warnings
@@ -48,18 +47,7 @@ else:
assert byteorder == 'big'
assert not signed
- if len(data) % 4 != 0:
- data = (b'\x00' * (4 - (len(data) % 4))) + data
-
- result = 0
-
- while len(data) > 0:
- digit, = struct.unpack('>I', data[:4])
- result = (result << 32) + digit
- # TODO: this is quadratic in the length of data
- data = data[4:]
-
- return result
+ return int(data.encode('hex'), 16)
def int_to_bytes(integer, length=None):