diff options
Diffstat (limited to 'crypto/src/bcpg/BcpgInputStream.cs')
-rw-r--r-- | crypto/src/bcpg/BcpgInputStream.cs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/crypto/src/bcpg/BcpgInputStream.cs b/crypto/src/bcpg/BcpgInputStream.cs index 7a19a90dd..3b6f61bbc 100644 --- a/crypto/src/bcpg/BcpgInputStream.cs +++ b/crypto/src/bcpg/BcpgInputStream.cs @@ -57,6 +57,21 @@ namespace Org.BouncyCastle.Bcpg return 1; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override int Read(Span<byte> buffer) + { + if (!next) + return m_in.Read(buffer); + + if (nextB < 0) + return 0; + + buffer[0] = (byte)nextB; + next = false; + return 1; + } +#endif + public byte[] ReadAll() { return Streams.ReadAll(this); @@ -312,9 +327,8 @@ namespace Org.BouncyCastle.Bcpg int readLen = (dataLength > count || dataLength < 0) ? count : dataLength; int len = m_in.Read(buffer, offset, readLen); if (len < 1) - { throw new EndOfStreamException("Premature end of stream in PartialInputStream"); - } + dataLength -= len; return len; } @@ -324,6 +338,29 @@ namespace Org.BouncyCastle.Bcpg return 0; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override int Read(Span<byte> buffer) + { + do + { + if (dataLength != 0) + { + int count = buffer.Length; + int readLen = (dataLength > count || dataLength < 0) ? count : dataLength; + int len = m_in.Read(buffer[..readLen]); + if (len < 1) + throw new EndOfStreamException("Premature end of stream in PartialInputStream"); + + dataLength -= len; + return len; + } + } + while (partial && ReadPartialDataLength() >= 0); + + return 0; + } +#endif + private int ReadPartialDataLength() { int l = m_in.ReadByte(); |