Skip to content

Commit c85a8ad

Browse files
committed
Make sure the computed hash is used.
1 parent 53e397b commit c85a8ad

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

highcpu/src/main/java/com/github/chrishantha/sample/highcpu/HashingWorker.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class HashingWorker implements Runnable {
2424
private final String algorithm;
2525
private final long length;
2626

27+
private byte[] lastComputedHash;
28+
2729
public HashingWorker(long length, String algorithm) {
2830
this.length = length;
2931
this.algorithm = algorithm;
@@ -48,6 +50,11 @@ public void run() {
4850

4951
// Hash
5052
digest.update(data.getBytes());
53+
byte[] computedHash = digest.digest();
54+
if (lastComputedHash != null && computedHash.length != lastComputedHash.length) {
55+
throw new IllegalStateException("Is the hash computation correct??");
56+
}
57+
lastComputedHash = computedHash;
5158
}
5259
}
5360
}

0 commit comments

Comments
 (0)