Fix Whirlpool variant validation

This commit is contained in:
marko1olo 2026-06-06 03:25:53 +04:00
parent d735496641
commit 3d9ae54cc5
2 changed files with 19 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];
if (!this.args[0].value.includes(variant)) {
throw new OperationError("Invalid Whirlpool variant");
}
return runHash(variant.toLowerCase(), input, {rounds: args[1]});
}
}

View File

@ -338,6 +338,17 @@ TestRegister.addTests([
}
]
},
{
name: "Whirlpool: invalid variant",
input: "a",
expectedOutput: "Invalid Whirlpool variant",
recipeConfig: [
{
"op": "Whirlpool",
"args": ["", 10]
}
]
},
{
name: "Snefru 2 128",
input: "Hello, World!",