From 50bad375f5dd3fbb7c7ea62896e2538dc5734be6 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Mon, 14 May 2018 20:47:57 -0700 Subject: 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 * Use not PY2 instead --- src/cryptography/hazmat/backends/openssl/backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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") -- cgit v1.2.3