diff options
author | David Reid <dreid@dreid.org> | 2014-07-10 13:21:25 -0700 |
---|---|---|
committer | David Reid <dreid@dreid.org> | 2014-07-10 13:21:25 -0700 |
commit | 3be364eb24dc31c0a90019f71edc72f9babebb98 (patch) | |
tree | 11c56a50f56d77a9dea1fe11e35b3e74e161a1f1 | |
parent | 32989282ff36de4d000afe71484c5711c9619faa (diff) | |
parent | 209c2f3fa85358e27264aecfe2daa55131c2caa3 (diff) | |
download | cryptography-3be364eb24dc31c0a90019f71edc72f9babebb98.tar.gz cryptography-3be364eb24dc31c0a90019f71edc72f9babebb98.tar.bz2 cryptography-3be364eb24dc31c0a90019f71edc72f9babebb98.zip |
Merge pull request #1249 from alex/factor-key-loading
Factor out the key loading logic to make it easier to have other key loading schemes
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index da52799c..0d71818f 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -766,11 +766,19 @@ class Backend(object): return self.load_pkcs8_pem_private_key(data, password) def load_pkcs8_pem_private_key(self, data, password): + return self._load_key( + self._lib.PEM_read_bio_PrivateKey, + self._evp_pkey_to_private_key, + data, + password, + ) + + def _load_key(self, openssl_read_func, convert_func, data, password): mem_bio = self._bytes_to_bio(data) password_callback, password_func = self._pem_password_cb(password) - evp_pkey = self._lib.PEM_read_bio_PrivateKey( + evp_pkey = openssl_read_func( mem_bio.bio, self._ffi.NULL, password_callback, @@ -791,7 +799,7 @@ class Backend(object): password is None ) - return self._evp_pkey_to_private_key(evp_pkey) + return convert_func(evp_pkey) def _handle_key_loading_error(self, password): errors = self._consume_errors() |