diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2016-01-08 00:18:58 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2016-01-08 00:18:58 -0500 |
commit | bbeb555933abb17b231c95f6ea0780910326b11a (patch) | |
tree | 28a3682654e79fcd54e347d3101b6c1588cbbd75 | |
parent | 952df2ffa4723b390b47205ea932b413a65405fd (diff) | |
parent | 449befa9fb6cbcb73bd9dff8636c883e9d4e7e4e (diff) | |
download | cryptography-bbeb555933abb17b231c95f6ea0780910326b11a.tar.gz cryptography-bbeb555933abb17b231c95f6ea0780910326b11a.tar.bz2 cryptography-bbeb555933abb17b231c95f6ea0780910326b11a.zip |
Merge pull request #2648 from reaperhulk/cleanup
small cleanup to reduce code duplication for EVP_PKEY_new calls
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/backend.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index e8b0322e..3c615e87 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -1022,10 +1022,14 @@ class Backend(object): return _RSAPublicKey(self, rsa_cdata, evp_pkey) - def _rsa_cdata_to_evp_pkey(self, rsa_cdata): + def _create_evp_pkey_gc(self): evp_pkey = self._lib.EVP_PKEY_new() self.openssl_assert(evp_pkey != self._ffi.NULL) evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free) + return evp_pkey + + def _rsa_cdata_to_evp_pkey(self, rsa_cdata): + evp_pkey = self._create_evp_pkey_gc() res = self._lib.EVP_PKEY_set1_RSA(evp_pkey, rsa_cdata) self.openssl_assert(res == 1) return evp_pkey @@ -1249,9 +1253,7 @@ class Backend(object): return _DSAParameters(self, dsa_cdata) def _dsa_cdata_to_evp_pkey(self, dsa_cdata): - evp_pkey = self._lib.EVP_PKEY_new() - self.openssl_assert(evp_pkey != self._ffi.NULL) - evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free) + evp_pkey = self._create_evp_pkey_gc() res = self._lib.EVP_PKEY_set1_DSA(evp_pkey, dsa_cdata) self.openssl_assert(res == 1) return evp_pkey @@ -1976,9 +1978,7 @@ class Backend(object): ) def _ec_cdata_to_evp_pkey(self, ec_cdata): - evp_pkey = self._lib.EVP_PKEY_new() - self.openssl_assert(evp_pkey != self._ffi.NULL) - evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free) + evp_pkey = self._create_evp_pkey_gc() res = self._lib.EVP_PKEY_set1_EC_KEY(evp_pkey, ec_cdata) self.openssl_assert(res == 1) return evp_pkey |