Fix IllegalArgumentException message for unknown Argon2 types

Array index 0 points to an empty string. Use index 1 instead.

Signed-off-by: Roman Trapickin <8594293+rntrp@users.noreply.github.com>
This commit is contained in:
Roman Trapickin 2025-04-21 10:44:17 +02:00 committed by Josh Cummings
parent 7bf776ec38
commit d2d1275b39
2 changed files with 3 additions and 2 deletions

View File

@ -111,7 +111,7 @@ final class Argon2EncodingUtils {
case "argon2d" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d);
case "argon2i" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i);
case "argon2id" -> new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
default -> throw new IllegalArgumentException("Invalid algorithm type: " + parts[0]);
default -> throw new IllegalArgumentException("Invalid algorithm type: " + parts[1]);
};
if (parts[currentPart].startsWith("v=")) {
paramsBuilder.withVersion(Integer.parseInt(parts[currentPart].substring(2)));

View File

@ -95,7 +95,8 @@ public class Argon2EncodingUtilsTests {
@Test
public void decodeWhenNonexistingAlgorithmThenThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
.decode("$argon2x$v=19$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
.decode("$argon2x$v=19$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"))
.withMessageContaining("argon2x");
}
@Test