<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0-beta.98" />

CertOrEncCert

using Org.BouncyCastle.Asn1.Crmf; using System; namespace Org.BouncyCastle.Asn1.Cmp { public class CertOrEncCert : Asn1Encodable, IAsn1Choice { private readonly CmpCertificate m_certificate; private readonly EncryptedKey m_encryptedCert; public virtual CmpCertificate Certificate => m_certificate; public virtual EncryptedKey EncryptedCert => m_encryptedCert; public virtual bool HasEncryptedCertificate => m_encryptedCert != null; public static CertOrEncCert GetInstance(object obj) { return Asn1Utilities.GetInstanceChoice(obj, GetOptional); } public static CertOrEncCert GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance); } public static CertOrEncCert GetOptional(Asn1Encodable element) { if (element == null) throw new ArgumentNullException("element"); CertOrEncCert certOrEncCert = element as CertOrEncCert; if (certOrEncCert != null) return certOrEncCert; Asn1TaggedObject optional = Asn1TaggedObject.GetOptional(element); if (optional != null) { if (optional.HasContextTag(0)) return new CertOrEncCert(CmpCertificate.GetInstance(optional.GetExplicitBaseObject())); if (optional.HasContextTag(1)) return new CertOrEncCert(EncryptedKey.GetInstance(optional.GetExplicitBaseObject())); } return null; } public static CertOrEncCert GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance); } public CertOrEncCert(CmpCertificate certificate) { if (certificate == null) throw new ArgumentNullException("certificate"); m_certificate = certificate; } [Obsolete("Use constructor with EncryptedKey instead")] public CertOrEncCert(EncryptedValue encryptedValue) { if (encryptedValue == null) throw new ArgumentNullException("encryptedValue"); m_encryptedCert = new EncryptedKey(encryptedValue); } public CertOrEncCert(EncryptedKey encryptedKey) { if (encryptedKey == null) throw new ArgumentNullException("encryptedKey"); m_encryptedCert = encryptedKey; } public override Asn1Object ToAsn1Object() { if (m_certificate != null) return new DerTaggedObject(true, 0, m_certificate); if (m_encryptedCert != null) return new DerTaggedObject(true, 1, m_encryptedCert); throw new InvalidOperationException(); } } }