diff options
Diffstat (limited to 'crypto/src/asn1/ocsp/CertStatus.cs')
-rw-r--r-- | crypto/src/asn1/ocsp/CertStatus.cs | 104 |
1 files changed, 46 insertions, 58 deletions
diff --git a/crypto/src/asn1/ocsp/CertStatus.cs b/crypto/src/asn1/ocsp/CertStatus.cs index 18b7bd21c..e1d06ed19 100644 --- a/crypto/src/asn1/ocsp/CertStatus.cs +++ b/crypto/src/asn1/ocsp/CertStatus.cs @@ -1,87 +1,75 @@ using System; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.Ocsp { public class CertStatus : Asn1Encodable, IAsn1Choice { - private readonly int tagNo; - private readonly Asn1Encodable value; - - /** - * create a CertStatus object with a tag of zero. - */ - public CertStatus() - { - tagNo = 0; - value = DerNull.Instance; - } - - public CertStatus( - RevokedInfo info) + public static CertStatus GetInstance(object obj) { - tagNo = 1; - value = info; + if (obj == null) + return null; + if (obj is CertStatus certStatus) + return certStatus; + return new CertStatus(Asn1TaggedObject.GetInstance(obj)); } - public CertStatus( - int tagNo, - Asn1Encodable value) + public static CertStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { - this.tagNo = tagNo; - this.value = value; + return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance); } - public CertStatus(Asn1TaggedObject choice) + private static Asn1Encodable GetValue(Asn1TaggedObject choice) { - this.tagNo = choice.TagNo; - - switch (choice.TagNo) + if (choice.HasContextTag()) { - case 0: - value = Asn1Null.GetInstance(choice, false); - break; - case 1: - value = RevokedInfo.GetInstance(choice, false); - break; - case 2: - value = Asn1Null.GetInstance(choice, false); - break; - default: - throw new ArgumentException("Unknown tag encountered: " + Asn1Utilities.GetTagText(choice)); + switch (choice.TagNo) + { + case 0: + return Asn1Null.GetInstance(choice, false); + case 1: + return RevokedInfo.GetInstance(choice, false); + case 2: + return Asn1Null.GetInstance(choice, false); + } } + + throw new ArgumentException("Unknown tag encountered: " + Asn1Utilities.GetTagText(choice)); } - public static CertStatus GetInstance(object obj) - { - if (obj == null) - return null; + private readonly int m_tagNo; + private readonly Asn1Encodable m_value; - if (obj is CertStatus certStatus) - return certStatus; + /** + * create a CertStatus object with a tag of zero. + */ + public CertStatus() + { + m_tagNo = 0; + m_value = DerNull.Instance; + } - if (obj is Asn1TaggedObject taggedObject) - return new CertStatus(taggedObject); + public CertStatus(RevokedInfo info) + { + m_tagNo = 1; + m_value = info ?? throw new ArgumentNullException(nameof(info)); + } - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); + public CertStatus(int tagNo, Asn1Encodable value) + { + m_tagNo = tagNo; + m_value = value ?? throw new ArgumentNullException(nameof(value)); } - public static CertStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + public CertStatus(Asn1TaggedObject choice) { - return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance); + m_tagNo = choice.TagNo; + m_value = GetValue(choice); } - public int TagNo - { - get { return tagNo; } - } + public int TagNo => m_tagNo; - public Asn1Encodable Status - { - get { return value; } - } + public Asn1Encodable Status => m_value; /** * Produce an object suitable for an Asn1OutputStream. @@ -94,7 +82,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - return new DerTaggedObject(false, tagNo, value); + return new DerTaggedObject(false, m_tagNo, m_value); } } } |