ExtensionValue.fromAsn1 constructor

ExtensionValue.fromAsn1(
  1. ASN1Object obj,
  2. ObjectIdentifier id
)

Creates an extension value from an ASN1Object.

id defines the type of extension to create.

Implementation

factory ExtensionValue.fromAsn1(ASN1Object obj, ObjectIdentifier id) {
  if (id.parent == ceId) {
    switch (id.nodes.last) {
      case 35:
        return AuthorityKeyIdentifier.fromAsn1(obj as ASN1Sequence);
      case 14:
        return SubjectKeyIdentifier.fromAsn1(obj);
      case 15:
        return KeyUsage.fromAsn1(obj as ASN1BitString);
      case 32:
        return CertificatePolicies.fromAsn1(obj as ASN1Sequence);
      case 31:
        return CrlDistributionPoints.fromAsn1(obj as ASN1Sequence);
      case 17: // subject alternative name extension
      case 18: // issuer alternative name extension
        return GeneralNames.fromAsn1(obj as ASN1Sequence);
      case 9: // TODO: subject directory attributes extension
      case 30: // TODO: name constraints extension
      case 33: // TODO: policy mappings extension
      case 36: // TODO: policy constraints extension
        break;
      case 19:
        return BasicConstraints.fromAsn1(obj as ASN1Sequence);
      case 37:
        return ExtendedKeyUsage.fromAsn1(obj as ASN1Sequence);
      case 16:
        return PrivateKeyUsagePeriod.fromAsn1(obj as ASN1Sequence);
    }
  }
  if (id.parent == peId) {
    switch (id.nodes.last) {
      case 1:
        return AuthorityInformationAccess.fromAsn1(obj as ASN1Sequence);
      case 3:
        return QCStatements.fromAsn1(obj as ASN1Sequence);
    }
  }
  if (id == xId) {
    return UnknownExtension.fromAsn1(obj);
  }
  else
    return UnknownExtension.fromAsn1(obj);
  throw UnimplementedError(
      'Cannot handle $id (${id.parent} ${id.nodes.last})');
}