summary refs log tree commit diff
path: root/crypto/src/asn1/IndefiniteLengthInputStream.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-01 14:39:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-01 14:39:54 +0700
commit716a491e3ed312da6c80a74e327d62dd4388b11e (patch)
tree0adabea28431857f372256233ddd4b2e0982190b /crypto/src/asn1/IndefiniteLengthInputStream.cs
parentPackage with LICENSE.md file (diff)
downloadBouncyCastle.NET-ed25519-716a491e3ed312da6c80a74e327d62dd4388b11e.tar.xz
More Span-based Stream methods
Diffstat (limited to 'crypto/src/asn1/IndefiniteLengthInputStream.cs')
-rw-r--r--crypto/src/asn1/IndefiniteLengthInputStream.cs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crypto/src/asn1/IndefiniteLengthInputStream.cs b/crypto/src/asn1/IndefiniteLengthInputStream.cs
index 1c8bd9a15..e192e9e8b 100644
--- a/crypto/src/asn1/IndefiniteLengthInputStream.cs
+++ b/crypto/src/asn1/IndefiniteLengthInputStream.cs
@@ -57,7 +57,28 @@ namespace Org.BouncyCastle.Asn1
 			return numRead + 1;
 		}
 
-		public override int ReadByte()
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public override int Read(Span<byte> buffer)
+        {
+            // Only use this optimisation if we aren't checking for 00
+            if (_eofOn00 || buffer.Length <= 1)
+                return base.Read(buffer);
+
+            if (_lookAhead < 0)
+                return 0;
+
+            int numRead = _in.Read(buffer[1..]);
+            if (numRead <= 0)
+                throw new EndOfStreamException();
+
+            buffer[0] = (byte)_lookAhead;
+            _lookAhead = RequireByte();
+
+            return numRead + 1;
+        }
+#endif
+
+        public override int ReadByte()
 		{
             if (_eofOn00 && _lookAhead <= 0)
             {