summary refs log tree commit diff
path: root/crypto/src/cms/CMSUtils.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-03-05 14:45:49 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-03-05 14:45:49 +0700
commit6b59dbbece3b1509b83b8479259a3c6059e9a60b (patch)
tree3dca66ea9a1e8aa02ac6099cde5844155783bd7b /crypto/src/cms/CMSUtils.cs
parentRefactor Asn1Set classes (diff)
downloadBouncyCastle.NET-ed25519-6b59dbbece3b1509b83b8479259a3c6059e9a60b.tar.xz
Support 'leaveOpen' in Asn1 streams
Diffstat (limited to 'crypto/src/cms/CMSUtils.cs')
-rw-r--r--crypto/src/cms/CMSUtils.cs25
1 files changed, 13 insertions, 12 deletions
diff --git a/crypto/src/cms/CMSUtils.cs b/crypto/src/cms/CMSUtils.cs
index 281e1e73a..0041d2fac 100644
--- a/crypto/src/cms/CMSUtils.cs
+++ b/crypto/src/cms/CMSUtils.cs
@@ -33,26 +33,27 @@ namespace Org.BouncyCastle.Cms
 			}
 		}
 
-		internal static ContentInfo ReadContentInfo(
-			byte[] input)
+		internal static ContentInfo ReadContentInfo(byte[] input)
 		{
-			// enforce limit checking as from a byte array
-			return ReadContentInfo(new Asn1InputStream(input));
-		}
+            using (var asn1In = new Asn1InputStream(input))
+			{
+                return ReadContentInfo(asn1In);
+            }
+        }
 
-		internal static ContentInfo ReadContentInfo(
-			Stream input)
+		internal static ContentInfo ReadContentInfo(Stream input)
 		{
-			// enforce some limit checking
-			return ReadContentInfo(new Asn1InputStream(input, MaximumMemory));
+            using (var asn1In = new Asn1InputStream(input, MaximumMemory, leaveOpen: true))
+            {
+                return ReadContentInfo(asn1In);
+            }
 		}
 
-		private static ContentInfo ReadContentInfo(
-			Asn1InputStream aIn)
+		private static ContentInfo ReadContentInfo(Asn1InputStream asn1In)
 		{
 			try
 			{
-				return ContentInfo.GetInstance(aIn.ReadObject());
+				return ContentInfo.GetInstance(asn1In.ReadObject());
 			}
 			catch (IOException e)
 			{