Merge efc05e419d6e80290ed374b67d6488b8f374e66e into 002ed911b1a39f303b70246ac0ebf455a91c6d0f
This commit is contained in:
commit
2b348d314b
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import {runHash} from "../lib/Hash.mjs";
|
||||
|
||||
/**
|
||||
@ -83,6 +84,11 @@ class SHA2 extends Operation {
|
||||
*/
|
||||
run(input, args) {
|
||||
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];
|
||||
return runHash("sha" + size, input, {rounds: rounds});
|
||||
}
|
||||
|
||||
@ -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",
|
||||
input: "Hello, World!",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user