|
11 | 11 | Any,
|
12 | 12 | Callable,
|
13 | 13 | Iterable,
|
14 |
| - NoReturn, |
15 | 14 | Sequence,
|
16 | 15 | Union,
|
17 | 16 | )
|
@@ -123,15 +122,6 @@ class Error(Exception):
|
123 | 122 | _openssl_assert = _make_assert(Error)
|
124 | 123 |
|
125 | 124 |
|
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 |
| - |
135 | 125 | def _new_mem_buf(buffer: bytes | None = None) -> Any:
|
136 | 126 | """
|
137 | 127 | Allocate a new OpenSSL memory BIO.
|
@@ -231,25 +221,13 @@ def _get_asn1_time(timestamp: Any) -> bytes | None:
|
231 | 221 | else:
|
232 | 222 | generalized_timestamp = _ffi.new("ASN1_GENERALIZEDTIME**")
|
233 | 223 | _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 |
253 | 231 |
|
254 | 232 |
|
255 | 233 | class _X509NameInvalidator:
|
|
0 commit comments