Fix SHA2 size validation
This commit is contained in:
parent
d735496641
commit
efc05e419d
@ -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});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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!",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user