From 01edeb28a669397b52126f40bb31e56f92a46c1d Mon Sep 17 00:00:00 2001 From: Ryan Chernoff Date: Mon, 21 Apr 2025 14:57:45 -0400 Subject: [PATCH] Wrapped XOR run function in try catch block to handle key errors --- src/core/operations/XOR.mjs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/operations/XOR.mjs b/src/core/operations/XOR.mjs index aa228842..0b867236 100644 --- a/src/core/operations/XOR.mjs +++ b/src/core/operations/XOR.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; import Utils from "../Utils.mjs"; import { bitOp, xor, BITWISE_OP_DELIMS } from "../lib/BitwiseOp.mjs"; @@ -51,11 +52,15 @@ class XOR extends Operation { * @returns {byteArray} */ run(input, args) { - input = new Uint8Array(input); - const key = Utils.convertToByteArray(args[0].string || "", args[0].option), - [, scheme, nullPreserving] = args; + try { + input = new Uint8Array(input); + const key = Utils.convertToByteArray(args[0].string || "", args[0].option), + [, scheme, nullPreserving] = args; - return bitOp(input, key, xor, nullPreserving, scheme); + return bitOp(input, key, xor, nullPreserving, scheme); + } catch (error) { + throw new OperationError("Invalid Characters in key"); + } } /**