Skip to content

Commit 1c5f484

Browse files
committed
Add support for SHAKE128-256 and SHAKE256-512 to DigestUtils and
`MessageDigestAlgorithms` on Java 25 and up
1 parent 6ca5a08 commit 1c5f484

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/test/java/org/apache/commons/codec/digest/Binary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static byte[] toByteArray(final String binary) {
3434
throw new IllegalArgumentException(String.format("Binary string length must be a multiple of %,d.", Byte.SIZE));
3535
}
3636
final byte[] byteArray = new byte[inLen / Byte.SIZE];
37-
for (int i = 0; i < byteArray.length; i += Byte.SIZE) {
38-
byteArray[i] = (byte) Integer.parseInt(binary.substring(i, i + Byte.SIZE), RADIX);
37+
for (int i = 0, j = 0; i < byteArray.length; i++, j += Byte.SIZE) {
38+
byteArray[i] = (byte) Integer.parseInt(binary.substring(j, j + Byte.SIZE), RADIX);
3939
}
4040
return byteArray;
4141
}

src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ void testShaHex() throws IOException {
853853
void testShake128_256(final String binaryInputText, final int inputBitSize, final String hexOutputText) throws Exception {
854854
final String cleanBinary = clean(binaryInputText);
855855
final String cleanBinaryInput = StringUtils.reverse(cleanBinary);
856-
final byte[] bytesInput = inputBitSize > 0 ? Binary.toByteArray(cleanBinaryInput) : ArrayUtils.EMPTY_BYTE_ARRAY;
856+
final byte[] bytesInput = Binary.toByteArray(cleanBinaryInput);
857857
// sanity check on the test fixture
858858
assertEquals(inputBitSize, bytesInput.length * Byte.SIZE);
859859
final String resultString = clean(hexOutputText).substring(0, SHAKE128_256_BYTE_LEN * 2);
@@ -892,7 +892,7 @@ void testShake128_256_String() throws Exception {
892892
void testShake256_512(final String binaryInputText, final int inputBitSize, final String hexOutputText) throws Exception {
893893
final String cleanBinary = clean(binaryInputText);
894894
final String cleanBinaryInput = StringUtils.reverse(cleanBinary);
895-
final byte[] bytesInput = inputBitSize > 0 ? Binary.toByteArray(cleanBinaryInput) : ArrayUtils.EMPTY_BYTE_ARRAY;
895+
final byte[] bytesInput = Binary.toByteArray(cleanBinaryInput);
896896
// sanity check on the test fixture
897897
assertEquals(inputBitSize, bytesInput.length * Byte.SIZE);
898898
final String resultString = clean(hexOutputText).substring(0, SHAKE128_512_BYTE_LEN * 2);

0 commit comments

Comments
 (0)