@@ -1420,27 +1420,16 @@ def set_serial_number(self, serial: int) -> None:
1420
1420
1421
1421
bignum_serial = _ffi .new ("BIGNUM**" )
1422
1422
1423
- # BN_hex2bn stores the result in &bignum. Unless it doesn't feel like
1424
- # it. If bignum is still NULL after this call, then the return value
1425
- # is actually the result. I hope. -exarkun
1426
- small_serial = _lib .BN_hex2bn (bignum_serial , hex_serial_bytes )
1427
-
1428
- if bignum_serial [0 ] == _ffi .NULL :
1429
- set_result = _lib .ASN1_INTEGER_set (
1430
- _lib .X509_get_serialNumber (self ._x509 ), small_serial
1431
- )
1432
- if set_result :
1433
- # TODO Not tested
1434
- _raise_current_error ()
1435
- else :
1436
- asn1_serial = _lib .BN_to_ASN1_INTEGER (bignum_serial [0 ], _ffi .NULL )
1437
- _lib .BN_free (bignum_serial [0 ])
1438
- if asn1_serial == _ffi .NULL :
1439
- # TODO Not tested
1440
- _raise_current_error ()
1441
- asn1_serial = _ffi .gc (asn1_serial , _lib .ASN1_INTEGER_free )
1442
- set_result = _lib .X509_set_serialNumber (self ._x509 , asn1_serial )
1443
- _openssl_assert (set_result == 1 )
1423
+ # BN_hex2bn stores the result in &bignum.
1424
+ result = _lib .BN_hex2bn (bignum_serial , hex_serial_bytes )
1425
+ _openssl_assert (result != _ffi .NULL )
1426
+
1427
+ asn1_serial = _lib .BN_to_ASN1_INTEGER (bignum_serial [0 ], _ffi .NULL )
1428
+ _lib .BN_free (bignum_serial [0 ])
1429
+ _openssl_assert (asn1_serial != _ffi .NULL )
1430
+ asn1_serial = _ffi .gc (asn1_serial , _lib .ASN1_INTEGER_free )
1431
+ set_result = _lib .X509_set_serialNumber (self ._x509 , asn1_serial )
1432
+ _openssl_assert (set_result == 1 )
1444
1433
1445
1434
def get_serial_number (self ) -> int :
1446
1435
"""
0 commit comments