Fix Whirlpool rounds validation

This commit is contained in:
marko1olo 2026-06-06 05:30:49 +04:00
parent d735496641
commit 1e564190fb
2 changed files with 30 additions and 2 deletions

View File

@ -5,6 +5,7 @@
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {runHash} from "../lib/Hash.mjs";
/**
@ -46,8 +47,13 @@ class Whirlpool extends Operation {
* @returns {string}
*/
run(input, args) {
const variant = args[0].toLowerCase();
return runHash(variant, input, {rounds: args[1]});
const variant = args[0].toLowerCase(),
rounds = args[1] ?? 10;
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 10)
throw new OperationError("Rounds must be an integer between 1 and 10");
return runHash(variant, input, {rounds});
}
}

View File

@ -338,6 +338,28 @@ TestRegister.addTests([
}
]
},
{
name: "Whirlpool rejects negative rounds",
input: "Hello, World!",
expectedOutput: "Rounds must be an integer between 1 and 10",
recipeConfig: [
{
"op": "Whirlpool",
"args": ["Whirlpool", -1]
}
]
},
{
name: "Whirlpool rejects fractional rounds",
input: "Hello, World!",
expectedOutput: "Rounds must be an integer between 1 and 10",
recipeConfig: [
{
"op": "Whirlpool",
"args": ["Whirlpool", 1.2]
}
]
},
{
name: "Snefru 2 128",
input: "Hello, World!",