Merge 1e564190fb75c2083dffaaef3576364f13b4d984 into 002ed911b1a39f303b70246ac0ebf455a91c6d0f
This commit is contained in:
commit
7f61c21827
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import {runHash} from "../lib/Hash.mjs";
|
import {runHash} from "../lib/Hash.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,8 +47,13 @@ class Whirlpool extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const variant = args[0].toLowerCase();
|
const variant = args[0].toLowerCase(),
|
||||||
return runHash(variant, input, {rounds: args[1]});
|
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});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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",
|
name: "Snefru 2 128",
|
||||||
input: "Hello, World!",
|
input: "Hello, World!",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user