diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 21:37:59 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 21:37:59 +0700 |
commit | 98c8cbf49384796d55cd05a766e2429d8a4262d2 (patch) | |
tree | d7e195fc5835e03398ee5a670829470d7633623d /crypto/src/bcpg/SignaturePacket.cs | |
parent | Refactoring around Stream signers (diff) | |
download | BouncyCastle.NET-ed25519-98c8cbf49384796d55cd05a766e2429d8a4262d2.tar.xz |
Cleanup Stream disposing in Bcpg
Diffstat (limited to 'crypto/src/bcpg/SignaturePacket.cs')
-rw-r--r-- | crypto/src/bcpg/SignaturePacket.cs | 71 |
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); } |