summary refs log tree commit diff
path: root/crypto/src/asn1/DERExternal.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-18 13:46:18 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-18 13:46:18 +0700
commit4fccb8f490eefe7181558b2c3376ab23c33632ee (patch)
treefe8c1877bb5567cb4823823af77e5c8a38423db8 /crypto/src/asn1/DERExternal.cs
parentASN.1: Staged encoding (diff)
downloadBouncyCastle.NET-ed25519-4fccb8f490eefe7181558b2c3376ab23c33632ee.tar.xz
ASN.1: Port of bc-java TYPE instances
- we use Meta.Instance here due to syntax restrictions
- also reworked some ASN.1 string types
Diffstat (limited to 'crypto/src/asn1/DERExternal.cs')
-rw-r--r--crypto/src/asn1/DERExternal.cs25
1 files changed, 15 insertions, 10 deletions
diff --git a/crypto/src/asn1/DERExternal.cs b/crypto/src/asn1/DERExternal.cs
index 67dad0534..28d5cc46a 100644
--- a/crypto/src/asn1/DERExternal.cs
+++ b/crypto/src/asn1/DERExternal.cs
@@ -11,6 +11,18 @@ namespace Org.BouncyCastle.Asn1
 	public class DerExternal
 		: Asn1Object
 	{
+        internal class Meta : Asn1UniversalType
+        {
+            internal static readonly Asn1UniversalType Instance = new Meta();
+
+            private Meta() : base(typeof(DerExternal), Asn1Tags.External) {}
+
+            internal override Asn1Object FromImplicitConstructed(Asn1Sequence sequence)
+            {
+                return sequence.ToAsn1External();
+            }
+        }
+
         public static DerExternal GetInstance(object obj)
         {
             if (obj == null || obj is DerExternal)
@@ -27,7 +39,7 @@ namespace Org.BouncyCastle.Asn1
             {
                 try
                 {
-                    return GetInstance(FromByteArray((byte[])obj));
+                    return (DerExternal)Meta.Instance.FromByteArray((byte[])obj);
                 }
                 catch (IOException e)
                 {
@@ -38,16 +50,9 @@ namespace Org.BouncyCastle.Asn1
             throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
         }
 
-        public static DerExternal GetInstance(Asn1TaggedObject taggedObject, bool isExplicit)
+        public static DerExternal GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            Asn1Object baseObject = taggedObject.GetObject();
-
-            if (isExplicit || baseObject is DerExternal)
-            {
-                return GetInstance(baseObject);
-            }
-
-            return Asn1Sequence.GetInstance(baseObject).ToAsn1External();
+            return (DerExternal)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
         }
 
 		private readonly DerObjectIdentifier directReference;