summary refs log tree commit diff
path: root/crypto/src/asn1/x9
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 12:06:03 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 12:06:03 +0700
commit913eada3ad9394f1327a1feb80a3261f7c6e55bb (patch)
tree6366c1e196ad2ac249edf12a4d41d52ee2d28629 /crypto/src/asn1/x9
parentRefactoring around PrivateKeyInfo (diff)
downloadBouncyCastle.NET-ed25519-913eada3ad9394f1327a1feb80a3261f7c6e55bb.tar.xz
Deprecated Asn1TaggedObject.GetObject and refactor
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/x9/OtherInfo.cs8
-rw-r--r--crypto/src/asn1/x9/X962Parameters.cs29
2 files changed, 20 insertions, 17 deletions
diff --git a/crypto/src/asn1/x9/OtherInfo.cs b/crypto/src/asn1/x9/OtherInfo.cs
index c1819a5ee..19bf3f401 100644
--- a/crypto/src/asn1/x9/OtherInfo.cs
+++ b/crypto/src/asn1/x9/OtherInfo.cs
@@ -32,13 +32,13 @@ namespace Org.BouncyCastle.Asn1.X9
             {
                 Asn1TaggedObject o = (Asn1TaggedObject)e.Current;
 
-				if (o.TagNo == 0)
+				if (o.HasContextTag(0))
                 {
-                    partyAInfo = (Asn1OctetString)o.GetObject();
+                    partyAInfo = (Asn1OctetString)o.GetExplicitBaseObject();
                 }
-                else if ((int) o.TagNo == 2)
+                else if (o.HasContextTag(2))
                 {
-                    suppPubInfo = (Asn1OctetString)o.GetObject();
+                    suppPubInfo = (Asn1OctetString)o.GetExplicitBaseObject();
                 }
             }
         }
diff --git a/crypto/src/asn1/x9/X962Parameters.cs b/crypto/src/asn1/x9/X962Parameters.cs
index b863f4bfd..af1fce1db 100644
--- a/crypto/src/asn1/x9/X962Parameters.cs
+++ b/crypto/src/asn1/x9/X962Parameters.cs
@@ -9,24 +9,22 @@ namespace Org.BouncyCastle.Asn1.X9
     {
         private readonly Asn1Object _params;
 
-		public static X962Parameters GetInstance(
-			object obj)
+		public static X962Parameters GetInstance(object obj)
 		{
-			if (obj == null || obj is X962Parameters) 
-			{
-				return (X962Parameters)obj;
-			}
+            if (obj == null)
+                return null;
 
-			if (obj is Asn1Object) 
-			{
-				return new X962Parameters((Asn1Object)obj);
-			}
+			if (obj is X962Parameters x962Parameters)
+				return x962Parameters;
 
-			if (obj is byte[])
+			if (obj is Asn1Object asn1Object)
+				return new X962Parameters(asn1Object);
+
+			if (obj is byte[] bytes)
 			{
 				try
 				{
-					return new X962Parameters(Asn1Object.FromByteArray((byte[])obj));
+					return new X962Parameters(Asn1Object.FromByteArray(bytes));
 				}
 				catch (Exception e)
 				{
@@ -34,9 +32,14 @@ namespace Org.BouncyCastle.Asn1.X9
 				}
 			}
 
-			throw new ArgumentException("unknown object in getInstance()");
+			throw new ArgumentException("unknown object in GetInstance()");
 		}
 
+        public static X962Parameters GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
+        }
+
 		public X962Parameters(
             X9ECParameters ecParameters)
         {