asn1IntegerToDecimal method

String asn1IntegerToDecimal(
  1. Pointer<ASN1_INTEGER> value
)
inherited

Converts ASN1_INTEGER to decimal string via BIGNUM.

Implementation

String asn1IntegerToDecimal(Pointer<ASN1_INTEGER> value) {
  final bn = bindings.ASN1_INTEGER_to_BN(value, nullptr);
  if (bn == nullptr) {
    throw OpenSslException('ASN1_INTEGER_to_BN failed');
  }

  try {
    final decPtr = bindings.BN_bn2dec(bn);
    if (decPtr == nullptr) {
      throw OpenSslException('BN_bn2dec failed');
    }
    try {
      return decPtr.cast<Utf8>().toDartString();
    } finally {
      bindings.CRYPTO_free(decPtr.cast(), nullptr, 0);
    }
  } finally {
    bindings.BN_free(bn);
  }
}