summary refs log tree commit diff
path: root/crypto/src/bcpg/PublicKeyPacket.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-20 18:42:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-20 18:42:12 +0700
commit8ab0160708d540e42b086582bd1992f5269f7166 (patch)
tree528bf8667e4db801fe74f888ad51d08f7533ba27 /crypto/src/bcpg/PublicKeyPacket.cs
parentRefactoring: reduced allocations (diff)
downloadBouncyCastle.NET-ed25519-8ab0160708d540e42b086582bd1992f5269f7166.tar.xz
Fix missing Dispose(s) of BcpgOutputStream
Diffstat (limited to 'crypto/src/bcpg/PublicKeyPacket.cs')
-rw-r--r--crypto/src/bcpg/PublicKeyPacket.cs21
1 files changed, 10 insertions, 11 deletions
diff --git a/crypto/src/bcpg/PublicKeyPacket.cs b/crypto/src/bcpg/PublicKeyPacket.cs
index 89177ce84..639d5595c 100644
--- a/crypto/src/bcpg/PublicKeyPacket.cs
+++ b/crypto/src/bcpg/PublicKeyPacket.cs
@@ -98,20 +98,19 @@ namespace Org.BouncyCastle.Bcpg
         public virtual byte[] GetEncodedContents()
         {
             MemoryStream bOut = new MemoryStream();
-            BcpgOutputStream pOut = new BcpgOutputStream(bOut);
-
-            pOut.WriteByte((byte) version);
-            pOut.WriteInt((int) time);
-
-            if (version <= 3)
+            using (var pOut = new BcpgOutputStream(bOut))
             {
-                pOut.WriteShort((short) validDays);
-            }
-
-            pOut.WriteByte((byte) algorithm);
+                pOut.WriteByte((byte)version);
+                pOut.WriteInt((int)time);
 
-            pOut.WriteObject((BcpgObject)key);
+                if (version <= 3)
+                {
+                    pOut.WriteShort((short)validDays);
+                }
 
+                pOut.WriteByte((byte)algorithm);
+                pOut.WriteObject((BcpgObject)key);
+            }
             return bOut.ToArray();
         }