diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-05-19 16:38:12 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-05-19 16:38:12 +0700 |
commit | 75ef73619db51c97a242b0e9c165838854534694 (patch) | |
tree | 3ce026ed1960af4ff7aedad8b4c4f52bb38faa76 /crypto/src/tls/TlsProtocol.cs | |
parent | ByteQueue improvements (diff) | |
download | BouncyCastle.NET-ed25519-75ef73619db51c97a242b0e9c165838854534694.tar.xz |
Add previewing of pending output records
Diffstat (limited to 'crypto/src/tls/TlsProtocol.cs')
-rw-r--r-- | crypto/src/tls/TlsProtocol.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/src/tls/TlsProtocol.cs b/crypto/src/tls/TlsProtocol.cs index 57b452f60..c30c253e1 100644 --- a/crypto/src/tls/TlsProtocol.cs +++ b/crypto/src/tls/TlsProtocol.cs @@ -1074,6 +1074,28 @@ namespace Org.BouncyCastle.Tls return SafePreviewRecordHeader(recordHeader); } + public virtual int PreviewOutputRecord() + { + if (m_blocking) + throw new InvalidOperationException("Cannot use PreviewOutputRecord() in blocking mode!"); + + ByteQueue buffer = m_outputBuffer.Buffer; + int available = buffer.Available; + if (available < 1) + return 0; + + if (available >= RecordFormat.FragmentOffset) + { + int length = buffer.ReadUint16(RecordFormat.LengthOffset); + int recordSize = RecordFormat.FragmentOffset + length; + + if (available >= recordSize) + return recordSize; + } + + throw new InvalidOperationException("Can only use PreviewOutputRecord() for record-aligned output."); + } + /// <exception cref="IOException"/> public virtual RecordPreview PreviewOutputRecord(int applicationDataSize) { |