diff --git a/src/OpenSSL/SSL.py b/src/OpenSSL/SSL.py index 5f655f4cc..d4eb243e1 100644 --- a/src/OpenSSL/SSL.py +++ b/src/OpenSSL/SSL.py @@ -12,7 +12,7 @@ ffi as _ffi, lib as _lib, make_assert as _make_assert, - path_string as _path_string, + path_bytes as _path_bytes, text_to_bytes_and_warn as _text_to_bytes_and_warn, no_zero_allocator as _no_zero_allocator, ) @@ -781,12 +781,12 @@ def load_verify_locations(self, cafile, capath=None): if cafile is None: cafile = _ffi.NULL else: - cafile = _path_string(cafile) + cafile = _path_bytes(cafile) if capath is None: capath = _ffi.NULL else: - capath = _path_string(capath) + capath = _path_bytes(capath) load_result = _lib.SSL_CTX_load_verify_locations( self._context, cafile, capath @@ -920,7 +920,7 @@ def use_certificate_chain_file(self, certfile): :return: None """ - certfile = _path_string(certfile) + certfile = _path_bytes(certfile) result = _lib.SSL_CTX_use_certificate_chain_file( self._context, certfile @@ -940,7 +940,7 @@ def use_certificate_file(self, certfile, filetype=FILETYPE_PEM): :return: None """ - certfile = _path_string(certfile) + certfile = _path_bytes(certfile) if not isinstance(filetype, int): raise TypeError("filetype must be an integer") @@ -998,7 +998,7 @@ def use_privatekey_file(self, keyfile, filetype=_UNSPECIFIED): :return: None """ - keyfile = _path_string(keyfile) + keyfile = _path_bytes(keyfile) if filetype is _UNSPECIFIED: filetype = FILETYPE_PEM @@ -1169,7 +1169,7 @@ def load_tmp_dh(self, dhfile): :return: None """ - dhfile = _path_string(dhfile) + dhfile = _path_bytes(dhfile) bio = _lib.BIO_new_file(dhfile, b"r") if bio == _ffi.NULL: diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py index 028989dec..a3d50753c 100644 --- a/src/OpenSSL/_util.py +++ b/src/OpenSSL/_util.py @@ -71,21 +71,21 @@ def openssl_assert(ok): return openssl_assert -def path_string(s): +def path_bytes(s): """ - Convert a Python path to a :py:class:`bytes` string identifying the same - path and which can be passed into an OpenSSL API accepting a filename. + Convert a Python path to a :py:class:`bytes` for the path which can be + passed into an OpenSSL API accepting a filename. :param s: A path (valid for os.fspath). :return: An instance of :py:class:`bytes`. """ - strpath = os.fspath(s) # returns str or bytes + b = os.fspath(s) - if isinstance(strpath, str): - return strpath.encode(sys.getfilesystemencoding()) + if isinstance(b, str): + return b.encode(sys.getfilesystemencoding()) else: - return strpath + return b def byte_string(s): diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py index 4c5d9f3d0..f6d90e126 100644 --- a/src/OpenSSL/crypto.py +++ b/src/OpenSSL/crypto.py @@ -13,7 +13,7 @@ lib as _lib, exception_from_error_queue as _exception_from_error_queue, byte_string as _byte_string, - path_string as _path_string, + path_bytes as _path_bytes, UNSPECIFIED as _UNSPECIFIED, text_to_bytes_and_warn as _text_to_bytes_and_warn, make_assert as _make_assert, @@ -1728,12 +1728,12 @@ def load_locations(self, cafile, capath=None): if cafile is None: cafile = _ffi.NULL else: - cafile = _path_string(cafile) + cafile = _path_bytes(cafile) if capath is None: capath = _ffi.NULL else: - capath = _path_string(capath) + capath = _path_bytes(capath) load_result = _lib.X509_STORE_load_locations( self._store, cafile, capath