<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.0" />

Target

public class Target : Asn1Encodable, IAsn1Choice
using System; namespace Org.BouncyCastle.Asn1.X509 { public class Target : Asn1Encodable, IAsn1Choice { public enum Choice { Name, Group } private readonly GeneralName m_targetName; private readonly GeneralName m_targetGroup; public virtual GeneralName TargetGroup => m_targetGroup; public virtual GeneralName TargetName => m_targetName; public static Target GetInstance(object obj) { return Asn1Utilities.GetInstanceChoice(obj, GetOptional); } public static Target GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance); } public static Target GetOptional(Asn1Encodable element) { if (element == null) throw new ArgumentNullException("element"); Target target = element as Target; if (target != null) return target; Asn1TaggedObject optional = Asn1TaggedObject.GetOptional(element); if (optional != null && (optional.HasContextTag(0) || optional.HasContextTag(1))) return new Target(optional); return null; } public static Target GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance); } private Target(Asn1TaggedObject tagObj) { switch (tagObj.TagNo) { case 0: m_targetName = GeneralName.GetInstance(tagObj, true); break; case 1: m_targetGroup = GeneralName.GetInstance(tagObj, true); break; default: throw new ArgumentException("unknown tag: " + tagObj.TagNo.ToString()); } } public Target(Choice type, GeneralName name) : this(new DerTaggedObject((int)type, name)) { } public override Asn1Object ToAsn1Object() { if (m_targetName != null) return new DerTaggedObject(true, 0, m_targetName); if (m_targetGroup != null) return new DerTaggedObject(true, 1, m_targetGroup); throw new InvalidOperationException(); } } }