diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-01-18 10:38:28 -0500 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-01-18 10:38:28 -0500 |
commit | 6922a86ff69b80e406f096716dc0a43413546e50 (patch) | |
tree | e399a92d79a5243efed9e4241572f94debfad088 | |
parent | de0754690e01202bb4bd7e47c529db87765fc805 (diff) | |
download | pyopenssl-6922a86ff69b80e406f096716dc0a43413546e50.tar.gz |
Allow unicode as well as bytes in all the load APIs as well
-rw-r--r-- | OpenSSL/crypto.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py index 7dc31c8..918d33d 100644 --- a/OpenSSL/crypto.py +++ b/OpenSSL/crypto.py @@ -1202,6 +1202,9 @@ def load_certificate(type, buffer): :return: The X509 object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) if type == FILETYPE_PEM: @@ -1988,6 +1991,9 @@ def load_privatekey(type, buffer, passphrase=None): :return: The PKey object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) helper = _PassphraseHelper(type, passphrase) @@ -2044,6 +2050,9 @@ def load_certificate_request(type, buffer): :param buffer: The buffer the certificate request is stored in :return: The X509Req object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) if type == FILETYPE_PEM: @@ -2137,6 +2146,9 @@ def load_crl(type, buffer): :return: The PKey object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) if type == FILETYPE_PEM: @@ -2163,6 +2175,9 @@ def load_pkcs7_data(type, buffer): :param buffer: The buffer with the pkcs7 data. :return: The PKCS7 object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) if type == FILETYPE_PEM: @@ -2191,6 +2206,9 @@ def load_pkcs12(buffer, passphrase): :param passphrase: (Optional) The password to decrypt the PKCS12 lump :returns: The PKCS12 object """ + if isinstance(buffer, _text_type): + buffer = buffer.encode("ascii") + bio = _new_mem_buf(buffer) p12 = _lib.d2i_PKCS12_bio(bio, _ffi.NULL) |