Merge a08f57cc1574515694c4c71513eb1cb0f90b4e7c into 002ed911b1a39f303b70246ac0ebf455a91c6d0f
This commit is contained in:
commit
6abe8088a6
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import {runHash} from "../lib/Hash.mjs";
|
||||
|
||||
/**
|
||||
@ -30,7 +31,7 @@ class Snefru extends Operation {
|
||||
type: "number",
|
||||
value: 128,
|
||||
min: 32,
|
||||
max: 480,
|
||||
max: 448,
|
||||
step: 32
|
||||
},
|
||||
{
|
||||
@ -47,8 +48,14 @@ class Snefru extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const size = args[0];
|
||||
|
||||
if (!Number.isInteger(size) || size < 32 || size > 448 || size % 32 !== 0) {
|
||||
throw new OperationError("Size must be a multiple of 32 between 32 and 448");
|
||||
}
|
||||
|
||||
return runHash("snefru", input, {
|
||||
length: args[0],
|
||||
length: size,
|
||||
rounds: args[1]
|
||||
});
|
||||
}
|
||||
|
||||
@ -404,6 +404,28 @@ TestRegister.addTests([
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Snefru rejects negative size",
|
||||
input: "hello",
|
||||
expectedOutput: "Size must be a multiple of 32 between 32 and 448",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": [-32, "8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Snefru rejects out-of-range size",
|
||||
input: "hello",
|
||||
expectedOutput: "Size must be a multiple of 32 between 32 and 448",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": [480, "8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM3 256 64",
|
||||
input: "Hello, World!",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user