createName static method

ASN1Sequence createName(
  1. String dn
)

Implementation

static ASN1Sequence createName(String dn) {
  final seq = ASN1Sequence();
  final parts = dn.split(',');
  for (final part in parts) {
    final kv = part.trim().split('=');
    if (kv.length != 2) continue;

    final type = kv[0].trim().toUpperCase();
    final value = kv[1].trim();

    String? oid;
    if (type == 'CN')
      oid = oidCommonName;
    else if (type == 'O')
      oid = oidOrganizationName;
    else if (type == 'C')
      oid = oidCountryName;
    else if (type == 'OU')
      oid = '2.5.4.11';
    else if (type == 'L')
      oid = '2.5.4.7';
    else if (type == 'ST')
      oid = '2.5.4.8';
    else if (type == 'E' || type == 'EMAIL')
      oid = '1.2.840.113549.1.9.1';
    else if (type == 'SERIALNUMBER') oid = '2.5.4.5';

    if (oid != null) {
      final set = ASN1Set();
      final attrSeq = ASN1Sequence();
      attrSeq.add(ASN1ObjectIdentifier.fromComponentString(oid));
      attrSeq.add(_encodeDnValue(oid, value));
      set.add(attrSeq);
      seq.add(set);
    }
  }
  return seq;
}