diff options
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r-- | crypto/src/openpgp/PgpEncryptedData.cs | 29 | ||||
-rw-r--r-- | crypto/src/openpgp/WrappedGeneratorStream.cs | 5 |
2 files changed, 30 insertions, 4 deletions
diff --git a/crypto/src/openpgp/PgpEncryptedData.cs b/crypto/src/openpgp/PgpEncryptedData.cs index 5cdc0d533..bad4cb8cd 100644 --- a/crypto/src/openpgp/PgpEncryptedData.cs +++ b/crypto/src/openpgp/PgpEncryptedData.cs @@ -54,6 +54,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { Streams.ValidateBufferArguments(buffer, offset, count); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return Read(buffer.AsSpan(offset, count)); +#else int avail = bufEnd - bufStart; int pos = offset; @@ -73,8 +76,34 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp bufStart += count; return pos + count - offset; +#endif } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override int Read(Span<byte> buffer) + { + int avail = bufEnd - bufStart; + + int pos = 0, count = buffer.Length; + while (count > avail) + { + lookAhead.AsSpan(bufStart, avail).CopyTo(buffer[pos..]); + + bufStart += avail; + pos += avail; + count -= avail; + + if ((avail = FillBuffer()) < 1) + return pos; + } + + lookAhead.AsSpan(bufStart, count).CopyTo(buffer[pos..]); + bufStart += count; + + return pos + count; + } +#endif + public override int ReadByte() { if (bufStart < bufEnd) diff --git a/crypto/src/openpgp/WrappedGeneratorStream.cs b/crypto/src/openpgp/WrappedGeneratorStream.cs index c54ee0b3b..6f96dc9b8 100644 --- a/crypto/src/openpgp/WrappedGeneratorStream.cs +++ b/crypto/src/openpgp/WrappedGeneratorStream.cs @@ -13,10 +13,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp internal WrappedGeneratorStream(IStreamGenerator generator, Stream s) : base(s) { - if (generator == null) - throw new ArgumentNullException(nameof(generator)); - - m_generator = generator; + m_generator = generator ?? throw new ArgumentNullException(nameof(generator)); } protected override void Dispose(bool disposing) |