From 387c367049a013b9f9c3b9478a765b40c115b7ce Mon Sep 17 00:00:00 2001 From: Allan Leary Date: Tue, 7 Jul 2026 14:29:03 +0100 Subject: [PATCH] Fix issues 2139, 2217 handling Auto delimiter in fromDecimal function used in HMAC recipe --- src/core/lib/Decimal.mjs | 15 ++++++++++----- tests/operations/tests/Hash.mjs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/core/lib/Decimal.mjs b/src/core/lib/Decimal.mjs index a140fd4e..9af54541 100644 --- a/src/core/lib/Decimal.mjs +++ b/src/core/lib/Decimal.mjs @@ -24,12 +24,17 @@ import Utils from "../Utils.mjs"; * fromDecimal("10:20:30", "Colon"); */ export function fromDecimal(data, delim="Auto") { - delim = Utils.charRep(delim); - const output = []; - let byteStr = data.split(delim); - if (byteStr[byteStr.length-1] === "") - byteStr = byteStr.slice(0, byteStr.length-1); + let byteStr; + if (delim === "Auto") { + byteStr = data.split(/[^\d-]+/).filter(v => v !== ""); + } else { + const delimStr = Utils.charRep(delim); + byteStr = data.split(delimStr); + if (byteStr[byteStr.length-1] === "") + byteStr = byteStr.slice(0, byteStr.length-1); + } + const output = []; for (let i = 0; i < byteStr.length; i++) { output[i] = parseInt(byteStr[i], 10); } diff --git a/tests/operations/tests/Hash.mjs b/tests/operations/tests/Hash.mjs index 1ffb749c..a805b94f 100644 --- a/tests/operations/tests/Hash.mjs +++ b/tests/operations/tests/Hash.mjs @@ -722,6 +722,39 @@ TestRegister.addTests([ } ] }, + { + name: "HMAC: Decimal key space-delimited matches Latin1 key (fromDecimal Auto delimiter regression)", + input: "Hello, World!", + expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957", + recipeConfig: [ + { + "op": "HMAC", + "args": [{"option": "Decimal", "string": "65 65"}, "SHA256"] + } + ] + }, + { + name: "HMAC: Latin1 key matches space-delimited Decimal key (fromDecimal Auto delimiter regression)", + input: "Hello, World!", + expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957", + recipeConfig: [ + { + "op": "HMAC", + "args": [{"option": "Latin1", "string": "AA"}, "SHA256"] + } + ] + }, + { + name: "HMAC: Decimal key comma-delimited matches Latin1 key (fromDecimal Auto delimiter regression)", + input: "Hello, World!", + expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957", + recipeConfig: [ + { + "op": "HMAC", + "args": [{"option": "Decimal", "string": "65,65"}, "SHA256"] + } + ] + }, { name: "MD5: Complex bytes", input: "10dc10e32010de10d010dc10d810d910d010e12e",