parent
c5d4041ca8
commit
b66ea9ab94
|
@ -31,7 +31,7 @@ final class Digester {
|
||||||
|
|
||||||
private final String algorithm;
|
private final String algorithm;
|
||||||
|
|
||||||
private final int iterations;
|
private int iterations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Digester.
|
* Create a new Digester.
|
||||||
|
@ -42,7 +42,7 @@ final class Digester {
|
||||||
// eagerly validate the algorithm
|
// eagerly validate the algorithm
|
||||||
createDigest(algorithm);
|
createDigest(algorithm);
|
||||||
this.algorithm = algorithm;
|
this.algorithm = algorithm;
|
||||||
this.iterations = iterations;
|
setIterations(iterations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] digest(byte[] value) {
|
public byte[] digest(byte[] value) {
|
||||||
|
@ -53,6 +53,13 @@ final class Digester {
|
||||||
return value;
|
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) {
|
private static MessageDigest createDigest(String algorithm) {
|
||||||
try {
|
try {
|
||||||
return MessageDigest.getInstance(algorithm);
|
return MessageDigest.getInstance(algorithm);
|
||||||
|
|
Loading…
Reference in New Issue