Merge 229fc6117919f2a0bc39d3a732f11f51fbc6b14e into 002ed911b1a39f303b70246ac0ebf455a91c6d0f

This commit is contained in:
Петушков А. 2026-07-07 06:35:21 +01:00 committed by GitHub
commit 3977073c77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -6,6 +6,7 @@
import Operation from "../Operation.mjs";
import {runHash} from "../lib/Hash.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* MD2 operation
@ -40,7 +41,12 @@ class MD2 extends Operation {
* @returns {string}
*/
run(input, args) {
return runHash("md2", input, {rounds: args[0]});
const rounds = args[0] ?? 18;
if (!Number.isInteger(rounds) || rounds < 0)
throw new OperationError("Rounds must be a non-negative integer");
return runHash("md2", input, {rounds});
}
}

View File

@ -19,6 +19,28 @@ TestRegister.addTests([
}
]
},
{
name: "MD2 rejects negative rounds",
input: "Hello, World!",
expectedOutput: "Rounds must be a non-negative integer",
recipeConfig: [
{
"op": "MD2",
"args": [-1]
}
]
},
{
name: "MD2 rejects fractional rounds",
input: "Hello, World!",
expectedOutput: "Rounds must be a non-negative integer",
recipeConfig: [
{
"op": "MD2",
"args": [1.2]
}
]
},
{
name: "MD4",
input: "Hello, World!",