From 3f85c32c7cd1e893c0b684eb94264ec1fcc32e87 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 25 Nov 2022 15:30:32 +0000 Subject: [PATCH] Lint --- src/core/Utils.mjs | 13 ++++++++----- src/core/operations/ChaCha.mjs | 18 ++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/Utils.mjs b/src/core/Utils.mjs index 2457c5b7..fe3b1a88 100755 --- a/src/core/Utils.mjs +++ b/src/core/Utils.mjs @@ -381,6 +381,7 @@ class Utils { } } + /** * Converts a byte array to an integer. * @@ -390,10 +391,10 @@ class Utils { * * @example * // returns 67305985 - * Utils.byteArrayToInt([ 1, 2, 3, 4], "little"); + * Utils.byteArrayToInt([1, 2, 3, 4], "little"); * * // returns 16909060 - * Utils.byteArrayToInt([ 1, 2, 3, 4], "big"); + * Utils.byteArrayToInt([1, 2, 3, 4], "big"); */ static byteArrayToInt(byteArray, byteorder) { let value = 0; @@ -409,6 +410,7 @@ class Utils { return value; } + /** * Converts an integer to a byte array of {length} bytes. * @@ -418,13 +420,13 @@ class Utils { * @returns {byteArray} * * @example - * // returns [ 5, 255, 109, 1 ] + * // returns [5, 255, 109, 1] * Utils.intToByteArray(23985925, 4, "little"); * - * // returns [ 1, 109, 255, 5 ] + * // returns [1, 109, 255, 5] * Utils.intToByteArray(23985925, 4, "big"); * - * // returns [ 0, 0, 0, 0, 1, 109, 255, 5 ] + * // returns [0, 0, 0, 0, 1, 109, 255, 5] * Utils.intToByteArray(23985925, 8, "big"); */ static intToByteArray(value, length, byteorder) { @@ -443,6 +445,7 @@ class Utils { return arr; } + /** * Converts a string to an ArrayBuffer. * Treats the string as UTF-8 if any values are over 255. diff --git a/src/core/operations/ChaCha.mjs b/src/core/operations/ChaCha.mjs index 1f253c68..166c1663 100644 --- a/src/core/operations/ChaCha.mjs +++ b/src/core/operations/ChaCha.mjs @@ -159,9 +159,12 @@ class ChaCha extends Operation { ChaCha uses a key of 16 or 32 bytes (128 or 256 bits).`); } - let counter, nonce; - let counterLength; - if (nonceType !== "Integer") { + + let counter, nonce, counterLength; + if (nonceType === "Integer") { + nonce = Utils.intToByteArray(parseInt(args[1].string, 10), 12, "little"); + counterLength = 4; + } else { nonce = Utils.convertToByteArray(args[1].string, args[1].option); if (!(nonce.length === 12 || nonce.length === 8)) { throw new OperationError(`Invalid nonce length: ${nonce.length} bytes. @@ -169,15 +172,10 @@ ChaCha uses a key of 16 or 32 bytes (128 or 256 bits).`); ChaCha uses a nonce of 8 or 12 bytes (64 or 96 bits).`); } counterLength = 16 - nonce.length; - counter = Utils.intToByteArray(args[2], counterLength, "little"); - } - if (nonceType === "Integer") { - nonce = Utils.intToByteArray(parseInt(args[1].string, 10), 12, "little"); - counterLength = 4; - counter = Utils.intToByteArray(args[2], counterLength, "little"); } + counter = Utils.intToByteArray(args[2], counterLength, "little"); - const output = new Array(); + const output = []; input = Utils.convertToByteArray(input, inputType); let counterAsInt = Utils.byteArrayToInt(counter, "little");