Skip to content

Commit 15ab815

Browse files
authored
Remove probably unreachable error handling (#1344)
1 parent d042980 commit 15ab815

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

src/OpenSSL/crypto.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Any,
1212
Callable,
1313
Iterable,
14-
NoReturn,
1514
Sequence,
1615
Union,
1716
)
@@ -123,15 +122,6 @@ class Error(Exception):
123122
_openssl_assert = _make_assert(Error)
124123

125124

126-
def _untested_error(where: str) -> NoReturn:
127-
"""
128-
An OpenSSL API failed somehow. Additionally, the failure which was
129-
encountered isn't one that's exercised by the test suite so future behavior
130-
of pyOpenSSL is now somewhat less predictable.
131-
"""
132-
raise RuntimeError(f"Unknown {where} failure")
133-
134-
135125
def _new_mem_buf(buffer: bytes | None = None) -> Any:
136126
"""
137127
Allocate a new OpenSSL memory BIO.
@@ -231,25 +221,13 @@ def _get_asn1_time(timestamp: Any) -> bytes | None:
231221
else:
232222
generalized_timestamp = _ffi.new("ASN1_GENERALIZEDTIME**")
233223
_lib.ASN1_TIME_to_generalizedtime(timestamp, generalized_timestamp)
234-
if generalized_timestamp[0] == _ffi.NULL:
235-
# This may happen:
236-
# - if timestamp was not an ASN1_TIME
237-
# - if allocating memory for the ASN1_GENERALIZEDTIME failed
238-
# - if a copy of the time data from timestamp cannot be made for
239-
# the newly allocated ASN1_GENERALIZEDTIME
240-
#
241-
# These are difficult to test. cffi enforces the ASN1_TIME type.
242-
# Memory allocation failures are a pain to trigger
243-
# deterministically.
244-
_untested_error("ASN1_TIME_to_generalizedtime")
245-
else:
246-
string_timestamp = _ffi.cast(
247-
"ASN1_STRING*", generalized_timestamp[0]
248-
)
249-
string_data = _lib.ASN1_STRING_get0_data(string_timestamp)
250-
string_result = _ffi.string(string_data)
251-
_lib.ASN1_GENERALIZEDTIME_free(generalized_timestamp[0])
252-
return string_result
224+
_openssl_assert(generalized_timestamp[0] != _ffi.NULL)
225+
226+
string_timestamp = _ffi.cast("ASN1_STRING*", generalized_timestamp[0])
227+
string_data = _lib.ASN1_STRING_get0_data(string_timestamp)
228+
string_result = _ffi.string(string_data)
229+
_lib.ASN1_GENERALIZEDTIME_free(generalized_timestamp[0])
230+
return string_result
253231

254232

255233
class _X509NameInvalidator:

0 commit comments

Comments
 (0)