summary refs log tree commit diff
path: root/crypto/src/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r--crypto/src/asn1/BEROctetStringGenerator.cs47
-rw-r--r--crypto/src/asn1/ConstructedBitStream.cs10
-rw-r--r--crypto/src/asn1/ConstructedOctetStream.cs10
3 files changed, 36 insertions, 31 deletions
diff --git a/crypto/src/asn1/BEROctetStringGenerator.cs b/crypto/src/asn1/BEROctetStringGenerator.cs
index de0a6c0b8..bed40b566 100644
--- a/crypto/src/asn1/BEROctetStringGenerator.cs
+++ b/crypto/src/asn1/BEROctetStringGenerator.cs
@@ -60,48 +60,49 @@ namespace Org.BouncyCastle.Asn1
 				_derOut = Asn1OutputStream.Create(_gen.Out, Asn1Encodable.Der);
 			}
 
-			public override void WriteByte(
-				byte b)
+			public override void Write(byte[] buffer, int offset, int count)
 			{
-				_buf[_off++] = b;
+				Streams.ValidateBufferArguments(buffer, offset, count);
 
-				if (_off == _buf.Length)
-				{
-					DerOctetString.Encode(_derOut, _buf, 0, _off);
-					_off = 0;
-				}
-			}
-
-			public override void Write(byte[] b, int off, int len)
-			{
                 int bufLen = _buf.Length;
                 int available = bufLen - _off;
-                if (len < available)
+                if (count < available)
                 {
-                    Array.Copy(b, off, _buf, _off, len);
-                    _off += len;
+                    Array.Copy(buffer, offset, _buf, _off, count);
+                    _off += count;
                     return;
                 }
 
-                int count = 0;
+                int pos = 0;
                 if (_off > 0)
                 {
-                    Array.Copy(b, off, _buf, _off, available);
-                    count += available;
+                    Array.Copy(buffer, offset, _buf, _off, available);
+                    pos += available;
                     DerOctetString.Encode(_derOut, _buf, 0, bufLen);
                 }
 
                 int remaining;
-                while ((remaining = len - count) >= bufLen)
+                while ((remaining = count - pos) >= bufLen)
                 {
-                    DerOctetString.Encode(_derOut, b, off + count, bufLen);
-                    count += bufLen;
+                    DerOctetString.Encode(_derOut, buffer, offset + pos, bufLen);
+                    pos += bufLen;
                 }
 
-                Array.Copy(b, off + count, _buf, 0, remaining);
+                Array.Copy(buffer, offset + pos, _buf, 0, remaining);
                 this._off = remaining;
             }
 
+			public override void WriteByte(byte value)
+			{
+				_buf[_off++] = value;
+
+				if (_off == _buf.Length)
+				{
+					DerOctetString.Encode(_derOut, _buf, 0, _off);
+					_off = 0;
+				}
+			}
+
 #if PORTABLE
             protected override void Dispose(bool disposing)
             {
@@ -119,7 +120,7 @@ namespace Org.BouncyCastle.Asn1
                 base.Dispose(disposing);
             }
 #else
-            public override void Close()
+			public override void Close()
 			{
 				if (_off != 0)
 				{
diff --git a/crypto/src/asn1/ConstructedBitStream.cs b/crypto/src/asn1/ConstructedBitStream.cs
index 7c9e7c9e4..49f54fc1b 100644
--- a/crypto/src/asn1/ConstructedBitStream.cs
+++ b/crypto/src/asn1/ConstructedBitStream.cs
@@ -29,9 +29,11 @@ namespace Org.BouncyCastle.Asn1
             get { return m_padBits; }
         }
 
-        public override int Read(byte[] buf, int off, int len)
+        public override int Read(byte[] buffer, int offset, int count)
         {
-            if (len < 1)
+            Streams.ValidateBufferArguments(buffer, offset, count);
+
+            if (count < 1)
                 return 0;
 
             if (m_currentStream == null)
@@ -51,13 +53,13 @@ namespace Org.BouncyCastle.Asn1
 
             for (;;)
             {
-                int numRead = m_currentStream.Read(buf, off + totalRead, len - totalRead);
+                int numRead = m_currentStream.Read(buffer, offset + totalRead, count - totalRead);
 
                 if (numRead > 0)
                 {
                     totalRead += numRead;
 
-                    if (totalRead == len)
+                    if (totalRead == count)
                         return totalRead;
                 }
                 else
diff --git a/crypto/src/asn1/ConstructedOctetStream.cs b/crypto/src/asn1/ConstructedOctetStream.cs
index 5541939b6..12aa14e74 100644
--- a/crypto/src/asn1/ConstructedOctetStream.cs
+++ b/crypto/src/asn1/ConstructedOctetStream.cs
@@ -18,9 +18,11 @@ namespace Org.BouncyCastle.Asn1
 			m_parser = parser;
 		}
 
-		public override int Read(byte[] buf, int off, int len)
+		public override int Read(byte[] buffer, int offset, int count)
 		{
-            if (len < 1)
+			Streams.ValidateBufferArguments(buffer, offset, count);
+
+			if (count < 1)
                 return 0;
 
 			if (m_currentStream == null)
@@ -40,13 +42,13 @@ namespace Org.BouncyCastle.Asn1
 
 			for (;;)
 			{
-				int numRead = m_currentStream.Read(buf, off + totalRead, len - totalRead);
+				int numRead = m_currentStream.Read(buffer, offset + totalRead, count - totalRead);
 
 				if (numRead > 0)
 				{
 					totalRead += numRead;
 
-					if (totalRead == len)
+					if (totalRead == count)
 						return totalRead;
 				}
 				else