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!",