diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 14:15:10 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 14:15:10 +0700 |
commit | 435210f10fd927653ce8fbc04ec537ae5d8966b6 (patch) | |
tree | 27b6ed1c029db271c3429ac57629d7f0156c5fed /crypto/src/x509/store | |
parent | Refactoring around Platform (diff) | |
download | BouncyCastle.NET-ed25519-435210f10fd927653ce8fbc04ec537ae5d8966b6.tar.xz |
Generics migration complete
Diffstat (limited to 'crypto/src/x509/store')
-rw-r--r-- | crypto/src/x509/store/X509AttrCertStoreSelector.cs | 50 | ||||
-rw-r--r-- | crypto/src/x509/store/X509CertStoreSelector.cs | 15 | ||||
-rw-r--r-- | crypto/src/x509/store/X509CrlStoreSelector.cs | 10 |
3 files changed, 36 insertions, 39 deletions
diff --git a/crypto/src/x509/store/X509AttrCertStoreSelector.cs b/crypto/src/x509/store/X509AttrCertStoreSelector.cs index b25d0de19..5744289e9 100644 --- a/crypto/src/x509/store/X509AttrCertStoreSelector.cs +++ b/crypto/src/x509/store/X509AttrCertStoreSelector.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; @@ -27,8 +27,8 @@ namespace Org.BouncyCastle.X509.Store private AttributeCertificateHolder holder; private AttributeCertificateIssuer issuer; private BigInteger serialNumber; - private ISet targetNames = new HashSet(); - private ISet targetGroups = new HashSet(); + private ISet<GeneralName> targetNames = new HashSet<GeneralName>(); + private ISet<GeneralName> targetGroups = new HashSet<GeneralName>(); public X509AttrCertStoreSelector() { @@ -42,8 +42,8 @@ namespace Org.BouncyCastle.X509.Store this.holder = o.holder; this.issuer = o.issuer; this.serialNumber = o.serialNumber; - this.targetGroups = new HashSet(o.targetGroups); - this.targetNames = new HashSet(o.targetNames); + this.targetGroups = new HashSet<GeneralName>(o.targetGroups); + this.targetNames = new HashSet<GeneralName>(o.targetNames); } /// <summary> @@ -225,8 +225,7 @@ namespace Org.BouncyCastle.X509.Store * @param name a byte array containing the name in ASN.1 DER encoded form of a GeneralName * @throws IOException if a parsing error occurs. */ - public void AddTargetName( - byte[] name) + public void AddTargetName(byte[] name) { AddTargetName(GeneralName.GetInstance(Asn1Object.FromByteArray(name))); } @@ -244,8 +243,7 @@ namespace Org.BouncyCastle.X509.Store * @see #AddTargetName(byte[]) * @see #AddTargetName(GeneralName) */ - public void SetTargetNames( - IEnumerable names) + public void SetTargetNames(IEnumerable<object> names) { targetNames = ExtractGeneralNames(names); } @@ -259,9 +257,9 @@ namespace Org.BouncyCastle.X509.Store * @return The collection of target names * @see #setTargetNames(Collection) */ - public IEnumerable GetTargetNames() + public IEnumerable<GeneralName> GetTargetNames() { - return new EnumerableProxy(targetNames); + return CollectionUtilities.Proxy(targetNames); } /** @@ -277,8 +275,7 @@ namespace Org.BouncyCastle.X509.Store * * @param group The group as GeneralName form (not <code>null</code>) */ - public void AddTargetGroup( - GeneralName group) + public void AddTargetGroup(GeneralName group) { targetGroups.Add(group); } @@ -297,8 +294,7 @@ namespace Org.BouncyCastle.X509.Store * @param name a byte array containing the group in ASN.1 DER encoded form of a GeneralName * @throws IOException if a parsing error occurs. */ - public void AddTargetGroup( - byte[] name) + public void AddTargetGroup(byte[] name) { AddTargetGroup(GeneralName.GetInstance(Asn1Object.FromByteArray(name))); } @@ -316,8 +312,7 @@ namespace Org.BouncyCastle.X509.Store * @see #AddTargetGroup(byte[]) * @see #AddTargetGroup(GeneralName) */ - public void SetTargetGroups( - IEnumerable names) + public void SetTargetGroups(IEnumerable<object> names) { targetGroups = ExtractGeneralNames(names); } @@ -331,28 +326,31 @@ namespace Org.BouncyCastle.X509.Store * @return The collection of target groups. * @see #setTargetGroups(Collection) */ - public IEnumerable GetTargetGroups() + public IEnumerable<GeneralName> GetTargetGroups() { - return new EnumerableProxy(targetGroups); + return CollectionUtilities.Proxy(targetGroups); } - private ISet ExtractGeneralNames( - IEnumerable names) + private ISet<GeneralName> ExtractGeneralNames(IEnumerable<object> names) { - ISet result = new HashSet(); + var result = new HashSet<GeneralName>(); if (names != null) { foreach (object o in names) { - if (o is GeneralName) + if (o is GeneralName gn) { - result.Add(o); + result.Add(gn); } - else + else if (o is byte[] bs) { - result.Add(GeneralName.GetInstance(Asn1Object.FromByteArray((byte[]) o))); + result.Add(GeneralName.GetInstance(Asn1Object.FromByteArray(bs))); } + else + { + throw new InvalidOperationException(); + } } } diff --git a/crypto/src/x509/store/X509CertStoreSelector.cs b/crypto/src/x509/store/X509CertStoreSelector.cs index 197e8f26d..71b5419a7 100644 --- a/crypto/src/x509/store/X509CertStoreSelector.cs +++ b/crypto/src/x509/store/X509CertStoreSelector.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; @@ -20,11 +20,11 @@ namespace Org.BouncyCastle.X509.Store private int basicConstraints = -1; private X509Certificate certificate; private DateTimeObject certificateValid; - private ISet extendedKeyUsage; + private ISet<DerObjectIdentifier> extendedKeyUsage; private bool ignoreX509NameOrdering; private X509Name issuer; private bool[] keyUsage; - private ISet policy; + private ISet<DerObjectIdentifier> policy; private DateTimeObject privateKeyValid; private BigInteger serialNumber; private X509Name subject; @@ -91,7 +91,7 @@ namespace Org.BouncyCastle.X509.Store set { certificateValid = value; } } - public ISet ExtendedKeyUsage + public ISet<DerObjectIdentifier> ExtendedKeyUsage { get { return CopySet(extendedKeyUsage); } set { extendedKeyUsage = CopySet(value); } @@ -118,7 +118,7 @@ namespace Org.BouncyCastle.X509.Store /// <summary> /// An <code>ISet</code> of <code>DerObjectIdentifier</code> objects. /// </summary> - public ISet Policy + public ISet<DerObjectIdentifier> Policy { get { return CopySet(policy); } set { policy = CopySet(value); } @@ -300,10 +300,9 @@ namespace Org.BouncyCastle.X509.Store return b == null ? null : (bool[]) b.Clone(); } - private static ISet CopySet( - ISet s) + private static ISet<T> CopySet<T>(ISet<T> s) { - return s == null ? null : new HashSet(s); + return s == null ? null : new HashSet<T>(s); } private static SubjectPublicKeyInfo GetSubjectPublicKey( diff --git a/crypto/src/x509/store/X509CrlStoreSelector.cs b/crypto/src/x509/store/X509CrlStoreSelector.cs index dcf8f8876..365ec1d38 100644 --- a/crypto/src/x509/store/X509CrlStoreSelector.cs +++ b/crypto/src/x509/store/X509CrlStoreSelector.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; @@ -18,7 +18,7 @@ namespace Org.BouncyCastle.X509.Store private X509Certificate certificateChecking; private DateTimeObject dateAndTime; - private ICollection issuers; + private IList<X509Name> issuers; private BigInteger maxCrlNumber; private BigInteger minCrlNumber; @@ -70,10 +70,10 @@ namespace Org.BouncyCastle.X509.Store /// <summary> /// An <code>ICollection</code> of <code>X509Name</code> objects /// </summary> - public ICollection Issuers + public IList<X509Name> Issuers { - get { return Platform.CreateArrayList(issuers); } - set { issuers = Platform.CreateArrayList(value); } + get { return new List<X509Name>(issuers); } + set { issuers = new List<X509Name>(value); } } public BigInteger MaxCrlNumber |