aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2014-12-14 22:31:29 -0600
committerMark Adams <mark@markadams.me>2014-12-14 22:31:29 -0600
commitcbddc9897b579f1b44e0c4cd5cd868fa7c6dd06d (patch)
tree25f5df1fd71deddeac1b4202e6105a0dba5b8967
parentc3e8b8890585d82bf19ac642756c5c4baac74237 (diff)
downloadcryptography-cbddc9897b579f1b44e0c4cd5cd868fa7c6dd06d.tar.gz
cryptography-cbddc9897b579f1b44e0c4cd5cd868fa7c6dd06d.tar.bz2
cryptography-cbddc9897b579f1b44e0c4cd5cd868fa7c6dd06d.zip
Added optimization for Python 3 to use int.from_bytes instead of Python code
-rw-r--r--src/cryptography/hazmat/primitives/serialization.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cryptography/hazmat/primitives/serialization.py b/src/cryptography/hazmat/primitives/serialization.py
index 455c8a91..8a4c8bd8 100644
--- a/src/cryptography/hazmat/primitives/serialization.py
+++ b/src/cryptography/hazmat/primitives/serialization.py
@@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function
import base64
import struct
+import sys
import warnings
from cryptography import utils
@@ -88,10 +89,15 @@ def _read_next_string(data):
def _read_next_mpint(data):
+ """Reads the next mpint from the data. Currently, all mpints are
+ interpreted as unsigned."""
mpint_data, rest = _read_next_string(data)
+ if sys.version_info >= (3, 2):
+ # If we're using >= 3.2, use int.from_bytes for identical results.
+ return int.from_bytes(mpint_data, byteorder='big', signed=False), rest
+
if len(mpint_data) % 4 != 0:
- # Pad the bytes with 0x00 to a block size of 4
mpint_data = (b'\x00' * (4 - (len(mpint_data) % 4))) + mpint_data
result = 0