Skip to content

Commit

Permalink
Remove probably unreachable error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Aug 5, 2024
1 parent d042980 commit 702f5a7
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Any,
Callable,
Iterable,
NoReturn,
Sequence,
Union,
)
Expand Down Expand Up @@ -123,15 +122,6 @@ class Error(Exception):
_openssl_assert = _make_assert(Error)


def _untested_error(where: str) -> NoReturn:
"""
An OpenSSL API failed somehow. Additionally, the failure which was
encountered isn't one that's exercised by the test suite so future behavior
of pyOpenSSL is now somewhat less predictable.
"""
raise RuntimeError(f"Unknown {where} failure")


def _new_mem_buf(buffer: bytes | None = None) -> Any:
"""
Allocate a new OpenSSL memory BIO.
Expand Down Expand Up @@ -231,25 +221,13 @@ def _get_asn1_time(timestamp: Any) -> bytes | None:
else:
generalized_timestamp = _ffi.new("ASN1_GENERALIZEDTIME**")
_lib.ASN1_TIME_to_generalizedtime(timestamp, generalized_timestamp)
if generalized_timestamp[0] == _ffi.NULL:
# This may happen:
# - if timestamp was not an ASN1_TIME
# - if allocating memory for the ASN1_GENERALIZEDTIME failed
# - if a copy of the time data from timestamp cannot be made for
# the newly allocated ASN1_GENERALIZEDTIME
#
# These are difficult to test. cffi enforces the ASN1_TIME type.
# Memory allocation failures are a pain to trigger
# deterministically.
_untested_error("ASN1_TIME_to_generalizedtime")
else:
string_timestamp = _ffi.cast(
"ASN1_STRING*", generalized_timestamp[0]
)
string_data = _lib.ASN1_STRING_get0_data(string_timestamp)
string_result = _ffi.string(string_data)
_lib.ASN1_GENERALIZEDTIME_free(generalized_timestamp[0])
return string_result
_openssl_assert(generalized_timestamp[0] != _ffi.NULL)

string_timestamp = _ffi.cast("ASN1_STRING*", generalized_timestamp[0])
string_data = _lib.ASN1_STRING_get0_data(string_timestamp)
string_result = _ffi.string(string_data)
_lib.ASN1_GENERALIZEDTIME_free(generalized_timestamp[0])
return string_result


class _X509NameInvalidator:
Expand Down

0 comments on commit 702f5a7

Please sign in to comment.