summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1Object.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-14 17:29:37 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-14 17:29:37 +0700
commit21f2eacb456c933df98a59a78143dfd1a05bb951 (patch)
tree368016a4f0a7885d0e01a952489b117c6e3e134a /crypto/src/asn1/Asn1Object.cs
parentUpdate ECPrivateKeyStructure following Java API (diff)
downloadBouncyCastle.NET-ed25519-21f2eacb456c933df98a59a78143dfd1a05bb951.tar.xz
Check there is no trailing data in Asn1Object.FromByteArray
Diffstat (limited to 'crypto/src/asn1/Asn1Object.cs')
-rw-r--r--crypto/src/asn1/Asn1Object.cs13
1 files changed, 9 insertions, 4 deletions
diff --git a/crypto/src/asn1/Asn1Object.cs b/crypto/src/asn1/Asn1Object.cs
index 08bd599c1..a86fdbb4a 100644
--- a/crypto/src/asn1/Asn1Object.cs
+++ b/crypto/src/asn1/Asn1Object.cs
@@ -13,13 +13,18 @@ namespace Org.BouncyCastle.Asn1
 		public static Asn1Object FromByteArray(
 			byte[] data)
 		{
-			try
+            try
 			{
-				return new Asn1InputStream(data).ReadObject();
+                MemoryStream input = new MemoryStream(data, false);
+                Asn1InputStream asn1 = new Asn1InputStream(input, data.Length);
+                Asn1Object result = asn1.ReadObject();
+                if (input.Position != input.Length)
+                    throw new IOException("extra data found after object");
+                return result;
 			}
 			catch (InvalidCastException)
 			{
-				throw new IOException("cannot recognise object in stream");    
+				throw new IOException("cannot recognise object in byte array");
 			}
 		}
 
@@ -36,7 +41,7 @@ namespace Org.BouncyCastle.Asn1
 			}
 			catch (InvalidCastException)
 			{
-				throw new IOException("cannot recognise object in stream");    
+				throw new IOException("cannot recognise object in stream");
 			}
 		}