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_otherTag;
private readonly Asn1Encodable m_otherObject;
public virtual bool IsX509v3PKCert => m_x509v3PKCert != null;
public virtual X509CertificateStructure X509v3PKCert => m_x509v3PKCert;
public virtual int OtherCertTag => m_otherTag;
public virtual Asn1Encodable OtherCert => m_otherObject;
public static CmpCertificate GetInstance(object obj)
{
if (obj == null)
return null;
CmpCertificate cmpCertificate = obj as CmpCertificate;
if (cmpCertificate != null)
return cmpCertificate;
X509CertificateStructure x509CertificateStructure = obj as X509CertificateStructure;
if (x509CertificateStructure != null)
return new CmpCertificate(x509CertificateStructure);
Asn1TaggedObject asn1TaggedObject = obj as Asn1TaggedObject;
if (asn1TaggedObject != null)
return new CmpCertificate(asn1TaggedObject);
Asn1Object asn1Object = null;
IAsn1Convertible asn1Convertible = obj as IAsn1Convertible;
if (asn1Convertible != null)
asn1Object = asn1Convertible.ToAsn1Object();
else {
byte[] array = obj as byte[];
if (array != null)
asn1Object = Asn1Object.FromByteArray(array);
}
Asn1TaggedObject asn1TaggedObject2 = asn1Object as Asn1TaggedObject;
if (asn1TaggedObject2 != null)
return new CmpCertificate(asn1TaggedObject2);
return new CmpCertificate(X509CertificateStructure.GetInstance(asn1Object ?? obj));
}
public static CmpCertificate GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
}
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_otherTag = type;
m_otherObject = otherCert;
}
internal CmpCertificate(Asn1TaggedObject taggedObject)
{
if (!taggedObject.HasContextTag(1))
throw new ArgumentException("Invalid CHOICE element", "taggedObject");
AttributeCertificate.GetInstance(taggedObject, true);
m_otherTag = taggedObject.TagNo;
m_otherObject = taggedObject.GetExplicitBaseObject();
}
internal CmpCertificate(CmpCertificate other)
{
m_x509v3PKCert = other.m_x509v3PKCert;
m_otherTag = other.m_otherTag;
m_otherObject = other.m_otherObject;
}
public CmpCertificate(X509CertificateStructure x509v3PKCert)
{
if (x509v3PKCert.Version != 3)
throw new ArgumentException("only version 3 certificates allowed", "x509v3PKCert");
m_x509v3PKCert = x509v3PKCert;
}
public override Asn1Object ToAsn1Object()
{
if (m_otherObject != null)
return new DerTaggedObject(true, m_otherTag, m_otherObject);
if (m_x509v3PKCert != null)
return m_x509v3PKCert.ToAsn1Object();
throw new InvalidOperationException();
}
}
}