extractCpf static method
Extracts the CPF in the order recommended by the standard:
serialNumberof the Subject DN (CPF directly);- natural-person
otherName(positional block); otherNameof the legal entity's responsible (same block layout).
Returns 11 digits with verified check digits, or null.
Implementation
static String? extractCpf({
String? subjectDn,
String? otherNameNaturalPerson,
String? otherNameResponsible,
}) {
final fromDn = _digitsOnly(_dnAttribute(subjectDn, 'serialNumber') ??
_dnAttribute(subjectDn, oidDnSerialNumber));
if (fromDn != null && fromDn.length == 11 && isValidCpf(fromDn)) {
return fromDn;
}
for (final block in [otherNameNaturalPerson, otherNameResponsible]) {
final cpf = extractCpfFromBlock(block);
if (cpf != null) return cpf;
}
return null;
}