From 3d9ae54cc52ef86aceec6853203f86cd63dfe923 Mon Sep 17 00:00:00 2001 From: marko1olo Date: Sat, 6 Jun 2026 03:25:53 +0400 Subject: [PATCH] Fix Whirlpool variant validation --- src/core/operations/Whirlpool.mjs | 10 ++++++++-- tests/operations/tests/Hash.mjs | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/operations/Whirlpool.mjs b/src/core/operations/Whirlpool.mjs index c2364912..f079da45 100644 --- a/src/core/operations/Whirlpool.mjs +++ b/src/core/operations/Whirlpool.mjs @@ -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]}); } } diff --git a/tests/operations/tests/Hash.mjs b/tests/operations/tests/Hash.mjs index ba502934..aeb220a2 100644 --- a/tests/operations/tests/Hash.mjs +++ b/tests/operations/tests/Hash.mjs @@ -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!",