Allow Digester iterations to update

Fixes gh-4676
This commit is contained in:
Rob Winch 2017-10-22 09:54:06 -05:00
parent c5d4041ca8
commit b66ea9ab94
1 changed files with 9 additions and 2 deletions

View File

@ -31,7 +31,7 @@ final class Digester {
private final String algorithm;
private final int iterations;
private int iterations;
/**
* Create a new Digester.
@ -42,7 +42,7 @@ final class Digester {
// eagerly validate the algorithm
createDigest(algorithm);
this.algorithm = algorithm;
this.iterations = iterations;
setIterations(iterations);
}
public byte[] digest(byte[] value) {
@ -53,6 +53,13 @@ final class Digester {
return value;
}
final void setIterations(int iterations) {
if(iterations <= 0) {
throw new IllegalArgumentException("Iterations value must be greater than zero");
}
this.iterations = iterations;
}
private static MessageDigest createDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);