diff options
Diffstat (limited to 'crypto/src/asn1/ocsp/RevokedInfo.cs')
-rw-r--r-- | crypto/src/asn1/ocsp/RevokedInfo.cs | 88 |
1 files changed, 36 insertions, 52 deletions
diff --git a/crypto/src/asn1/ocsp/RevokedInfo.cs b/crypto/src/asn1/ocsp/RevokedInfo.cs index e6438dd08..d2395e186 100644 --- a/crypto/src/asn1/ocsp/RevokedInfo.cs +++ b/crypto/src/asn1/ocsp/RevokedInfo.cs @@ -1,77 +1,60 @@ using System; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Ocsp { public class RevokedInfo : Asn1Encodable { - private readonly Asn1GeneralizedTime revocationTime; - private readonly CrlReason revocationReason; - - public static RevokedInfo GetInstance( - Asn1TaggedObject obj, - bool explicitly) - { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); - } - - public static RevokedInfo GetInstance( - object obj) - { - if (obj == null || obj is RevokedInfo) - { - return (RevokedInfo) obj; - } + public static RevokedInfo GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is RevokedInfo revokedInfo) + return revokedInfo; + return new RevokedInfo(Asn1Sequence.GetInstance(obj)); + } - if (obj is Asn1Sequence) - { - return new RevokedInfo((Asn1Sequence) obj); - } + public static RevokedInfo GetInstance(Asn1TaggedObject obj, bool explicitly) + { + return new RevokedInfo(Asn1Sequence.GetInstance(obj, explicitly)); + } - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + private readonly Asn1GeneralizedTime m_revocationTime; + private readonly CrlReason m_revocationReason; - public RevokedInfo( - Asn1GeneralizedTime revocationTime) + public RevokedInfo(Asn1GeneralizedTime revocationTime) : this(revocationTime, null) { } - public RevokedInfo( - Asn1GeneralizedTime revocationTime, - CrlReason revocationReason) + public RevokedInfo(Asn1GeneralizedTime revocationTime, CrlReason revocationReason) { - if (revocationTime == null) - throw new ArgumentNullException("revocationTime"); - - this.revocationTime = revocationTime; - this.revocationReason = revocationReason; + m_revocationTime = revocationTime ?? throw new ArgumentNullException("revocationTime"); + m_revocationReason = revocationReason; } - private RevokedInfo( - Asn1Sequence seq) + private RevokedInfo(Asn1Sequence seq) { - this.revocationTime = (Asn1GeneralizedTime)seq[0]; + int count = seq.Count; + if (count < 1 || count > 2) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); + + int pos = 0; + + m_revocationTime = Asn1GeneralizedTime.GetInstance(seq[pos++]); + + m_revocationReason = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, true, + (t, e) => new CrlReason(DerEnumerated.GetInstance(t, e))); - if (seq.Count > 1) - { - this.revocationReason = new CrlReason( - DerEnumerated.GetInstance((Asn1TaggedObject) seq[1], true)); - } + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } - public Asn1GeneralizedTime RevocationTime - { - get { return revocationTime; } - } + public Asn1GeneralizedTime RevocationTime => m_revocationTime; - public CrlReason RevocationReason - { - get { return revocationReason; } - } + public CrlReason RevocationReason => m_revocationReason; /** * Produce an object suitable for an Asn1OutputStream. @@ -83,8 +66,9 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(revocationTime); - v.AddOptionalTagged(true, 0, revocationReason); + Asn1EncodableVector v = new Asn1EncodableVector(2); + v.Add(m_revocationTime); + v.AddOptionalTagged(true, 0, m_revocationReason); return new DerSequence(v); } } |