diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 01:13:27 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 01:13:27 +0700 |
commit | a8a17fd70fc8df3ca7402323ad5c4f36b25cb806 (patch) | |
tree | 9b276b62885505abbb899d17744b65b912072140 /crypto/src/util/io/pem/PemWriter.cs | |
parent | Primes improvements (diff) | |
download | BouncyCastle.NET-ed25519-a8a17fd70fc8df3ca7402323ad5c4f36b25cb806.tar.xz |
Dispose cleanup
- IDisposable for PemReader, PemWriter, IStreamGenerator
Diffstat (limited to 'crypto/src/util/io/pem/PemWriter.cs')
-rw-r--r-- | crypto/src/util/io/pem/PemWriter.cs | 32 |
1 files changed, 24 insertions, 8 deletions
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 + "-----"); } - } + } } |