summary refs log tree commit diff
path: root/crypto/src/util/io/pem/PemWriter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util/io/pem/PemWriter.cs')
-rw-r--r--crypto/src/util/io/pem/PemWriter.cs32
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 + "-----");
 		}
-	}
+    }
 }