summary refs log tree commit diff
path: root/crypto/src/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-03-09 16:17:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-03-09 16:17:26 +0700
commit95db89f0bcf07e49ed86b235f3953718a50b6f54 (patch)
tree3354d8f3687f37f14800eb75627bf34630d90fdf /crypto/src/cms
parentFix some warnings (diff)
downloadBouncyCastle.NET-ed25519-95db89f0bcf07e49ed86b235f3953718a50b6f54.tar.xz
Refactoring around Stream usage
Diffstat (limited to 'crypto/src/cms')
-rw-r--r--crypto/src/cms/CMSTypedStream.cs66
1 files changed, 15 insertions, 51 deletions
diff --git a/crypto/src/cms/CMSTypedStream.cs b/crypto/src/cms/CMSTypedStream.cs
index 624833848..4cd8014aa 100644
--- a/crypto/src/cms/CMSTypedStream.cs
+++ b/crypto/src/cms/CMSTypedStream.cs
@@ -1,4 +1,3 @@
-using System;
 using System.IO;
 
 using Org.BouncyCastle.Asn1.Pkcs;
@@ -6,69 +5,34 @@ using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
 {
-	public class CmsTypedStream
+    public class CmsTypedStream
 	{
-		private const int BufferSize = 32 * 1024;
+		private readonly string	m_oid;
+		private readonly Stream	m_in;
 
-		private readonly string	_oid;
-		private readonly Stream	_in;
-
-		public CmsTypedStream(
-			Stream inStream)
-			: this(PkcsObjectIdentifiers.Data.Id, inStream, BufferSize)
+		public CmsTypedStream(Stream inStream)
+			: this(PkcsObjectIdentifiers.Data.Id, inStream)
 		{
 		}
 
-		public CmsTypedStream(
-			string oid,
-			Stream inStream)
-			: this(oid, inStream, BufferSize)
+		public CmsTypedStream(string oid, Stream inStream)
+			: this(oid, inStream, Streams.DefaultBufferSize)
 		{
 		}
 
-		public CmsTypedStream(
-			string	oid,
-			Stream	inStream,
-			int		bufSize)
+		public CmsTypedStream(string oid, Stream inStream, int bufSize)
 		{
-			_oid = oid;
-			_in = new FullReaderStream(new BufferedStream(inStream, bufSize));
-		}
+			m_oid = oid;
+            m_in = new BufferedFilterStream(inStream, bufSize);
+        }
 
-		public string ContentType
-		{
-			get { return _oid; }
-		}
+		public string ContentType => m_oid;
 
-		public Stream ContentStream
-		{
-			get { return _in; }
-		}
+		public Stream ContentStream => m_in;
 
 		public void Drain()
 		{
-			Streams.Drain(_in);
-            _in.Dispose();
+			using (m_in) Streams.Drain(m_in);
 		}
-
-		private class FullReaderStream : FilterStream
-		{
-			internal FullReaderStream(Stream input)
-				: base(input)
-			{
-			}
-
-            public override int Read(byte[]	buf, int off, int len)
-			{
-				return Streams.ReadFully(s, buf, off, len);
-			}
-
-#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            public override int Read(Span<byte> buffer)
-            {
-                return Streams.ReadFully(s, buffer);
-            }
-#endif
-        }
-    }
+	}
 }