extensionObject method

X509Extension? extensionObject({
  1. String? oidValue,
  2. OID? oid,
})

Gets the extension information of the given OID code or enum string value.

Implementation

X509Extension? extensionObject({String? oidValue, OID? oid}) {
  if (oidValue == null && oid != null) {
    oidValue = oid.toValue();
  }
  if (oidValue != null) {
    var block = block1
        ?.atIndex(X509BlockPosition.extensions)
        ?.findOid(oidValue: oidValue)
        ?.parent;
    if (block != null) {
      if (oidValue == OID.basicConstraints.toValue()) {
        return BasicConstraintExtension(block: block);
      } else if (oidValue == OID.subjectKeyIdentifier.toValue()) {
        return SubjectKeyIdentifierExtension(block: block);
      } else if (oidValue == OID.authorityInfoAccess.toValue()) {
        return AuthorityInfoAccessExtension(block: block);
      } else if (oidValue == OID.authorityKeyIdentifier.toValue()) {
        return AuthorityKeyIdentifierExtension(block: block);
      } else if (oidValue == OID.certificatePolicies.toValue()) {
        return CertificatePoliciesExtension(block: block);
      } else if (oidValue == OID.cRLDistributionPoints.toValue()) {
        return CRLDistributionPointsExtension(block: block);
      }
      return X509Extension(block: block);
    }
  }
  return null;
}