summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-21 13:53:34 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-21 13:53:34 +0700
commitfd62c077b82454d94ee2419992c886ed821777e3 (patch)
tree2ecd30ac0d0894fd3981be7232aa6237ba65afb7 /crypto/src/util
parentASN.1: Tagged object parser improvements (diff)
downloadBouncyCastle.NET-ed25519-fd62c077b82454d94ee2419992c886ed821777e3.tar.xz
Use Seek when available
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/io/PushbackStream.cs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crypto/src/util/io/PushbackStream.cs b/crypto/src/util/io/PushbackStream.cs
index 954694259..d51e195ca 100644
--- a/crypto/src/util/io/PushbackStream.cs
+++ b/crypto/src/util/io/PushbackStream.cs
@@ -1,27 +1,24 @@
 using System;
 using System.IO;
 
-using Org.BouncyCastle.Asn1.Utilities;
-
 namespace Org.BouncyCastle.Utilities.IO
 {
 	public class PushbackStream
 		: FilterStream
 	{
-		private int buf = -1;
+		private int m_buf = -1;
 
-		public PushbackStream(
-			Stream s)
+		public PushbackStream(Stream s)
 			: base(s)
 		{
 		}
 
 		public override int ReadByte()
 		{
-			if (buf != -1)
+			if (m_buf != -1)
 			{
-				int tmp = buf;
-				buf = -1;
+				int tmp = m_buf;
+				m_buf = -1;
 				return tmp;
 			}
 
@@ -30,11 +27,13 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public override int Read(byte[] buffer, int offset, int count)
 		{
-			if (buf != -1 && count > 0)
+            if (count < 1)
+                return 0;
+
+			if (m_buf != -1)
 			{
-				// TODO Can this case be made more efficient?
-				buffer[offset] = (byte) buf;
-				buf = -1;
+				buffer[offset] = (byte)m_buf;
+				m_buf = -1;
 				return 1;
 			}
 
@@ -43,10 +42,10 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public virtual void Unread(int b)
 		{
-			if (buf != -1)
+			if (m_buf != -1)
 				throw new InvalidOperationException("Can only push back one byte");
 
-			buf = b & 0xFF;
+			m_buf = b & 0xFF;
 		}
 	}
 }