diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-05-23 22:44:57 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-05-23 22:44:57 +0700 |
commit | 98b3ce6512812cd1d91c60ca0e69d69c32838d8e (patch) | |
tree | 8af69c097b389fe494e97401f7808590314a5b6b /crypto/src/openpgp/PgpEncryptedData.cs | |
parent | Add ValidateBufferArguments (diff) | |
download | BouncyCastle.NET-ed25519-98b3ce6512812cd1d91c60ca0e69d69c32838d8e.tar.xz |
Work on Stream classes
- consistent naming, ordering - CanRead/Seek/Write fixes - argument validation - some cases of blocking zero-byte Read calls
Diffstat (limited to 'crypto/src/openpgp/PgpEncryptedData.cs')
-rw-r--r-- | crypto/src/openpgp/PgpEncryptedData.cs | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/crypto/src/openpgp/PgpEncryptedData.cs b/crypto/src/openpgp/PgpEncryptedData.cs index 558e0b8a2..d3220fe86 100644 --- a/crypto/src/openpgp/PgpEncryptedData.cs +++ b/crypto/src/openpgp/PgpEncryptedData.cs @@ -50,41 +50,43 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp return bufEnd; } - public override int ReadByte() - { - if (bufStart < bufEnd) - return lookAhead[bufStart++]; + public override int Read(byte[] buffer, int offset, int count) + { + Streams.ValidateBufferArguments(buffer, offset, count); - if (FillBuffer() < 1) - return -1; + int avail = bufEnd - bufStart; - return lookAhead[bufStart++]; - } + int pos = offset; + while (count > avail) + { + Array.Copy(lookAhead, bufStart, buffer, pos, avail); - public override int Read(byte[] buf, int off, int len) - { - int avail = bufEnd - bufStart; + bufStart += avail; + pos += avail; + count -= avail; - int pos = off; - while (len > avail) - { - Array.Copy(lookAhead, bufStart, buf, pos, avail); + if ((avail = FillBuffer()) < 1) + return pos - offset; + } - bufStart += avail; - pos += avail; - len -= avail; + Array.Copy(lookAhead, bufStart, buffer, pos, count); + bufStart += count; - if ((avail = FillBuffer()) < 1) - return pos - off; - } + return pos + count - offset; + } - Array.Copy(lookAhead, bufStart, buf, pos, len); - bufStart += len; + public override int ReadByte() + { + if (bufStart < bufEnd) + return lookAhead[bufStart++]; - return pos + len - off; - } + if (FillBuffer() < 1) + return -1; + + return lookAhead[bufStart++]; + } - internal byte[] GetLookAhead() + internal byte[] GetLookAhead() { byte[] temp = new byte[LookAheadSize]; Array.Copy(lookAhead, bufStart, temp, 0, LookAheadSize); |