diff options
Diffstat (limited to 'crypto/src/util/io/pem')
-rw-r--r-- | crypto/src/util/io/pem/PemReader.cs | 29 | ||||
-rw-r--r-- | crypto/src/util/io/pem/PemWriter.cs | 32 |
2 files changed, 45 insertions, 16 deletions
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 + "-----"); } - } + } } |