Skip to content

Commit

Permalink
Correctly reset MessageDigest before reusing it.
Browse files Browse the repository at this point in the history
Motivation:

I missed to reset the MessageDigest before reusing it. This bug was introduced by 79634e6.

Modifications:

Call reset() on the MessageDigest.

Result:

Correctly reset MessageDigest before re-using
  • Loading branch information
normanmaurer committed Jan 4, 2016
1 parent bc2559c commit 8dc164a
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected MessageDigest initialValue() throws Exception {
*/
static byte[] md5(byte[] data) {
// TODO(normanmaurer): Create md5 method that not need MessageDigest.
return MD5.get().digest(data);
return digest(MD5, data);
}

/**
Expand All @@ -74,7 +74,13 @@ static byte[] md5(byte[] data) {
*/
static byte[] sha1(byte[] data) {
// TODO(normanmaurer): Create sha1 method that not need MessageDigest.
return SHA1.get().digest(data);
return digest(SHA1, data);
}

private static byte[] digest(FastThreadLocal<MessageDigest> digestFastThreadLocal, byte[] data) {
MessageDigest digest = digestFastThreadLocal.get();
digest.reset();
return digest.digest(data);
}

/**
Expand Down

0 comments on commit 8dc164a

Please sign in to comment.