summary refs log tree commit diff
path: root/crypto/src/asn1/x509
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/x509
parentRefactoring around PrivateKeyInfo (diff)
downloadBouncyCastle.NET-ed25519-913eada3ad9394f1327a1feb80a3261f7c6e55bb.tar.xz
Deprecated Asn1TaggedObject.GetObject and refactor
Diffstat (limited to 'crypto/src/asn1/x509')
-rw-r--r--crypto/src/asn1/x509/AttCertIssuer.cs6
-rw-r--r--crypto/src/asn1/x509/DisplayText.cs22
-rw-r--r--crypto/src/asn1/x509/Time.cs2
-rw-r--r--crypto/src/asn1/x509/X509Extensions.cs6
4 files changed, 19 insertions, 17 deletions
diff --git a/crypto/src/asn1/x509/AttCertIssuer.cs b/crypto/src/asn1/x509/AttCertIssuer.cs
index 9d74f631e..39ff28790 100644
--- a/crypto/src/asn1/x509/AttCertIssuer.cs
+++ b/crypto/src/asn1/x509/AttCertIssuer.cs
@@ -36,11 +36,9 @@ namespace Org.BouncyCastle.Asn1.X509
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
         }
 
-        public static AttCertIssuer GetInstance(
-			Asn1TaggedObject	obj,
-			bool				isExplicit)
+        public static AttCertIssuer GetInstance(Asn1TaggedObject obj, bool isExplicit)
 		{
-			return GetInstance(obj.GetObject()); // must be explictly tagged
+            return Asn1Utilities.GetInstanceFromChoice(obj, isExplicit, GetInstance);
 		}
 
 		/// <summary>
diff --git a/crypto/src/asn1/x509/DisplayText.cs b/crypto/src/asn1/x509/DisplayText.cs
index 39b3c98d7..772e3f522 100644
--- a/crypto/src/asn1/x509/DisplayText.cs
+++ b/crypto/src/asn1/x509/DisplayText.cs
@@ -140,23 +140,23 @@ namespace Org.BouncyCastle.Asn1.X509
 			this.contents = contents;
 		}
 
-		public static DisplayText GetInstance(
-			object obj)
+		public static DisplayText GetInstance(object obj)
 		{
-			if (obj is IAsn1String)
-			{
-				return new DisplayText((IAsn1String) obj);
-			}
+			if (obj is IAsn1String asn1String)
+				return new DisplayText(asn1String);
 
-			if (obj is DisplayText)
-			{
-				return (DisplayText) obj;
-			}
+			if (obj is DisplayText displayText)
+				return displayText;
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
 
-		public override Asn1Object ToAsn1Object()
+		public static DisplayText GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+		{
+            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
+        }
+
+        public override Asn1Object ToAsn1Object()
 		{
 			return (Asn1Object) contents;
 		}
diff --git a/crypto/src/asn1/x509/Time.cs b/crypto/src/asn1/x509/Time.cs
index f7746257c..99d141c43 100644
--- a/crypto/src/asn1/x509/Time.cs
+++ b/crypto/src/asn1/x509/Time.cs
@@ -24,7 +24,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
         public static Time GetInstance(Asn1TaggedObject	taggedObject, bool declaredExplicit)
         {
-            return GetInstance(taggedObject.GetObject());
+            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
         }
 
         private readonly Asn1Object m_timeObject;
diff --git a/crypto/src/asn1/x509/X509Extensions.cs b/crypto/src/asn1/x509/X509Extensions.cs
index 390bf46b7..d4497d255 100644
--- a/crypto/src/asn1/x509/X509Extensions.cs
+++ b/crypto/src/asn1/x509/X509Extensions.cs
@@ -215,7 +215,11 @@ namespace Org.BouncyCastle.Asn1.X509
                 return new X509Extensions(sequence);
 
             if (obj is Asn1TaggedObject taggedObject)
-                return GetInstance(taggedObject.GetObject());
+            {
+                Asn1Utilities.CheckTagClass(taggedObject, Asn1Tags.ContextSpecific);
+
+                return GetInstance(taggedObject.GetBaseObject().ToAsn1Object());
+            }
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
         }