summary refs log tree commit diff
path: root/crypto/src/util/io/pem/PemReader.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 01:13:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 01:13:27 +0700
commita8a17fd70fc8df3ca7402323ad5c4f36b25cb806 (patch)
tree9b276b62885505abbb899d17744b65b912072140 /crypto/src/util/io/pem/PemReader.cs
parentPrimes improvements (diff)
downloadBouncyCastle.NET-ed25519-a8a17fd70fc8df3ca7402323ad5c4f36b25cb806.tar.xz
Dispose cleanup
- IDisposable for PemReader, PemWriter, IStreamGenerator
Diffstat (limited to 'crypto/src/util/io/pem/PemReader.cs')
-rw-r--r--crypto/src/util/io/pem/PemReader.cs29
1 files changed, 21 insertions, 8 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; }
 		}