aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-03-29 08:53:09 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-03-29 08:53:09 -0500
commit29699f12e150e51ad051243963f6bdcc80ce96f2 (patch)
treef0cad27ad81677a27fe95d0189133f212fdb7bdc
parent43f49de4fb7e878e8ff7bb5c49cef8bbddb65e3f (diff)
parentc91ac82cdda63b50b1d6ab8c1f84ccd3183fab08 (diff)
downloadcryptography-29699f12e150e51ad051243963f6bdcc80ce96f2.tar.gz
cryptography-29699f12e150e51ad051243963f6bdcc80ce96f2.tar.bz2
cryptography-29699f12e150e51ad051243963f6bdcc80ce96f2.zip
Merge pull request #1796 from rev112/minor_refactorings
Minor refactorings
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py26
-rw-r--r--src/cryptography/hazmat/backends/openssl/utils.py2
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py2
3 files changed, 15 insertions, 15 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index 6cc3fd91..854219f7 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -477,20 +477,20 @@ class Backend(object):
pointer.
"""
- type = evp_pkey.type
+ key_type = evp_pkey.type
- if type == self._lib.EVP_PKEY_RSA:
+ if key_type == self._lib.EVP_PKEY_RSA:
rsa_cdata = self._lib.EVP_PKEY_get1_RSA(evp_pkey)
assert rsa_cdata != self._ffi.NULL
rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
return _RSAPrivateKey(self, rsa_cdata)
- elif type == self._lib.EVP_PKEY_DSA:
+ elif key_type == self._lib.EVP_PKEY_DSA:
dsa_cdata = self._lib.EVP_PKEY_get1_DSA(evp_pkey)
assert dsa_cdata != self._ffi.NULL
dsa_cdata = self._ffi.gc(dsa_cdata, self._lib.DSA_free)
return _DSAPrivateKey(self, dsa_cdata)
elif (self._lib.Cryptography_HAS_EC == 1 and
- type == self._lib.EVP_PKEY_EC):
+ key_type == self._lib.EVP_PKEY_EC):
ec_cdata = self._lib.EVP_PKEY_get1_EC_KEY(evp_pkey)
assert ec_cdata != self._ffi.NULL
ec_cdata = self._ffi.gc(ec_cdata, self._lib.EC_KEY_free)
@@ -504,20 +504,20 @@ class Backend(object):
pointer.
"""
- type = evp_pkey.type
+ key_type = evp_pkey.type
- if type == self._lib.EVP_PKEY_RSA:
+ if key_type == self._lib.EVP_PKEY_RSA:
rsa_cdata = self._lib.EVP_PKEY_get1_RSA(evp_pkey)
assert rsa_cdata != self._ffi.NULL
rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
return _RSAPublicKey(self, rsa_cdata)
- elif type == self._lib.EVP_PKEY_DSA:
+ elif key_type == self._lib.EVP_PKEY_DSA:
dsa_cdata = self._lib.EVP_PKEY_get1_DSA(evp_pkey)
assert dsa_cdata != self._ffi.NULL
dsa_cdata = self._ffi.gc(dsa_cdata, self._lib.DSA_free)
return _DSAPublicKey(self, dsa_cdata)
elif (self._lib.Cryptography_HAS_EC == 1 and
- type == self._lib.EVP_PKEY_EC):
+ key_type == self._lib.EVP_PKEY_EC):
ec_cdata = self._lib.EVP_PKEY_get1_EC_KEY(evp_pkey)
assert ec_cdata != self._ffi.NULL
ec_cdata = self._ffi.gc(ec_cdata, self._lib.EC_KEY_free)
@@ -671,7 +671,7 @@ class Backend(object):
def dsa_parameters_supported(self, p, q, g):
if self._lib.OPENSSL_VERSION_NUMBER < 0x1000000f:
- return (utils.bit_length(p) <= 1024 and utils.bit_length(q) <= 160)
+ return utils.bit_length(p) <= 1024 and utils.bit_length(q) <= 160
else:
return True
@@ -1219,13 +1219,13 @@ class Backend(object):
assert res == 1
return self._read_mem_bio(bio)
- def _private_key_bytes_traditional_der(self, type, cdata):
- if type == self._lib.EVP_PKEY_RSA:
+ def _private_key_bytes_traditional_der(self, key_type, cdata):
+ if key_type == self._lib.EVP_PKEY_RSA:
write_bio = self._lib.i2d_RSAPrivateKey_bio
elif (self._lib.Cryptography_HAS_EC == 1 and
- type == self._lib.EVP_PKEY_EC):
+ key_type == self._lib.EVP_PKEY_EC):
write_bio = self._lib.i2d_ECPrivateKey_bio
- elif type == self._lib.EVP_PKEY_DSA:
+ elif key_type == self._lib.EVP_PKEY_DSA:
write_bio = self._lib.i2d_DSAPrivateKey_bio
bio = self._create_mem_bio()
diff --git a/src/cryptography/hazmat/backends/openssl/utils.py b/src/cryptography/hazmat/backends/openssl/utils.py
index 498c100d..001121f9 100644
--- a/src/cryptography/hazmat/backends/openssl/utils.py
+++ b/src/cryptography/hazmat/backends/openssl/utils.py
@@ -16,7 +16,7 @@ def _truncate_digest(digest, order_bits):
if 8 * digest_len > order_bits:
rshift = 8 - (order_bits & 0x7)
- assert rshift > 0 and rshift < 8
+ assert 0 < rshift < 8
mask = 0xFF >> rshift << rshift
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 2b66c21e..6a7032ba 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -45,7 +45,7 @@ def _build_x509_name(backend, x509_name):
assert res >= 0
assert buf[0] != backend._ffi.NULL
buf = backend._ffi.gc(
- buf, lambda buf: backend._lib.OPENSSL_free(buf[0])
+ buf, lambda buffer: backend._lib.OPENSSL_free(buffer[0])
)
value = backend._ffi.buffer(buf[0], res)[:].decode('utf8')
oid = _obj2txt(backend, obj)