mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
strictness parameter in fromHex
This commit is contained in:
parent
542bbdc248
commit
7acd9a3bd2
1 changed files with 2 additions and 2 deletions
|
@ -100,7 +100,7 @@ export function toHexFast(data) {
|
||||||
* // returns [10,20,30]
|
* // returns [10,20,30]
|
||||||
* fromHex("0a:14:1e", "Colon");
|
* 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)
|
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
|
||||||
throw new OperationError("Byte length must be a positive integer");
|
throw new OperationError("Byte length must be a positive integer");
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ export function fromHex(data, delim="Auto", byteLen=2) {
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
for (let i = 0; i < data.length; i++) {
|
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");
|
throw new OperationError("Hex input must only contain hex digits");
|
||||||
for (let j = 0; j < data[i].length; j += byteLen) {
|
for (let j = 0; j < data[i].length; j += byteLen) {
|
||||||
output.push(parseInt(data[i].substr(j, byteLen), 16));
|
output.push(parseInt(data[i].substr(j, byteLen), 16));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue