Fix BLAKE2 output encoding validation

This commit is contained in:
marko1olo 2026-06-06 01:58:37 +04:00
parent d735496641
commit 309e0932db
4 changed files with 20 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class BLAKE2b extends Operation {
case "Raw": case "Raw":
return Utils.arrayBufferToStr(blakejs.blake2b(input, key, outSize / 8).buffer); return Utils.arrayBufferToStr(blakejs.blake2b(input, key, outSize / 8).buffer);
default: default:
return new OperationError("Unsupported Output Type"); throw new OperationError("Unsupported Output Type");
} }
} }

View File

@ -71,7 +71,7 @@ class BLAKE2s extends Operation {
case "Raw": case "Raw":
return Utils.arrayBufferToStr(blakejs.blake2s(input, key, outSize / 8).buffer); return Utils.arrayBufferToStr(blakejs.blake2s(input, key, outSize / 8).buffer);
default: default:
return new OperationError("Unsupported Output Type"); throw new OperationError("Unsupported Output Type");
} }
} }

View File

@ -52,5 +52,14 @@ TestRegister.addTests([
{ "op": "BLAKE2b", { "op": "BLAKE2b",
"args": ["128", "Hex", {string: "pseudorandom key", option: "UTF8"}] } "args": ["128", "Hex", {string: "pseudorandom key", option: "UTF8"}] }
] ]
},
{
name: "BLAKE2b: missing output encoding",
input: "hello",
expectedOutput: "Unsupported Output Type",
recipeConfig: [
{ "op": "BLAKE2b",
"args": ["512", "", {string: "", option: "UTF8"}] }
]
} }
]); ]);

View File

@ -43,5 +43,14 @@ TestRegister.addTests([
{ "op": "BLAKE2s", { "op": "BLAKE2s",
"args": ["128", "Hex", {string: "", option: "UTF8"}] } "args": ["128", "Hex", {string: "", option: "UTF8"}] }
] ]
},
{
name: "BLAKE2s: missing output encoding",
input: "hello",
expectedOutput: "Unsupported Output Type",
recipeConfig: [
{ "op": "BLAKE2s",
"args": ["256", "", {string: "", option: "UTF8"}] }
]
} }
]); ]);