From 0e44e9c5ce378b1f3b31afec85fd6a9e562529c9 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Fri, 14 Feb 2025 23:10:36 -0500 Subject: [PATCH 01/10] Update Hex.mjs --- src/core/lib/Hex.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 78e1ad58..8e08f612 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -105,7 +105,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { throw new OperationError("Byte length must be a positive integer"); if (delim !== "None") { - const delimRegex = delim === "Auto" ? /[^a-f\d]|0x/gi : Utils.regexRep(delim); + const delimRegex = delim === "Auto" ? /\s|0x/gi : Utils.regexRep(delim); data = data.split(delimRegex); } else { data = [data]; @@ -113,6 +113,8 @@ export function fromHex(data, delim="Auto", byteLen=2) { const output = []; for (let i = 0; i < data.length; i++) { + if (/[^a-f\d]/.test(data[i])) + throw new OperationError("Hex input must only contain hex digits"); for (let j = 0; j < data[i].length; j += byteLen) { output.push(parseInt(data[i].substr(j, byteLen), 16)); } From d5d2660655c83ecb3a9a9ed27314b52b9919299e Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Fri, 14 Feb 2025 23:32:29 -0500 Subject: [PATCH 02/10] \s to \s+ --- src/core/lib/Hex.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 8e08f612..89f7e239 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -105,7 +105,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { throw new OperationError("Byte length must be a positive integer"); if (delim !== "None") { - const delimRegex = delim === "Auto" ? /\s|0x/gi : Utils.regexRep(delim); + const delimRegex = delim === "Auto" ? /\s+|0x/gi : Utils.regexRep(delim); data = data.split(delimRegex); } else { data = [data]; From 542bbdc248e239eb835a7d03803d9b29120e15a6 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Fri, 14 Feb 2025 23:44:52 -0500 Subject: [PATCH 03/10] allow whitespace in elements of data I think this was why it was failing a test --- src/core/lib/Hex.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 89f7e239..69b5a326 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -113,7 +113,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { const output = []; for (let i = 0; i < data.length; i++) { - if (/[^a-f\d]/.test(data[i])) + if (/[^a-f\d\s]/.test(data[i])) throw new OperationError("Hex input must only contain hex digits"); for (let j = 0; j < data[i].length; j += byteLen) { output.push(parseInt(data[i].substr(j, byteLen), 16)); From 7acd9a3bd215a98a7f89b8a3493be54191077574 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 14:47:42 -0500 Subject: [PATCH 04/10] strictness parameter in fromHex --- src/core/lib/Hex.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 69b5a326..63d8c7eb 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -100,7 +100,7 @@ export function toHexFast(data) { * // returns [10,20,30] * fromHex("0a:14:1e", "Colon"); */ -export function fromHex(data, delim="Auto", byteLen=2) { +export function fromHex(data, delim="Auto", byteLen=2, strict=False) { if (byteLen < 1 || Math.round(byteLen) !== byteLen) throw new OperationError("Byte length must be a positive integer"); @@ -113,7 +113,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { const output = []; for (let i = 0; i < data.length; i++) { - if (/[^a-f\d\s]/.test(data[i])) + if (/[^a-f\d\s]/.test(data[i]) && strict) throw new OperationError("Hex input must only contain hex digits"); for (let j = 0; j < data[i].length; j += byteLen) { output.push(parseInt(data[i].substr(j, byteLen), 16)); From d9fb3e28dd9226cd8fada435667c794f0eff7e7f Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 14:52:18 -0500 Subject: [PATCH 05/10] consistency with ../Base64.mjs removeNonAlphChars and strictMode params --- src/core/lib/Hex.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 63d8c7eb..1f4bd423 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -100,10 +100,13 @@ export function toHexFast(data) { * // returns [10,20,30] * fromHex("0a:14:1e", "Colon"); */ -export function fromHex(data, delim="Auto", byteLen=2, strict=False) { +export function fromHex(data, delim="Auto", byteLen=2, removeNonAlphChars=false, strictMode=false) { if (byteLen < 1 || Math.round(byteLen) !== byteLen) throw new OperationError("Byte length must be a positive integer"); + if (removeNonAlphChars) + data = data.replace(/[^\da-fA-F]/g, ''); + if (delim !== "None") { const delimRegex = delim === "Auto" ? /\s+|0x/gi : Utils.regexRep(delim); data = data.split(delimRegex); @@ -113,7 +116,7 @@ export function fromHex(data, delim="Auto", byteLen=2, strict=False) { const output = []; for (let i = 0; i < data.length; i++) { - if (/[^a-f\d\s]/.test(data[i]) && strict) + if (/[^a-f\d\s]/.test(data[i]) && strictMode) throw new OperationError("Hex input must only contain hex digits"); for (let j = 0; j < data[i].length; j += byteLen) { output.push(parseInt(data[i].substr(j, byteLen), 16)); From 58b0d06760d2693565c772328f0b0a924bb4d658 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 14:54:35 -0500 Subject: [PATCH 06/10] add boolean args removeNonAlphChars, strictMode --- src/core/operations/FromHex.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/operations/FromHex.mjs b/src/core/operations/FromHex.mjs index cd82d7df..d3c469d0 100644 --- a/src/core/operations/FromHex.mjs +++ b/src/core/operations/FromHex.mjs @@ -30,6 +30,16 @@ class FromHex extends Operation { name: "Delimiter", type: "option", value: FROM_HEX_DELIM_OPTIONS + }, + { + name: "Remove non-alphabet chars", + type: "boolean", + value: true + }, + { + name: "Strict mode", + type: "boolean", + value: false } ]; this.checks = [ @@ -92,8 +102,8 @@ class FromHex extends Operation { * @returns {byteArray} */ run(input, args) { - const delim = args[0] || "Auto"; - return fromHex(input, delim, 2); + const [delim, removeNonAlphChars, strictMode] = [args[0] || "Auto", args[1], args[2]]; + return fromHex(input, delim, 2, removeNonAlphChars, strictMode); } /** From 515a17d8f1e8f131e4b1ee35e3057927dc9d5286 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 15:00:08 -0500 Subject: [PATCH 07/10] style tweaks --- src/core/lib/Hex.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 1f4bd423..ce7ee3a6 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -105,8 +105,8 @@ export function fromHex(data, delim="Auto", byteLen=2, removeNonAlphChars=false, throw new OperationError("Byte length must be a positive integer"); if (removeNonAlphChars) - data = data.replace(/[^\da-fA-F]/g, ''); - + data = data.replace(/[^\da-fA-F]/g, ""); + if (delim !== "None") { const delimRegex = delim === "Auto" ? /\s+|0x/gi : Utils.regexRep(delim); data = data.split(delimRegex); From ec899efdc1157077ec57fd5880876730e2155e03 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 15:25:31 -0500 Subject: [PATCH 08/10] removing strictMode I thought it served a different purpose than it did in ./FromBase64.mjs --- src/core/operations/FromHex.mjs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/core/operations/FromHex.mjs b/src/core/operations/FromHex.mjs index d3c469d0..560abdac 100644 --- a/src/core/operations/FromHex.mjs +++ b/src/core/operations/FromHex.mjs @@ -35,11 +35,6 @@ class FromHex extends Operation { name: "Remove non-alphabet chars", type: "boolean", value: true - }, - { - name: "Strict mode", - type: "boolean", - value: false } ]; this.checks = [ @@ -103,7 +98,7 @@ class FromHex extends Operation { */ run(input, args) { const [delim, removeNonAlphChars, strictMode] = [args[0] || "Auto", args[1], args[2]]; - return fromHex(input, delim, 2, removeNonAlphChars, strictMode); + return fromHex(input, delim, 2, removeNonAlphChars); } /** From d0d1f743f0d7a1c73108626d0bfb93cdf7e05b68 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 15:29:38 -0500 Subject: [PATCH 09/10] removing strictMode I thought it served a different purpose than it did in ./Base64.mjs --- src/core/lib/Hex.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index ce7ee3a6..806b0dd2 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -100,7 +100,7 @@ export function toHexFast(data) { * // returns [10,20,30] * fromHex("0a:14:1e", "Colon"); */ -export function fromHex(data, delim="Auto", byteLen=2, removeNonAlphChars=false, strictMode=false) { +export function fromHex(data, delim="Auto", byteLen=2, removeNonAlphChars=false) { if (byteLen < 1 || Math.round(byteLen) !== byteLen) throw new OperationError("Byte length must be a positive integer"); @@ -116,7 +116,7 @@ export function fromHex(data, delim="Auto", byteLen=2, removeNonAlphChars=false, const output = []; for (let i = 0; i < data.length; i++) { - if (/[^a-f\d\s]/.test(data[i]) && strictMode) + if (/[^a-f\d\s]/.test(data[i])) throw new OperationError("Hex input must only contain hex digits"); for (let j = 0; j < data[i].length; j += byteLen) { output.push(parseInt(data[i].substr(j, byteLen), 16)); From 5e86407825f8d6b4d8b91dfdc1cbe5e032090ae9 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Mon, 17 Feb 2025 15:40:58 -0500 Subject: [PATCH 10/10] removing strictMode pt. 2 --- src/core/operations/FromHex.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/operations/FromHex.mjs b/src/core/operations/FromHex.mjs index 560abdac..9bc78403 100644 --- a/src/core/operations/FromHex.mjs +++ b/src/core/operations/FromHex.mjs @@ -97,7 +97,7 @@ class FromHex extends Operation { * @returns {byteArray} */ run(input, args) { - const [delim, removeNonAlphChars, strictMode] = [args[0] || "Auto", args[1], args[2]]; + const [delim, removeNonAlphChars] = [args[0] || "Auto", args[1]]; return fromHex(input, delim, 2, removeNonAlphChars); }