diff options
Diffstat (limited to 'crypto/src/util/io/PushbackStream.cs')
-rw-r--r-- | crypto/src/util/io/PushbackStream.cs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/crypto/src/util/io/PushbackStream.cs b/crypto/src/util/io/PushbackStream.cs index 2ceb64361..15ba70501 100644 --- a/crypto/src/util/io/PushbackStream.cs +++ b/crypto/src/util/io/PushbackStream.cs @@ -13,7 +13,20 @@ namespace Org.BouncyCastle.Utilities.IO { } - public override int Read(byte[] buffer, int offset, int count) +#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override void CopyTo(Stream destination, int bufferSize) + { + if (m_buf != -1) + { + destination.WriteByte((byte)m_buf); + m_buf = -1; + } + + s.CopyTo(destination, bufferSize); + } +#endif + + public override int Read(byte[] buffer, int offset, int count) { Streams.ValidateBufferArguments(buffer, offset, count); @@ -27,10 +40,27 @@ namespace Org.BouncyCastle.Utilities.IO return 1; } - return base.Read(buffer, offset, count); + return s.Read(buffer, offset, count); } - public override int ReadByte() +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override int Read(Span<byte> buffer) + { + if (m_buf != -1) + { + if (buffer.IsEmpty) + return 0; + + buffer[0] = (byte)m_buf; + m_buf = -1; + return 1; + } + + return s.Read(buffer); + } +#endif + + public override int ReadByte() { if (m_buf != -1) { |