diff options
Diffstat (limited to 'crypto/src/asn1/esf/CrlListID.cs')
-rw-r--r-- | crypto/src/asn1/esf/CrlListID.cs | 78 |
1 files changed, 33 insertions, 45 deletions
diff --git a/crypto/src/asn1/esf/CrlListID.cs b/crypto/src/asn1/esf/CrlListID.cs index 1ee58aebc..ef49f9f4f 100644 --- a/crypto/src/asn1/esf/CrlListID.cs +++ b/crypto/src/asn1/esf/CrlListID.cs @@ -1,50 +1,44 @@ using System; using System.Collections.Generic; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.Esf { - /// <remarks> - /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition - /// <code> - /// CRLListID ::= SEQUENCE - /// { - /// crls SEQUENCE OF CrlValidatedID - /// } - /// </code> - /// </remarks> - public class CrlListID + /// <remarks> + /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition + /// <code> + /// CRLListID ::= SEQUENCE + /// { + /// crls SEQUENCE OF CrlValidatedID + /// } + /// </code> + /// </remarks> + public class CrlListID : Asn1Encodable { - private readonly Asn1Sequence m_crls; - - public static CrlListID GetInstance(object obj) - { - if (obj == null) - return null; + public static CrlListID GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is CrlListID crlListID) + return crlListID; + return new CrlListID(Asn1Sequence.GetInstance(obj)); + } - if (obj is CrlListID crlListID) - return crlListID; + public static CrlListID GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + return new CrlListID(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); + } - if (obj is Asn1Sequence asn1Sequence) - return new CrlListID(asn1Sequence); - - throw new ArgumentException("Unknown object in 'CrlListID' factory: " + Platform.GetTypeName(obj), - nameof(obj)); - } + private readonly Asn1Sequence m_crls; - private CrlListID(Asn1Sequence seq) + private CrlListID(Asn1Sequence seq) { - if (seq == null) - throw new ArgumentNullException(nameof(seq)); - if (seq.Count != 1) - throw new ArgumentException("Bad sequence size: " + seq.Count, nameof(seq)); + int count = seq.Count; + if (count != 1) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - m_crls = (Asn1Sequence)seq[0].ToAsn1Object(); - - // Validate - m_crls.MapElements(element => CrlValidatedID.GetInstance(element.ToAsn1Object())); + m_crls = Asn1Sequence.GetInstance(seq[0]); + m_crls.MapElements(CrlValidatedID.GetInstance); // Validate } public CrlListID(params CrlValidatedID[] crls) @@ -52,7 +46,7 @@ namespace Org.BouncyCastle.Asn1.Esf if (crls == null) throw new ArgumentNullException(nameof(crls)); - this.m_crls = new DerSequence(crls); + m_crls = DerSequence.FromElements(crls); } public CrlListID(IEnumerable<CrlValidatedID> crls) @@ -60,17 +54,11 @@ namespace Org.BouncyCastle.Asn1.Esf if (crls == null) throw new ArgumentNullException(nameof(crls)); - this.m_crls = new DerSequence(Asn1EncodableVector.FromEnumerable(crls)); + m_crls = DerSequence.FromVector(Asn1EncodableVector.FromEnumerable(crls)); } - public CrlValidatedID[] GetCrls() - { - return m_crls.MapElements(element => CrlValidatedID.GetInstance(element.ToAsn1Object())); - } + public CrlValidatedID[] GetCrls() => m_crls.MapElements(CrlValidatedID.GetInstance); - public override Asn1Object ToAsn1Object() - { - return new DerSequence(m_crls); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_crls); } } |