GeneralName.fromAsn1 constructor

GeneralName.fromAsn1(
  1. ASN1Object obj
)

Implementation

factory GeneralName.fromAsn1(ASN1Object obj) {
  var tag = obj.tag;
  var isConstructed = (0xA0 & tag) == 0xA0;
  var choice = (0x1F & tag);
  ASN1Object? contents;
  if (isConstructed) {
    contents = ASN1Parser(obj.valueBytes()).nextObject();
  } else {
    switch (choice) {
      case 1:
      case 2:
      case 6:
        contents = ASN1IA5String(String.fromCharCodes(obj.valueBytes()));
        break;
      case 7: // IPAddress (OctetString)
        contents = ASN1OctetString(obj.valueBytes());
        break;
      case 8: // registeredID (ObjectIdentifier)
        contents = ASN1ObjectIdentifier.fromBytes(obj.valueBytes());
        break;
      case 0: // TODO: unimplemented.
      case 3:
      case 4:
      case 5: // ediPartyName
        //  EDIPartyName ::= SEQUENCE {
        //   nameAssigner            [0]     DirectoryString OPTIONAL,
        //   partyName               [1]     DirectoryString }
        log('Warning Not Supported CHOICE($choice).');
        contents = obj;
    }
  }
  return GeneralName(
      isConstructed: isConstructed, choice: choice, contents: contents!);
}