diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-03-05 14:45:49 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-03-05 14:45:49 +0700 |
commit | 6b59dbbece3b1509b83b8479259a3c6059e9a60b (patch) | |
tree | 3dca66ea9a1e8aa02ac6099cde5844155783bd7b /crypto/src/tls | |
parent | Refactor Asn1Set classes (diff) | |
download | BouncyCastle.NET-ed25519-6b59dbbece3b1509b83b8479259a3c6059e9a60b.tar.xz |
Support 'leaveOpen' in Asn1 streams
Diffstat (limited to 'crypto/src/tls')
-rw-r--r-- | crypto/src/tls/TlsUtilities.cs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/src/tls/TlsUtilities.cs b/crypto/src/tls/TlsUtilities.cs index 7a601bebf..d187aeed2 100644 --- a/crypto/src/tls/TlsUtilities.cs +++ b/crypto/src/tls/TlsUtilities.cs @@ -966,14 +966,15 @@ namespace Org.BouncyCastle.Tls public static Asn1Object ReadAsn1Object(byte[] encoding) { - Asn1InputStream asn1 = new Asn1InputStream(encoding); - Asn1Object result = asn1.ReadObject(); - if (null == result) - throw new TlsFatalAlert(AlertDescription.decode_error); - if (null != asn1.ReadObject()) - throw new TlsFatalAlert(AlertDescription.decode_error); - - return result; + using (var asn1In = new Asn1InputStream(encoding)) + { + Asn1Object result = asn1In.ReadObject(); + if (null == result) + throw new TlsFatalAlert(AlertDescription.decode_error); + if (asn1In.Length != asn1In.Position) + throw new TlsFatalAlert(AlertDescription.decode_error); + return result; + } } /// <exception cref="IOException"/> |