Skip to content

Commit

Permalink
Rename path_string to path_bytes since that's what it actually does (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Dec 19, 2021
1 parent de073c6 commit 8b85cfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions src/OpenSSL/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b85cfd

Please sign in to comment.