summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpEncryptedDataGenerator.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/openpgp/PgpEncryptedDataGenerator.cs
parentPrimes improvements (diff)
downloadBouncyCastle.NET-ed25519-a8a17fd70fc8df3ca7402323ad5c4f36b25cb806.tar.xz
Dispose cleanup
- IDisposable for PemReader, PemWriter, IStreamGenerator
Diffstat (limited to 'crypto/src/openpgp/PgpEncryptedDataGenerator.cs')
-rw-r--r--crypto/src/openpgp/PgpEncryptedDataGenerator.cs83
1 files changed, 43 insertions, 40 deletions
diff --git a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
index 69e0d5dbc..b9473a32c 100644
--- a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
@@ -2,7 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
-using Org.BouncyCastle.Asn1;
+
 using Org.BouncyCastle.Asn1.Cryptlib;
 using Org.BouncyCastle.Asn1.EdEC;
 using Org.BouncyCastle.Crypto;
@@ -600,52 +600,55 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             return Open(outStr, 0, buffer);
         }
 
-		/// <summary>
-		/// <p>
-		/// Close off the encrypted object - this is equivalent to calling Close() on the stream
-		/// returned by the Open() method.
-		/// </p>
-		/// <p>
-		/// <b>Note</b>: This does not close the underlying output stream, only the stream on top of
-		/// it created by the Open() method.
-		/// </p>
-		/// </summary>
-        public void Close()
+        #region IDisposable
+
+        public void Dispose()
         {
-            if (cOut != null)
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposing)
             {
-				// TODO Should this all be under the try/catch block?
-                if (digestOut != null)
+                if (cOut != null)
                 {
-                    //
-                    // hand code a mod detection packet
-                    //
-                    BcpgOutputStream bOut = new BcpgOutputStream(
-						digestOut, PacketTag.ModificationDetectionCode, 20);
-
-                    bOut.Flush();
-                    digestOut.Flush();
+				    // TODO Should this all be under the try/catch block?
+                    if (digestOut != null)
+                    {
+                        //
+                        // hand code a mod detection packet
+                        //
+                        BcpgOutputStream bOut = new BcpgOutputStream(
+						    digestOut, PacketTag.ModificationDetectionCode, 20);
+
+                        bOut.Flush();
+                        digestOut.Flush();
+
+					    // TODO
+					    byte[] dig = DigestUtilities.DoFinal(digestOut.WriteDigest);
+					    cOut.Write(dig, 0, dig.Length);
+                    }
 
-					// TODO
-					byte[] dig = DigestUtilities.DoFinal(digestOut.WriteDigest);
-					cOut.Write(dig, 0, dig.Length);
-                }
+				    cOut.Flush();
 
-				cOut.Flush();
+				    try
+                    {
+					    pOut.Write(c.DoFinal());
+                        pOut.Finish();
+                    }
+                    catch (Exception e)
+                    {
+                        throw new IOException(e.Message, e);
+                    }
 
-				try
-                {
-					pOut.Write(c.DoFinal());
-                    pOut.Finish();
-                }
-                catch (Exception e)
-                {
-                    throw new IOException(e.Message, e);
+				    cOut = null;
+				    pOut = null;
                 }
-
-				cOut = null;
-				pOut = null;
             }
-		}
+        }
+
+        #endregion
 	}
 }