summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-03-25 20:49:35 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-13 17:16:20 +0700
commit7e3395f7bdc819fd5542446f8fb45c277fd64676 (patch)
treebb4547ca12a062a1bcb43c586e7c3c4e56e00918 /crypto/src
parentRFC 9146: Add ReceivePending methods (diff)
downloadBouncyCastle.NET-ed25519-7e3395f7bdc819fd5542446f8fb45c277fd64676.tar.xz
RFC 9146: Update RecordStream for completeness
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/tls/RecordStream.cs16
1 files changed, 14 insertions, 2 deletions
diff --git a/crypto/src/tls/RecordStream.cs b/crypto/src/tls/RecordStream.cs
index ed1c8d871..5b5ceff34 100644
--- a/crypto/src/tls/RecordStream.cs
+++ b/crypto/src/tls/RecordStream.cs
@@ -4,6 +4,7 @@ using System.IO;
 using System.Runtime.ExceptionServices;
 
 using Org.BouncyCastle.Tls.Crypto;
+using Org.BouncyCastle.Tls.Crypto.Impl;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Tls
@@ -149,8 +150,19 @@ namespace Org.BouncyCastle.Tls
             // NOTE: For TLS 1.3, this only MIGHT be application data
             if (ContentType.application_data == recordType && m_handler.IsApplicationDataReady)
             {
-                applicationDataLimit = System.Math.Max(0, System.Math.Min(m_plaintextLimit,
-                    m_readCipher.GetPlaintextLimit(length)));
+                var cipher = m_readCipher;
+
+                int plaintextDecodeLimit;
+                if (cipher is AbstractTlsCipher abstractTlsCipher)
+                {
+                    plaintextDecodeLimit = abstractTlsCipher.GetPlaintextDecodeLimit(length);
+                }
+                else
+                {
+                    plaintextDecodeLimit = cipher.GetPlaintextLimit(length);
+                }
+
+                applicationDataLimit = System.Math.Max(0, System.Math.Min(m_plaintextLimit, plaintextDecodeLimit));
             }
 
             return new RecordPreview(recordSize, applicationDataLimit);