Merge 1e564190fb75c2083dffaaef3576364f13b4d984 into 002ed911b1a39f303b70246ac0ebf455a91c6d0f

This commit is contained in:
Петушков А. 2026-07-07 06:35:22 +01:00 committed by GitHub
commit 7f61c21827
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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!",