2
0
mirror of https://github.com/gchq/CyberChef synced 2025-12-05 23:53:27 +00:00

Added numeric validation for arguments in Binary and Hex operattions. Fixes #1178

This commit is contained in:
n1474335
2021-02-22 19:13:38 +00:00
parent 95884d77cf
commit 1e0e7f16a7
5 changed files with 18 additions and 4 deletions

View File

@@ -7,6 +7,7 @@
*/
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
@@ -58,6 +59,9 @@ export function toBinary(data, delim="Space", padding=8) {
* fromBinary("00010000:00100000:00110000", "Colon");
*/
export function fromBinary(data, delim="Space", byteLen=8) {
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
throw new OperationError("Byte length must be a positive integer");
const delimRegex = Utils.regexRep(delim);
data = data.replace(delimRegex, "");