summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1Sequence.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-09 23:37:08 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-09 23:37:08 +0700
commit3c034ea8ac68da52b5ff128300b6780549d05bd1 (patch)
treea3f4572beee014d784560c0ba1282a4000e1a98a /crypto/src/asn1/Asn1Sequence.cs
parentFix DER encoding of lazy objects (diff)
downloadBouncyCastle.NET-ed25519-3c034ea8ac68da52b5ff128300b6780549d05bd1.tar.xz
Add DLSequence, DLSet for internal use
- improve sorting of sets
Diffstat (limited to 'crypto/src/asn1/Asn1Sequence.cs')
-rw-r--r--crypto/src/asn1/Asn1Sequence.cs49
1 files changed, 21 insertions, 28 deletions
diff --git a/crypto/src/asn1/Asn1Sequence.cs b/crypto/src/asn1/Asn1Sequence.cs
index e1d0fa675..8025492d2 100644
--- a/crypto/src/asn1/Asn1Sequence.cs
+++ b/crypto/src/asn1/Asn1Sequence.cs
@@ -10,9 +10,6 @@ namespace Org.BouncyCastle.Asn1
     public abstract class Asn1Sequence
         : Asn1Object, IEnumerable
     {
-        // NOTE: Only non-readonly to support LazyDerSequence
-        internal Asn1Encodable[] elements;
-
         /**
          * return an Asn1Sequence from the given object.
          *
@@ -57,49 +54,43 @@ namespace Org.BouncyCastle.Asn1
          * dealing with implicitly tagged sequences you really <b>should</b>
          * be using this method.
          *
-         * @param obj the tagged object.
-         * @param explicitly true if the object is meant to be explicitly tagged,
+         * @param taggedObject the tagged object.
+         * @param declaredExplicit true if the object is meant to be explicitly tagged,
          *          false otherwise.
          * @exception ArgumentException if the tagged object cannot
          *          be converted.
          */
-        public static Asn1Sequence GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+        public static Asn1Sequence GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            Asn1Object inner = obj.GetObject();
+            Asn1Object baseObject = taggedObject.GetObject();
 
-            if (explicitly)
+            if (declaredExplicit)
             {
-                if (!obj.IsExplicit())
+                if (!taggedObject.IsExplicit())
                     throw new ArgumentException("object implicit - explicit expected.");
 
-                return (Asn1Sequence) inner;
+                return (Asn1Sequence)baseObject;
             }
 
-            //
-            // constructed object which appears to be explicitly tagged
-            // when it should be implicit means we have to add the
-            // surrounding sequence.
-            //
-            if (obj.IsExplicit())
+            // If parsed as explicit though declared implicit, it should have been a sequence of one
+            if (taggedObject.IsExplicit())
             {
-                if (obj is BerTaggedObject)
-                {
-                    return new BerSequence(inner);
-                }
+                if (taggedObject is BerTaggedObject)
+                    return new BerSequence(baseObject);
 
-                return new DerSequence(inner);
+                return new DLSequence(baseObject);
             }
 
-            if (inner is Asn1Sequence)
-            {
-                return (Asn1Sequence) inner;
-            }
+            if (baseObject is Asn1Sequence)
+                return (Asn1Sequence)baseObject;
 
-            throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
+            throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(taggedObject),
+                "taggedObject");
         }
 
+        // NOTE: Only non-readonly to support LazyDLSequence
+        internal Asn1Encodable[] elements;
+
         protected internal Asn1Sequence()
         {
             this.elements = Asn1EncodableVector.EmptyElements;
@@ -286,5 +277,7 @@ namespace Org.BouncyCastle.Asn1
         internal abstract DerExternal ToAsn1External();
 
         internal abstract Asn1OctetString ToAsn1OctetString();
+
+        internal abstract Asn1Set ToAsn1Set();
     }
 }