diff options
Diffstat (limited to 'crypto/src/asn1/esf/OcspResponsesID.cs')
-rw-r--r-- | crypto/src/asn1/esf/OcspResponsesID.cs | 115 |
1 files changed, 46 insertions, 69 deletions
diff --git a/crypto/src/asn1/esf/OcspResponsesID.cs b/crypto/src/asn1/esf/OcspResponsesID.cs index 8718188fc..954125e3c 100644 --- a/crypto/src/asn1/esf/OcspResponsesID.cs +++ b/crypto/src/asn1/esf/OcspResponsesID.cs @@ -1,94 +1,71 @@ using System; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.Esf { - /// <remarks> - /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition - /// <code> - /// OcspResponsesID ::= SEQUENCE { - /// ocspIdentifier OcspIdentifier, - /// ocspRepHash OtherHash OPTIONAL - /// } - /// </code> - /// </remarks> - public class OcspResponsesID + /// <remarks> + /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition + /// <code> + /// OcspResponsesID ::= SEQUENCE { + /// ocspIdentifier OcspIdentifier, + /// ocspRepHash OtherHash OPTIONAL + /// } + /// </code> + /// </remarks> + public class OcspResponsesID : Asn1Encodable { - private readonly OcspIdentifier ocspIdentifier; - private readonly OtherHash ocspRepHash; - - public static OcspResponsesID GetInstance( - object obj) - { - if (obj == null || obj is OcspResponsesID) - return (OcspResponsesID) obj; - - if (obj is Asn1Sequence) - return new OcspResponsesID((Asn1Sequence) obj); - - throw new ArgumentException( - "Unknown object in 'OcspResponsesID' factory: " - + Platform.GetTypeName(obj), - "obj"); - } - - private OcspResponsesID( - Asn1Sequence seq) + public static OcspResponsesID GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is OcspResponsesID ocspResponsesID) + return ocspResponsesID; + return new OcspResponsesID(Asn1Sequence.GetInstance(obj)); + } + + public static OcspResponsesID GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + return new OcspResponsesID(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); + } + + private readonly OcspIdentifier m_ocspIdentifier; + private readonly OtherHash m_ocspRepHash; + + private OcspResponsesID(Asn1Sequence seq) { - if (seq == null) - throw new ArgumentNullException("seq"); - if (seq.Count < 1 || seq.Count > 2) - throw new ArgumentException("Bad sequence size: " + seq.Count, "seq"); + int count = seq.Count; + if (count < 1 || count > 2) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - this.ocspIdentifier = OcspIdentifier.GetInstance(seq[0].ToAsn1Object()); + m_ocspIdentifier = OcspIdentifier.GetInstance(seq[0]); if (seq.Count > 1) { - this.ocspRepHash = OtherHash.GetInstance(seq[1].ToAsn1Object()); + m_ocspRepHash = OtherHash.GetInstance(seq[1]); } } - public OcspResponsesID( - OcspIdentifier ocspIdentifier) - : this(ocspIdentifier, null) - { - } - - public OcspResponsesID( - OcspIdentifier ocspIdentifier, - OtherHash ocspRepHash) - { - if (ocspIdentifier == null) - throw new ArgumentNullException("ocspIdentifier"); + public OcspResponsesID(OcspIdentifier ocspIdentifier) + : this(ocspIdentifier, null) + { + } - this.ocspIdentifier = ocspIdentifier; - this.ocspRepHash = ocspRepHash; + public OcspResponsesID(OcspIdentifier ocspIdentifier, OtherHash ocspRepHash) + { + m_ocspIdentifier = ocspIdentifier ?? throw new ArgumentNullException(nameof(ocspIdentifier)); + m_ocspRepHash = ocspRepHash; } - public OcspIdentifier OcspIdentifier - { - get { return ocspIdentifier; } - } + public OcspIdentifier OcspIdentifier => m_ocspIdentifier; - public OtherHash OcspRepHash - { - get { return ocspRepHash; } - } + public OtherHash OcspRepHash => m_ocspRepHash; public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector( - ocspIdentifier.ToAsn1Object()); - - if (ocspRepHash != null) - { - v.Add(ocspRepHash.ToAsn1Object()); - } - + Asn1EncodableVector v = new Asn1EncodableVector(2); + v.Add(m_ocspIdentifier); + v.AddOptional(m_ocspRepHash); return new DerSequence(v); } - } } |