Skip to content

Commit

Permalink
Remove unreachable error handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Aug 5, 2024
1 parent 3ada747 commit 07be225
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,27 +1420,16 @@ def set_serial_number(self, serial: int) -> None:

bignum_serial = _ffi.new("BIGNUM**")

# BN_hex2bn stores the result in &bignum. Unless it doesn't feel like
# it. If bignum is still NULL after this call, then the return value
# is actually the result. I hope. -exarkun
small_serial = _lib.BN_hex2bn(bignum_serial, hex_serial_bytes)

if bignum_serial[0] == _ffi.NULL:
set_result = _lib.ASN1_INTEGER_set(
_lib.X509_get_serialNumber(self._x509), small_serial
)
if set_result:
# TODO Not tested
_raise_current_error()
else:
asn1_serial = _lib.BN_to_ASN1_INTEGER(bignum_serial[0], _ffi.NULL)
_lib.BN_free(bignum_serial[0])
if asn1_serial == _ffi.NULL:
# TODO Not tested
_raise_current_error()
asn1_serial = _ffi.gc(asn1_serial, _lib.ASN1_INTEGER_free)
set_result = _lib.X509_set_serialNumber(self._x509, asn1_serial)
_openssl_assert(set_result == 1)
# BN_hex2bn stores the result in &bignum.
result = _lib.BN_hex2bn(bignum_serial, hex_serial_bytes)
_openssl_assert(result != _ffi.NULL)

asn1_serial = _lib.BN_to_ASN1_INTEGER(bignum_serial[0], _ffi.NULL)
_lib.BN_free(bignum_serial[0])
_openssl_assert(asn1_serial != _ffi.NULL)
asn1_serial = _ffi.gc(asn1_serial, _lib.ASN1_INTEGER_free)
set_result = _lib.X509_set_serialNumber(self._x509, asn1_serial)
_openssl_assert(set_result == 1)

def get_serial_number(self) -> int:
"""
Expand Down

0 comments on commit 07be225

Please sign in to comment.