diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 02:19:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 02:19:14 +0700 |
commit | 4ea1816cffd5c8663bc9ae1234df0a70ef23fcd6 (patch) | |
tree | eb4fe294ef230435928a573fadef3047b4466e9b /crypto/src/x509 | |
parent | Implement generic IEnumerable in ASN.1 classes (diff) | |
download | BouncyCastle.NET-ed25519-4ea1816cffd5c8663bc9ae1234df0a70ef23fcd6.tar.xz |
Generics migration work
Diffstat (limited to 'crypto/src/x509')
-rw-r--r-- | crypto/src/x509/IX509Extension.cs | 6 | ||||
-rw-r--r-- | crypto/src/x509/X509ExtensionBase.cs | 42 | ||||
-rw-r--r-- | crypto/src/x509/X509Utilities.cs | 3 |
3 files changed, 19 insertions, 32 deletions
diff --git a/crypto/src/x509/IX509Extension.cs b/crypto/src/x509/IX509Extension.cs index a08f5e052..7d7a06c04 100644 --- a/crypto/src/x509/IX509Extension.cs +++ b/crypto/src/x509/IX509Extension.cs @@ -1,7 +1,7 @@ using System; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; -using Org.BouncyCastle.Utilities.Collections; namespace Org.BouncyCastle.X509 { @@ -11,13 +11,13 @@ namespace Org.BouncyCastle.X509 /// Get all critical extension values, by oid /// </summary> /// <returns>IDictionary with string (OID) keys and Asn1OctetString values</returns> - ISet GetCriticalExtensionOids(); + ISet<string> GetCriticalExtensionOids(); /// <summary> /// Get all non-critical extension values, by oid /// </summary> /// <returns>IDictionary with string (OID) keys and Asn1OctetString values</returns> - ISet GetNonCriticalExtensionOids(); + ISet<string> GetNonCriticalExtensionOids(); Asn1OctetString GetExtensionValue(DerObjectIdentifier oid); } diff --git a/crypto/src/x509/X509ExtensionBase.cs b/crypto/src/x509/X509ExtensionBase.cs index af3907773..d9df364b0 100644 --- a/crypto/src/x509/X509ExtensionBase.cs +++ b/crypto/src/x509/X509ExtensionBase.cs @@ -1,8 +1,8 @@ using System; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities.Collections; namespace Org.BouncyCastle.X509 { @@ -11,33 +11,29 @@ namespace Org.BouncyCastle.X509 { protected abstract X509Extensions GetX509Extensions(); - protected virtual ISet GetExtensionOids( - bool critical) + protected virtual ISet<string> GetExtensionOids(bool critical) { X509Extensions extensions = GetX509Extensions(); - if (extensions != null) + if (extensions == null) + return null; + + var set = new HashSet<string>(); + foreach (DerObjectIdentifier oid in extensions.ExtensionOids) { - HashSet set = new HashSet(); - foreach (DerObjectIdentifier oid in extensions.ExtensionOids) + X509Extension ext = extensions.GetExtension(oid); + if (ext.IsCritical == critical) { - X509Extension ext = extensions.GetExtension(oid); - if (ext.IsCritical == critical) - { - set.Add(oid.Id); - } + set.Add(oid.Id); } - - return set; } - - return null; + return set; } /// <summary> /// Get non critical extensions. /// </summary> /// <returns>A set of non critical extension oids.</returns> - public virtual ISet GetNonCriticalExtensionOids() + public virtual ISet<string> GetNonCriticalExtensionOids() { return GetExtensionOids(false); } @@ -46,24 +42,14 @@ namespace Org.BouncyCastle.X509 /// Get any critical extensions. /// </summary> /// <returns>A sorted list of critical entension.</returns> - public virtual ISet GetCriticalExtensionOids() + public virtual ISet<string> GetCriticalExtensionOids() { return GetExtensionOids(true); } public virtual Asn1OctetString GetExtensionValue(DerObjectIdentifier oid) { - X509Extensions exts = GetX509Extensions(); - if (exts != null) - { - X509Extension ext = exts.GetExtension(oid); - if (ext != null) - { - return ext.Value; - } - } - - return null; + return GetX509Extensions()?.GetExtension(oid)?.Value; } } } diff --git a/crypto/src/x509/X509Utilities.cs b/crypto/src/x509/X509Utilities.cs index 461a545f9..85f24f26a 100644 --- a/crypto/src/x509/X509Utilities.cs +++ b/crypto/src/x509/X509Utilities.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.CryptoPro; @@ -21,7 +22,7 @@ namespace Org.BouncyCastle.X509 { private static readonly IDictionary algorithms = Platform.CreateHashtable(); private static readonly IDictionary exParams = Platform.CreateHashtable(); - private static readonly ISet noParams = new HashSet(); + private static readonly HashSet<DerObjectIdentifier> noParams = new HashSet<DerObjectIdentifier>(); static X509Utilities() { |