Skip to content

Commit

Permalink
Make RecentMessages thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
luai-michlawi committed Aug 27, 2019
1 parent db044dc commit 0e72be0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/RecentMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ namespace Makaretu.Dns
/// </remarks>
public class RecentMessages
{
// MD5 is okay because the hash is not used for security.
HashAlgorithm hasher = MD5.Create();

/// <summary>
/// Recent messages.
/// </summary>
Expand Down Expand Up @@ -84,7 +81,11 @@ public int Prune()
/// </returns>
public string GetId(byte[] message)
{
return Convert.ToBase64String(hasher.ComputeHash(message));
// MD5 is okay because the hash is not used for security.
using (HashAlgorithm hasher = MD5.Create())
{
return Convert.ToBase64String(hasher.ComputeHash(message));
}
}
}
}

0 comments on commit 0e72be0

Please sign in to comment.