From 309e0932dbc55ee00938f275a24aec194643430a Mon Sep 17 00:00:00 2001 From: marko1olo Date: Sat, 6 Jun 2026 01:58:37 +0400 Subject: [PATCH] Fix BLAKE2 output encoding validation --- src/core/operations/BLAKE2b.mjs | 2 +- src/core/operations/BLAKE2s.mjs | 2 +- tests/operations/tests/BLAKE2b.mjs | 9 +++++++++ tests/operations/tests/BLAKE2s.mjs | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/operations/BLAKE2b.mjs b/src/core/operations/BLAKE2b.mjs index 6218f7f0..7ae3b99c 100644 --- a/src/core/operations/BLAKE2b.mjs +++ b/src/core/operations/BLAKE2b.mjs @@ -70,7 +70,7 @@ class BLAKE2b extends Operation { case "Raw": return Utils.arrayBufferToStr(blakejs.blake2b(input, key, outSize / 8).buffer); default: - return new OperationError("Unsupported Output Type"); + throw new OperationError("Unsupported Output Type"); } } diff --git a/src/core/operations/BLAKE2s.mjs b/src/core/operations/BLAKE2s.mjs index 8f84e041..4f56939b 100644 --- a/src/core/operations/BLAKE2s.mjs +++ b/src/core/operations/BLAKE2s.mjs @@ -71,7 +71,7 @@ class BLAKE2s extends Operation { case "Raw": return Utils.arrayBufferToStr(blakejs.blake2s(input, key, outSize / 8).buffer); default: - return new OperationError("Unsupported Output Type"); + throw new OperationError("Unsupported Output Type"); } } diff --git a/tests/operations/tests/BLAKE2b.mjs b/tests/operations/tests/BLAKE2b.mjs index 088b1078..d32875eb 100644 --- a/tests/operations/tests/BLAKE2b.mjs +++ b/tests/operations/tests/BLAKE2b.mjs @@ -52,5 +52,14 @@ TestRegister.addTests([ { "op": "BLAKE2b", "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"}] } + ] } ]); diff --git a/tests/operations/tests/BLAKE2s.mjs b/tests/operations/tests/BLAKE2s.mjs index fe978d24..db4c705b 100755 --- a/tests/operations/tests/BLAKE2s.mjs +++ b/tests/operations/tests/BLAKE2s.mjs @@ -43,5 +43,14 @@ TestRegister.addTests([ { "op": "BLAKE2s", "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"}] } + ] } ]);