From da13ced93565971e2551ab874b6a1804b9e2322a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 9 Nov 2022 16:08:53 +0700 Subject: Various Close/Dispose cleanup --- crypto/test/src/openpgp/test/PGPPBETest.cs | 8 +++++++- crypto/test/src/openpgp/test/PGPRSATest.cs | 6 ++++++ crypto/test/src/tls/test/NetworkStream.cs | 13 ++++++++----- crypto/test/src/tls/test/PipedStream.cs | 24 +++++++++++++++--------- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/crypto/test/src/openpgp/test/PGPPBETest.cs b/crypto/test/src/openpgp/test/PGPPBETest.cs index 85d6b7bff..8bab78fd9 100644 --- a/crypto/test/src/openpgp/test/PGPPBETest.cs +++ b/crypto/test/src/openpgp/test/PGPPBETest.cs @@ -365,7 +365,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests { throw new Exception("Close() called on underlying stream"); } - } + + protected override void Dispose(bool disposing) + { + if (disposing) + throw new Exception("Dispose() called on underlying stream"); + } + } public override string Name { diff --git a/crypto/test/src/openpgp/test/PGPRSATest.cs b/crypto/test/src/openpgp/test/PGPRSATest.cs index d8b350b2d..6de95fbeb 100644 --- a/crypto/test/src/openpgp/test/PGPRSATest.cs +++ b/crypto/test/src/openpgp/test/PGPRSATest.cs @@ -1208,6 +1208,12 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests { throw new Exception("Close() called on underlying stream"); } + + protected override void Dispose(bool disposing) + { + if (disposing) + throw new Exception("Dispose() called on underlying stream"); + } } public override string Name diff --git a/crypto/test/src/tls/test/NetworkStream.cs b/crypto/test/src/tls/test/NetworkStream.cs index c5f1dfd59..ed1b21014 100644 --- a/crypto/test/src/tls/test/NetworkStream.cs +++ b/crypto/test/src/tls/test/NetworkStream.cs @@ -34,11 +34,6 @@ namespace Org.BouncyCastle.Tls.Tests get { return m_inner.CanWrite; } } - public override void Close() - { - lock (this) m_closed = true; - } - public override void Flush() { m_inner.Flush(); @@ -89,6 +84,14 @@ namespace Org.BouncyCastle.Tls.Tests m_inner.WriteByte(value); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + lock (this) m_closed = true; + } + } + private void CheckNotClosed() { lock (this) diff --git a/crypto/test/src/tls/test/PipedStream.cs b/crypto/test/src/tls/test/PipedStream.cs index dfca35b81..95c3de465 100644 --- a/crypto/test/src/tls/test/PipedStream.cs +++ b/crypto/test/src/tls/test/PipedStream.cs @@ -41,15 +41,6 @@ namespace Org.BouncyCastle.Tls.Tests get { return true; } } - public override void Close() - { - lock (this) - { - m_closed = true; - Monitor.PulseAll(this); - } - } - public override void Flush() { } @@ -117,6 +108,21 @@ namespace Org.BouncyCastle.Tls.Tests } } + protected override void Dispose(bool disposing) + { + if (disposing) + { + lock (this) + { + if (!m_closed) + { + m_closed = true; + Monitor.PulseAll(this); + } + } + } + } + private void CheckOpen() { if (m_closed) -- cgit 1.4.1