diff options
Diffstat (limited to 'crypto/src/x509/X509AttrCertParser.cs')
-rw-r--r-- | crypto/src/x509/X509AttrCertParser.cs | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/crypto/src/x509/X509AttrCertParser.cs b/crypto/src/x509/X509AttrCertParser.cs index ce708ed8d..f1dc09543 100644 --- a/crypto/src/x509/X509AttrCertParser.cs +++ b/crypto/src/x509/X509AttrCertParser.cs @@ -1,12 +1,11 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Security.Certificates; -using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.IO; namespace Org.BouncyCastle.X509 @@ -19,7 +18,7 @@ namespace Org.BouncyCastle.X509 private int sDataObjectCount; private Stream currentStream; - private IX509AttributeCertificate ReadDerCertificate( + private X509V2AttributeCertificate ReadDerCertificate( Asn1InputStream dIn) { Asn1Sequence seq = (Asn1Sequence)dIn.ReadObject(); @@ -35,25 +34,21 @@ namespace Org.BouncyCastle.X509 } } -// return new X509V2AttributeCertificate(seq.getEncoded()); return new X509V2AttributeCertificate(AttributeCertificate.GetInstance(seq)); } - private IX509AttributeCertificate GetCertificate() + private X509V2AttributeCertificate GetCertificate() { if (sData != null) { while (sDataObjectCount < sData.Count) { - object obj = sData[sDataObjectCount++]; + Asn1Encodable ae = sData[sDataObjectCount++]; - if (obj is Asn1TaggedObject && ((Asn1TaggedObject)obj).TagNo == 2) + if (ae.ToAsn1Object() is Asn1TaggedObject t && t.TagNo == 2) { - //return new X509V2AttributeCertificate( - // Asn1Sequence.GetInstance((Asn1TaggedObject)obj, false).GetEncoded()); return new X509V2AttributeCertificate( - AttributeCertificate.GetInstance( - Asn1Sequence.GetInstance((Asn1TaggedObject)obj, false))); + AttributeCertificate.GetInstance(Asn1Sequence.GetInstance(t, false))); } } } @@ -61,14 +56,13 @@ namespace Org.BouncyCastle.X509 return null; } - private IX509AttributeCertificate ReadPemCertificate( + private X509V2AttributeCertificate ReadPemCertificate( Stream inStream) { Asn1Sequence seq = PemAttrCertParser.ReadPemObject(inStream); return seq == null ? null - //: new X509V2AttributeCertificate(seq.getEncoded()); : new X509V2AttributeCertificate(AttributeCertificate.GetInstance(seq)); } @@ -76,8 +70,7 @@ namespace Org.BouncyCastle.X509 /// Create loading data from byte array. /// </summary> /// <param name="input"></param> - public IX509AttributeCertificate ReadAttrCert( - byte[] input) + public X509V2AttributeCertificate ReadAttrCert(byte[] input) { return ReadAttrCert(new MemoryStream(input, false)); } @@ -86,8 +79,7 @@ namespace Org.BouncyCastle.X509 /// Create loading data from byte array. /// </summary> /// <param name="input"></param> - public ICollection ReadAttrCerts( - byte[] input) + public IList<X509V2AttributeCertificate> ReadAttrCerts(byte[] input) { return ReadAttrCerts(new MemoryStream(input, false)); } @@ -96,7 +88,7 @@ namespace Org.BouncyCastle.X509 * Generates a certificate object and initializes it with the data * read from the input stream inStream. */ - public IX509AttributeCertificate ReadAttrCert( + public X509V2AttributeCertificate ReadAttrCert( Stream inStream) { if (inStream == null) @@ -163,12 +155,11 @@ namespace Org.BouncyCastle.X509 * Returns a (possibly empty) collection view of the certificates * read from the given input stream inStream. */ - public ICollection ReadAttrCerts( - Stream inStream) + public IList<X509V2AttributeCertificate> ReadAttrCerts(Stream inStream) { - IX509AttributeCertificate attrCert; - IList attrCerts = Platform.CreateArrayList(); + var attrCerts = new List<X509V2AttributeCertificate>(); + X509V2AttributeCertificate attrCert; while ((attrCert = ReadAttrCert(inStream)) != null) { attrCerts.Add(attrCert); @@ -177,4 +168,4 @@ namespace Org.BouncyCastle.X509 return attrCerts; } } -} \ No newline at end of file +} |