summary refs log tree commit diff
path: root/crypto/src/bcpg/SignaturePacket.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/bcpg/SignaturePacket.cs')
-rw-r--r--crypto/src/bcpg/SignaturePacket.cs71
1 files changed, 30 insertions, 41 deletions
diff --git a/crypto/src/bcpg/SignaturePacket.cs b/crypto/src/bcpg/SignaturePacket.cs
index ca11ba9f4..3256ee35e 100644
--- a/crypto/src/bcpg/SignaturePacket.cs
+++ b/crypto/src/bcpg/SignaturePacket.cs
@@ -384,55 +384,44 @@ namespace Org.BouncyCastle.Bcpg
             get { return creationTime; }
         }
 
-		public override void Encode(
-            BcpgOutputStream bcpgOut)
+		public override void Encode(BcpgOutputStream bcpgOut)
         {
             MemoryStream bOut = new MemoryStream();
-            BcpgOutputStream pOut = new BcpgOutputStream(bOut);
-
-			pOut.WriteByte((byte) version);
-
-			if (version == 3 || version == 2)
+            using (var pOut = new BcpgOutputStream(bOut))
             {
-				pOut.Write(
-					5, // the length of the next block
-					(byte) signatureType);
-
-				pOut.WriteInt((int)(creationTime / 1000L));
+                pOut.WriteByte((byte)version);
 
-				pOut.WriteLong(keyId);
-
-				pOut.Write(
-					(byte) keyAlgorithm,
-					(byte) hashAlgorithm);
-            }
-            else if (version == 4)
-            {
-                pOut.Write(
-					(byte) signatureType,
-					(byte) keyAlgorithm,
-					(byte) hashAlgorithm);
+                if (version == 3 || version == 2)
+                {
+                    byte nextBlockLength = 5;
+                    pOut.Write(nextBlockLength, (byte)signatureType);
+                    pOut.WriteInt((int)(creationTime / 1000L));
+                    pOut.WriteLong(keyId);
+                    pOut.Write((byte)keyAlgorithm, (byte)hashAlgorithm);
+                }
+                else if (version == 4)
+                {
+                    pOut.Write((byte)signatureType, (byte)keyAlgorithm, (byte)hashAlgorithm);
+                    EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));
+                    EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
+                }
+                else
+                {
+                    throw new IOException("unknown version: " + version);
+                }
 
-				EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));
+                pOut.Write(fingerprint);
 
-				EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
-            }
-            else
-            {
-                throw new IOException("unknown version: " + version);
+                if (signature != null)
+                {
+                    pOut.WriteObjects(signature);
+                }
+                else
+                {
+                    pOut.Write(signatureEncoding);
+                }
             }
 
-			pOut.Write(fingerprint);
-
-			if (signature != null)
-			{
-				pOut.WriteObjects(signature);
-			}
-			else
-			{
-				pOut.Write(signatureEncoding);
-			}
-
 			bcpgOut.WritePacket(PacketTag.Signature, bOut.ToArray(), true);
         }