Merge efc05e419d6e80290ed374b67d6488b8f374e66e into 002ed911b1a39f303b70246ac0ebf455a91c6d0f

This commit is contained in:
Петушков А. 2026-07-06 22:09:13 +00:00 committed by GitHub
commit 2b348d314b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -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";
/** /**
@ -83,6 +84,11 @@ class SHA2 extends Operation {
*/ */
run(input, args) { run(input, args) {
const size = args[0]; const size = args[0];
if (!this.args[0].value.some(option => option.name === size)) {
throw new OperationError("Invalid SHA2 size");
}
const rounds = (size === "256" || size === "224") ? args[1] : args[2]; const rounds = (size === "256" || size === "224") ? args[1] : args[2];
return runHash("sha" + size, input, {rounds: rounds}); return runHash("sha" + size, input, {rounds: rounds});
} }

View File

@ -140,6 +140,17 @@ TestRegister.addTests([
} }
] ]
}, },
{
name: "SHA2: invalid size",
input: "hi",
expectedOutput: "Invalid SHA2 size",
recipeConfig: [
{
"op": "SHA2",
"args": ["", 64, 13]
}
]
},
{ {
name: "SHA3 224", name: "SHA3 224",
input: "Hello, World!", input: "Hello, World!",