CmpCertificate
using Org.BouncyCastle.Asn1.X509;
using System;
namespace Org.BouncyCastle.Asn1.Cmp
{
public class CmpCertificate : Asn1Encodable, IAsn1Choice
{
private readonly X509CertificateStructure m_x509v3PKCert;
private readonly int m_otherCertTag;
private readonly Asn1Encodable m_otherCert;
public virtual bool IsX509v3PKCert => m_x509v3PKCert != null;
public virtual X509CertificateStructure X509v3PKCert => m_x509v3PKCert;
public virtual int OtherCertTag => m_otherCertTag;
public virtual Asn1Encodable OtherCert => m_otherCert;
public static CmpCertificate GetInstance(object obj)
{
return Asn1Utilities.GetInstanceChoice(obj, GetOptional);
}
public static CmpCertificate GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
}
public static CmpCertificate GetOptional(Asn1Encodable element)
{
if (element == null)
throw new ArgumentNullException("element");
CmpCertificate cmpCertificate = element as CmpCertificate;
if (cmpCertificate != null)
return cmpCertificate;
X509CertificateStructure optional = X509CertificateStructure.GetOptional(element);
if (optional != null)
return new CmpCertificate(optional);
Asn1TaggedObject optional2 = Asn1TaggedObject.GetOptional(element);
if (optional2 != null && optional2.HasContextTag() && optional2.IsExplicit())
return new CmpCertificate(optional2.TagNo, optional2.GetBaseObject());
return null;
}
public static CmpCertificate GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
}
[Obsolete("Use 'GetInstance' from tagged object instead")]
public CmpCertificate(int type, Asn1Encodable otherCert)
{
m_x509v3PKCert = null;
m_otherCertTag = type;
m_otherCert = otherCert;
}
internal CmpCertificate(CmpCertificate other)
{
m_x509v3PKCert = other.m_x509v3PKCert;
m_otherCertTag = other.m_otherCertTag;
m_otherCert = other.m_otherCert;
}
public CmpCertificate(X509CertificateStructure x509v3PKCert)
{
if (x509v3PKCert.Version != 3)
throw new ArgumentException("only version 3 certificates allowed", "x509v3PKCert");
m_x509v3PKCert = x509v3PKCert;
m_otherCertTag = -1;
m_otherCert = null;
}
public override Asn1Object ToAsn1Object()
{
if (m_x509v3PKCert != null)
return m_x509v3PKCert.ToAsn1Object();
if (m_otherCert != null)
return new DerTaggedObject(true, m_otherCertTag, m_otherCert);
throw new InvalidOperationException();
}
}
}