summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1InputStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/Asn1InputStream.cs')
-rw-r--r--crypto/src/asn1/Asn1InputStream.cs23
1 files changed, 10 insertions, 13 deletions
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs
index a94ae5235..0c7461c98 100644
--- a/crypto/src/asn1/Asn1InputStream.cs
+++ b/crypto/src/asn1/Asn1InputStream.cs
@@ -98,13 +98,13 @@ namespace Org.BouncyCastle.Asn1
                         //
                         // yes, people actually do this...
                         //
-                        return new BerOctetString(BuildDerEncodableVector(defIn));
+                        return new BerOctetString(ReadVector(defIn));
                     case Asn1Tags.Sequence:
                         return CreateDerSequence(defIn);
                     case Asn1Tags.Set:
                         return CreateDerSet(defIn);
                     case Asn1Tags.External:
-                        return new DerExternal(BuildDerEncodableVector(defIn));                
+                        return new DerExternal(ReadVector(defIn));                
                     default:
                         throw new IOException("unknown tag " + tagNo + " encountered");
                 }
@@ -113,12 +113,15 @@ namespace Org.BouncyCastle.Asn1
             return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
         }
 
-        internal Asn1EncodableVector BuildEncodableVector()
+        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)
         {
-            Asn1EncodableVector v = new Asn1EncodableVector();
+            if (dIn.Remaining < 1)
+                return new Asn1EncodableVector(0);
 
+            Asn1InputStream subStream = new Asn1InputStream(dIn);
+            Asn1EncodableVector v = new Asn1EncodableVector();
             Asn1Object o;
-            while ((o = ReadObject()) != null)
+            while ((o = subStream.ReadObject()) != null)
             {
                 v.Add(o);
             }
@@ -126,22 +129,16 @@ namespace Org.BouncyCastle.Asn1
             return v;
         }
 
-        internal virtual Asn1EncodableVector BuildDerEncodableVector(
-            DefiniteLengthInputStream dIn)
-        {
-            return new Asn1InputStream(dIn).BuildEncodableVector();
-        }
-
         internal virtual DerSequence CreateDerSequence(
             DefiniteLengthInputStream dIn)
         {
-            return DerSequence.FromVector(BuildDerEncodableVector(dIn));
+            return DerSequence.FromVector(ReadVector(dIn));
         }
 
         internal virtual DerSet CreateDerSet(
             DefiniteLengthInputStream dIn)
         {
-            return DerSet.FromVector(BuildDerEncodableVector(dIn), false);
+            return DerSet.FromVector(ReadVector(dIn), false);
         }
 
         public Asn1Object ReadObject()