summary refs log tree commit diff
path: root/crypto/src/bcpg/BcpgInputStream.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-05-23 22:44:57 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-05-23 22:44:57 +0700
commit98b3ce6512812cd1d91c60ca0e69d69c32838d8e (patch)
tree8af69c097b389fe494e97401f7808590314a5b6b /crypto/src/bcpg/BcpgInputStream.cs
parentAdd ValidateBufferArguments (diff)
downloadBouncyCastle.NET-ed25519-98b3ce6512812cd1d91c60ca0e69d69c32838d8e.tar.xz
Work on Stream classes
- consistent naming, ordering
- CanRead/Seek/Write fixes
- argument validation
- some cases of blocking zero-byte Read calls
Diffstat (limited to 'crypto/src/bcpg/BcpgInputStream.cs')
-rw-r--r--crypto/src/bcpg/BcpgInputStream.cs28
1 files changed, 9 insertions, 19 deletions
diff --git a/crypto/src/bcpg/BcpgInputStream.cs b/crypto/src/bcpg/BcpgInputStream.cs
index 5efef193a..87c3f3812 100644
--- a/crypto/src/bcpg/BcpgInputStream.cs
+++ b/crypto/src/bcpg/BcpgInputStream.cs
@@ -1,7 +1,6 @@
 using System;
 using System.IO;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
@@ -43,33 +42,22 @@ namespace Org.BouncyCastle.Bcpg
             return m_in.ReadByte();
         }
 
-        public override int Read(
-			byte[]	buffer,
-			int		offset,
-			int		count)
+        public override int Read(byte[] buffer, int offset, int count)
         {
-			// Strangely, when count == 0, we should still attempt to read a byte
-//			if (count == 0)
-//				return 0;
-
 			if (!next)
 				return m_in.Read(buffer, offset, count);
 
-			// We have next byte waiting, so return it
+            Streams.ValidateBufferArguments(buffer, offset, count);
 
 			if (nextB < 0)
-				return 0; // EndOfStream
-
-			if (buffer == null)
-				throw new ArgumentNullException("buffer");
-
-			buffer[offset] = (byte) nextB;
-			next = false;
+				return 0;
 
-			return 1;
+            buffer[offset] = (byte)nextB;
+            next = false;
+            return 1;
         }
 
-		public byte[] ReadAll()
+        public byte[] ReadAll()
         {
 			return Streams.ReadAll(this);
 		}
@@ -323,6 +311,8 @@ namespace Org.BouncyCastle.Bcpg
 
 			public override int Read(byte[] buffer, int offset, int count)
 			{
+                Streams.ValidateBufferArguments(buffer, offset, count);
+
 				do
 				{
 					if (dataLength != 0)