x509GetSerialBytes method

Uint8List x509GetSerialBytes(
  1. Pointer<X509> cert
)
inherited

Reads certificate serial bytes directly from ASN1_INTEGER payload.

This preserves full serial bytes without truncation.

Implementation

Uint8List x509GetSerialBytes(Pointer<X509> cert) {
  final serial = bindings.X509_get_serialNumber(cert);
  if (serial == nullptr) {
    throw OpenSslException('X509_get_serialNumber failed');
  }

  final len = bindings.ASN1_STRING_length(serial.cast());
  if (len < 0) {
    throw OpenSslException('ASN1_STRING_length failed for serial');
  }

  if (len == 0) {
    return Uint8List(0);
  }

  final data = bindings.ASN1_STRING_get0_data(serial.cast());
  if (data == nullptr) {
    throw OpenSslException('ASN1_STRING_get0_data failed for serial');
  }

  return Uint8List.fromList(data.cast<Uint8>().asTypedList(len));
}