From b232d995a81fa027106024aa74a5abbcda9fa3a0 Mon Sep 17 00:00:00 2001 From: deniszykov Date: Thu, 9 May 2019 15:29:40 +0300 Subject: Update TlsProtocol.cs added `TlsProtocol.OfferInput()` overload which specify _offset_ and _length_ of input buffer like in java source https://www.bouncycastle.org/docs/tlsdocs1.5on/org/bouncycastle/tls/TlsProtocol.html --- crypto/src/crypto/tls/TlsProtocol.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crypto/src') diff --git a/crypto/src/crypto/tls/TlsProtocol.cs b/crypto/src/crypto/tls/TlsProtocol.cs index 394967c37..103f6af0f 100644 --- a/crypto/src/crypto/tls/TlsProtocol.cs +++ b/crypto/src/crypto/tls/TlsProtocol.cs @@ -747,13 +747,18 @@ namespace Org.BouncyCastle.Crypto.Tls * @throws IOException If an error occurs while decrypting or processing a record */ public virtual void OfferInput(byte[] input) + { + this.OfferInput(input, 0, input.Length); + } + + public virtual void OfferInput(byte[] input, int offset, int length) { if (mBlocking) throw new InvalidOperationException("Cannot use OfferInput() in blocking mode! Use Stream instead."); if (mClosed) throw new IOException("Connection is closed, cannot accept any more input"); - mInputBuffers.Write(input); + mInputBuffers.Write(input, offset, length); // loop while there are enough bytes to read the length of the next record while (mInputBuffers.Available >= RecordStream.TLS_HEADER_SIZE) -- cgit 1.5.1 From ba90e9a89d92981916e6c34307d4cc08f8063ea8 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 10 May 2019 17:14:03 +0700 Subject: Cleanup around OfferInput methods --- crypto/src/crypto/tls/TlsProtocol.cs | 25 +++++++++++++--------- .../crypto/tls/test/TlsProtocolNonBlockingTest.cs | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'crypto/src') diff --git a/crypto/src/crypto/tls/TlsProtocol.cs b/crypto/src/crypto/tls/TlsProtocol.cs index 103f6af0f..388eb629f 100644 --- a/crypto/src/crypto/tls/TlsProtocol.cs +++ b/crypto/src/crypto/tls/TlsProtocol.cs @@ -728,12 +728,20 @@ namespace Org.BouncyCastle.Crypto.Tls throw new TlsNoCloseNotifyException(); } + /** + * Equivalent to OfferInput(input, 0, input.length) + * @see TlsProtocol#OfferInput(byte[], int, int) + * @param input The input buffer to offer + * @throws IOException If an error occurs while decrypting or processing a record + */ + public virtual void OfferInput(byte[] input) + { + OfferInput(input, 0, input.Length); + } + /** * Offer input from an arbitrary source. Only allowed in non-blocking mode.
*
- * After this method returns, the input buffer is "owned" by this object. Other code - * must not attempt to do anything with it.
- *
* This method will decrypt and process all records that are fully available. * If only part of a record is available, the buffer will be retained until the * remainder of the record is offered.
@@ -744,21 +752,18 @@ namespace Org.BouncyCastle.Crypto.Tls * You should always check to see if there is any available output after calling * this method by calling {@link #getAvailableOutputBytes()}. * @param input The input buffer to offer + * @param inputOff The offset within the input buffer that input begins + * @param inputLen The number of bytes of input being offered * @throws IOException If an error occurs while decrypting or processing a record */ - public virtual void OfferInput(byte[] input) - { - this.OfferInput(input, 0, input.Length); - } - - public virtual void OfferInput(byte[] input, int offset, int length) + public virtual void OfferInput(byte[] input, int inputOff, int inputLen) { if (mBlocking) throw new InvalidOperationException("Cannot use OfferInput() in blocking mode! Use Stream instead."); if (mClosed) throw new IOException("Connection is closed, cannot accept any more input"); - mInputBuffers.Write(input, offset, length); + mInputBuffers.Write(input, inputOff, inputLen); // loop while there are enough bytes to read the length of the next record while (mInputBuffers.Available >= RecordStream.TLS_HEADER_SIZE) diff --git a/crypto/test/src/crypto/tls/test/TlsProtocolNonBlockingTest.cs b/crypto/test/src/crypto/tls/test/TlsProtocolNonBlockingTest.cs index 68f2341ee..219a65af7 100644 --- a/crypto/test/src/crypto/tls/test/TlsProtocolNonBlockingTest.cs +++ b/crypto/test/src/crypto/tls/test/TlsProtocolNonBlockingTest.cs @@ -79,9 +79,9 @@ namespace Org.BouncyCastle.Crypto.Tls.Tests if (fragment) { + byte[] buffer = new byte[1]; while (from.GetAvailableOutputBytes() > 0) { - byte[] buffer = new byte[1]; from.ReadOutput(buffer, 0, 1); to.OfferInput(buffer); } -- cgit 1.5.1