diff options
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/Platform.cs | 5 | ||||
-rw-r--r-- | crypto/src/util/bzip2/CBZip2InputStream.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/bzip2/CBZip2OutputStream.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/io/TeeInputStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/io/TeeOutputStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/io/pem/PemReader.cs | 29 | ||||
-rw-r--r-- | crypto/src/util/io/pem/PemWriter.cs | 32 | ||||
-rw-r--r-- | crypto/src/util/zlib/ZInputStream.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/zlib/ZOutputStream.cs | 2 |
9 files changed, 53 insertions, 29 deletions
diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs index 78ff6cee4..a78153b8c 100644 --- a/crypto/src/util/Platform.cs +++ b/crypto/src/util/Platform.cs @@ -26,11 +26,6 @@ namespace Org.BouncyCastle.Utilities } } - internal static void Dispose(IDisposable d) - { - d.Dispose(); - } - internal static int IndexOf(string source, char value) { return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal); diff --git a/crypto/src/util/bzip2/CBZip2InputStream.cs b/crypto/src/util/bzip2/CBZip2InputStream.cs index 7879f28af..08760f547 100644 --- a/crypto/src/util/bzip2/CBZip2InputStream.cs +++ b/crypto/src/util/bzip2/CBZip2InputStream.cs @@ -258,7 +258,7 @@ namespace Org.BouncyCastle.Utilities.Bzip2 { if (this.bsStream != null) { - Platform.Dispose(this.bsStream); + this.bsStream.Dispose(); this.bsStream = null; } } diff --git a/crypto/src/util/bzip2/CBZip2OutputStream.cs b/crypto/src/util/bzip2/CBZip2OutputStream.cs index b896f36c6..d1400c7c4 100644 --- a/crypto/src/util/bzip2/CBZip2OutputStream.cs +++ b/crypto/src/util/bzip2/CBZip2OutputStream.cs @@ -441,7 +441,7 @@ namespace Org.BouncyCastle.Utilities.Bzip2 { Finish(); closed = true; - Platform.Dispose(this.bsStream); + this.bsStream.Dispose(); } } base.Dispose(disposing); diff --git a/crypto/src/util/io/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs index 3d45bb4f1..7815fde76 100644 --- a/crypto/src/util/io/TeeInputStream.cs +++ b/crypto/src/util/io/TeeInputStream.cs @@ -22,8 +22,8 @@ namespace Org.BouncyCastle.Utilities.IO { if (disposing) { - Platform.Dispose(input); - Platform.Dispose(tee); + input.Dispose(); + tee.Dispose(); } base.Dispose(disposing); } diff --git a/crypto/src/util/io/TeeOutputStream.cs b/crypto/src/util/io/TeeOutputStream.cs index fc213ae55..1762d6f52 100644 --- a/crypto/src/util/io/TeeOutputStream.cs +++ b/crypto/src/util/io/TeeOutputStream.cs @@ -22,8 +22,8 @@ namespace Org.BouncyCastle.Utilities.IO { if (disposing) { - Platform.Dispose(output); - Platform.Dispose(tee); + output.Dispose(); + tee.Dispose(); } base.Dispose(disposing); } diff --git a/crypto/src/util/io/pem/PemReader.cs b/crypto/src/util/io/pem/PemReader.cs index cd19e95b8..77b457338 100644 --- a/crypto/src/util/io/pem/PemReader.cs +++ b/crypto/src/util/io/pem/PemReader.cs @@ -6,8 +6,8 @@ using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Utilities.IO.Pem { - public class PemReader + : IDisposable { private readonly TextReader reader; private readonly MemoryStream buffer; @@ -17,17 +17,30 @@ namespace Org.BouncyCastle.Utilities.IO.Pem public PemReader(TextReader reader) { - if (reader == null) - throw new ArgumentNullException("reader"); + this.reader = reader ?? throw new ArgumentNullException(nameof(reader)); + this.buffer = new MemoryStream(); + this.textBuffer = new StreamWriter(buffer); + } + #region IDisposable - buffer = new MemoryStream(); - textBuffer = new StreamWriter(buffer); + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } - this.reader = reader; - } + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + reader.Dispose(); + } + } + + #endregion - public TextReader Reader + public TextReader Reader { get { return reader; } } diff --git a/crypto/src/util/io/pem/PemWriter.cs b/crypto/src/util/io/pem/PemWriter.cs index fbb8b0f2d..ee92556c7 100644 --- a/crypto/src/util/io/pem/PemWriter.cs +++ b/crypto/src/util/io/pem/PemWriter.cs @@ -9,13 +9,14 @@ namespace Org.BouncyCastle.Utilities.IO.Pem * A generic PEM writer, based on RFC 1421 */ public class PemWriter + : IDisposable { private const int LineLength = 64; private readonly TextWriter writer; private readonly int nlLength; private char[] buf = new char[LineLength]; - + /** * Base constructor. * @@ -23,14 +24,29 @@ namespace Org.BouncyCastle.Utilities.IO.Pem */ public PemWriter(TextWriter writer) { - if (writer == null) - throw new ArgumentNullException("writer"); - - this.writer = writer; - this.nlLength = Environment.NewLine.Length; + this.writer = writer ?? throw new ArgumentNullException(nameof(writer)); + this.nlLength = Environment.NewLine.Length; } - public TextWriter Writer + #region IDisposable + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + writer.Dispose(); + } + } + + #endregion + + public TextWriter Writer { get { return writer; } } @@ -115,5 +131,5 @@ namespace Org.BouncyCastle.Utilities.IO.Pem { writer.WriteLine("-----END " + type + "-----"); } - } + } } diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs index 0433a0182..de1c27202 100644 --- a/crypto/src/util/zlib/ZInputStream.cs +++ b/crypto/src/util/zlib/ZInputStream.cs @@ -123,7 +123,7 @@ namespace Org.BouncyCastle.Utilities.Zlib if (!closed) { closed = true; - Platform.Dispose(input); + input.Dispose(); } } base.Dispose(disposing); diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs index 51a5050dd..ecf33cddf 100644 --- a/crypto/src/util/zlib/ZOutputStream.cs +++ b/crypto/src/util/zlib/ZOutputStream.cs @@ -158,7 +158,7 @@ namespace Org.BouncyCastle.Utilities.Zlib { this.closed = true; End(); - Platform.Dispose(output); + output.Dispose(); output = null; } } |