Fix BLAKE3 size validation

This commit is contained in:
marko1olo 2026-06-06 01:44:14 +04:00
parent d735496641
commit 2672b1dfad
2 changed files with 23 additions and 0 deletions

View File

@ -47,6 +47,11 @@ class BLAKE3 extends Operation {
run(input, args) {
const key = args[1];
const size = args[0];
if (!Number.isInteger(size) || size < 0) {
throw new OperationError("Size must be a non-negative integer");
}
const opts = { dkLen: size };
const inputBytes = new Uint8Array(Utils.strToArrayBuffer(input));
if (key !== "") {

View File

@ -34,6 +34,24 @@ TestRegister.addTests([
"args": [32, ""] }
]
},
{
name: "BLAKE3: negative size",
input: "hello",
expectedOutput: "Size must be a non-negative integer",
recipeConfig: [
{ "op": "BLAKE3",
"args": [-6, ""] }
]
},
{
name: "BLAKE3: fractional size",
input: "hello",
expectedOutput: "Size must be a non-negative integer",
recipeConfig: [
{ "op": "BLAKE3",
"args": [1.2, ""] }
]
},
{
name: "BLAKE3: Key Test",
input: "Hello world",