summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1InputStream.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/Asn1InputStream.cs26
1 files changed, 19 insertions, 7 deletions
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs
index 4f99301b3..d7edae9e0 100644
--- a/crypto/src/asn1/Asn1InputStream.cs
+++ b/crypto/src/asn1/Asn1InputStream.cs
@@ -133,22 +133,29 @@ namespace Org.BouncyCastle.Asn1
             return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
         }
 
-        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)
+        internal virtual Asn1EncodableVector ReadVector()
         {
-            if (dIn.Remaining < 1)
+            Asn1Object o = ReadObject();
+            if (null == o)
                 return new Asn1EncodableVector(0);
 
-            Asn1InputStream subStream = new Asn1InputStream(dIn);
             Asn1EncodableVector v = new Asn1EncodableVector();
-            Asn1Object o;
-            while ((o = subStream.ReadObject()) != null)
+            do
             {
                 v.Add(o);
             }
-
+            while ((o = ReadObject()) != null);
             return v;
         }
 
+        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)
+        {
+            if (dIn.Remaining < 1)
+                return new Asn1EncodableVector(0);
+
+            return new Asn1InputStream(dIn).ReadVector();
+        }
+
         internal virtual DerSequence CreateDerSequence(
             DefiniteLengthInputStream dIn)
         {
@@ -405,7 +412,12 @@ namespace Org.BouncyCastle.Asn1
                 case Asn1Tags.Integer:
                     return new DerInteger(bytes, false);
                 case Asn1Tags.Null:
-                    return DerNull.Instance;   // actual content is ignored (enforce 0 length?)
+                {
+                    if (0 != bytes.Length)
+                        throw new InvalidOperationException("malformed NULL encoding encountered");
+
+                    return DerNull.Instance;
+                }
                 case Asn1Tags.NumericString:
                     return new DerNumericString(bytes);
                 case Asn1Tags.OctetString: