Remove unnecessary call to MessageDigest.reset
This commit is contained in:
parent
e5a10e9520
commit
d3cef85352
|
@ -41,23 +41,20 @@ public class MessageDigests {
|
|||
}
|
||||
|
||||
public static MessageDigest md5() {
|
||||
return cloneAndReset(MD5_DIGEST);
|
||||
return clone(MD5_DIGEST);
|
||||
}
|
||||
|
||||
|
||||
public static MessageDigest sha1() {
|
||||
return cloneAndReset(SHA_1_DIGEST);
|
||||
return clone(SHA_1_DIGEST);
|
||||
}
|
||||
|
||||
public static MessageDigest sha256() {
|
||||
return cloneAndReset(SHA_256_DIGEST);
|
||||
return clone(SHA_256_DIGEST);
|
||||
}
|
||||
|
||||
private static MessageDigest cloneAndReset(MessageDigest messageDigest) {
|
||||
private static MessageDigest clone(MessageDigest messageDigest) {
|
||||
try {
|
||||
MessageDigest clone = (MessageDigest) messageDigest.clone();
|
||||
clone.reset();
|
||||
return clone;
|
||||
return (MessageDigest) messageDigest.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new ElasticsearchException("Unexpected exception cloning MessageDigest instance", e);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class MessageDigestsTests extends ESTestCase {
|
|||
BigInteger expected = BigInteger.probablePrime(256, random());
|
||||
byte[] bytes = expected.toByteArray();
|
||||
String hex = MessageDigests.toHexString(bytes);
|
||||
String zeros = new String(new char[bytes.length * 2]).replace("\0", "0");
|
||||
String zeros = new String(new char[2 * bytes.length]).replace("\0", "0");
|
||||
String expectedAsString = expected.toString(16);
|
||||
String expectedHex = zeros.substring(expectedAsString.length()) + expectedAsString;
|
||||
assertEquals(expectedHex, hex);
|
||||
|
|
Loading…
Reference in New Issue