Skip to content

Commit

Permalink
Dispose MemoryStreams
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon committed Aug 23, 2023
1 parent a5a2837 commit 49e4c21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Test/Extensions/CertInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static byte[] CreateCertInfo(
ReadOnlySpan<byte> tPM2BName,
ReadOnlySpan<byte> attestedQualifiedNameBuffer)
{
var stream = new MemoryStream();
using var stream = new MemoryStream();

stream.Write(magic);
stream.Write(type);
Expand Down
46 changes: 23 additions & 23 deletions Test/Extensions/PubAreaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ internal static byte[] CreatePubArea(
ReadOnlySpan<byte> kdf,
ReadOnlySpan<byte> unique = default)
{
var raw = new MemoryStream();
using var stream = new MemoryStream();

if (type is TpmAlg.TPM_ALG_ECC)
{
raw.Write(type.ToUInt16BigEndianBytes());
raw.Write(alg);
raw.Write(attributes);
raw.Write(GetUInt16BigEndianBytes(policy.Length));
raw.Write(policy);
raw.Write(symmetric);
raw.Write(scheme);
raw.Write(curveID);
raw.Write(kdf);
raw.Write(unique);
stream.Write(type.ToUInt16BigEndianBytes());
stream.Write(alg);
stream.Write(attributes);
stream.Write(GetUInt16BigEndianBytes(policy.Length));
stream.Write(policy);
stream.Write(symmetric);
stream.Write(scheme);
stream.Write(curveID);
stream.Write(kdf);
stream.Write(unique);
}
else
{
raw.Write(type.ToUInt16BigEndianBytes());
raw.Write(alg);
raw.Write(attributes);
raw.Write(GetUInt16BigEndianBytes(policy.Length));
raw.Write(policy);
raw.Write(symmetric);
raw.Write(scheme);
raw.Write(keyBits);
raw.Write(BitConverter.GetBytes(exponent[0] + (exponent[1] << 8) + (exponent[2] << 16)));
raw.Write(GetUInt16BigEndianBytes(unique.Length));
raw.Write(unique);
stream.Write(type.ToUInt16BigEndianBytes());
stream.Write(alg);
stream.Write(attributes);
stream.Write(GetUInt16BigEndianBytes(policy.Length));
stream.Write(policy);
stream.Write(symmetric);
stream.Write(scheme);
stream.Write(keyBits);
stream.Write(BitConverter.GetBytes(exponent[0] + (exponent[1] << 8) + (exponent[2] << 16)));
stream.Write(GetUInt16BigEndianBytes(unique.Length));
stream.Write(unique);
}

return raw.ToArray();
return stream.ToArray();
}

private static byte[] GetUInt16BigEndianBytes(int value)
Expand Down

0 comments on commit 49e4c21

Please sign in to comment.