string static method

String string({
  1. required ASN1Object block,
})

Format subject/issuer information in RFC1779

Implementation

static String string({required ASN1Object block}) {
  var result = "";
  var oidNames = ASN1DistinguishedNames.values;
  for (var oidName in oidNames) {
    var oidBlock = block.findOid(oidValue: oidName.oid());
    if (oidBlock == null) {
      continue;
    }
    if (result.isNotEmpty) {
      result += ", ";
    }
    result += oidName.representation();
    result += "=";

    String? value;
    try {
      value = oidBlock.parent?.sub?.last.value as String?;
    } catch (e) {}
    if (value != null) {
      result += quote(value);
    }
  }
  return result;
}