extractCnpj static method

String? extractCnpj({
  1. String? subjectDn,
  2. String? otherNameCnpj,
})

Extracts the CNPJ (14 digits) from the DN serialNumber or from the oidCnpj otherName. Returns null when absent or when the check digits do not match.

Implementation

static String? extractCnpj({
  String? subjectDn,
  String? otherNameCnpj,
}) {
  final fromOtherName = _digitsOnly(otherNameCnpj);
  if (fromOtherName != null &&
      fromOtherName.length == 14 &&
      isValidCnpj(fromOtherName)) {
    return fromOtherName;
  }

  final fromDn = _digitsOnly(_dnAttribute(subjectDn, 'serialNumber') ??
      _dnAttribute(subjectDn, oidDnSerialNumber));
  if (fromDn != null && fromDn.length == 14 && isValidCnpj(fromDn)) {
    return fromDn;
  }
  return null;
}