aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Brown <ericwb@users.noreply.github.com>2018-05-14 20:47:57 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2018-05-14 23:47:57 -0400
commit50bad375f5dd3fbb7c7ea62896e2538dc5734be6 (patch)
tree2ae4a8d5b9576012069ce28ae08ebc575129fdd6 /src
parentb2165c2ef0fdf8d63c3b4780648266e37d39df2d (diff)
downloadcryptography-50bad375f5dd3fbb7c7ea62896e2538dc5734be6.tar.gz
cryptography-50bad375f5dd3fbb7c7ea62896e2538dc5734be6.tar.bz2
cryptography-50bad375f5dd3fbb7c7ea62896e2538dc5734be6.zip
Future proofing use of the six python version constants (#4238)
* Future proofing use of the six python version constants After reading [1], noticed that cryptography uses a lot of if six.PY3 blocks. The issue with this is that whenever Python 4 is released, this code in the else block will be executed even though it was only intended for Python 2. [1] http://astrofrog.github.io/blog/2016/01/12/stop-writing-python-4-incompatible-code/ Signed-off-by: Eric Brown <browne@vmware.com> * Use not PY2 instead
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index 0b7550e5..af14bfaa 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -298,7 +298,7 @@ class Backend(object):
def _bn_to_int(self, bn):
assert bn != self._ffi.NULL
- if six.PY3:
+ if not six.PY2:
# Python 3 has constant time from_bytes, so use that.
bn_num_bytes = self._lib.BN_num_bytes(bn)
bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes)
@@ -326,7 +326,7 @@ class Backend(object):
if bn is None:
bn = self._ffi.NULL
- if six.PY3:
+ if not six.PY2:
# Python 3 has constant time to_bytes, so use that.
binary = num.to_bytes(int(num.bit_length() / 8.0 + 1), "big")