From 191964a388b22a5a3706be6cb152894d3f076769 Mon Sep 17 00:00:00 2001 From: Brian Turek <2017685+Caligatio@users.noreply.github.com> Date: Sun, 9 Oct 2022 07:34:52 +0200 Subject: [PATCH] Updates for newer version of eslint --- .eslintrc.js | 13 ++++++- src/common.ts | 74 +++++-------------------------------- src/converters.ts | 29 +++++++++++---- test/src/common.ts | 2 +- test/src/test_common.ts | 28 +++++--------- test/src/test_converters.ts | 2 +- test/src/test_sha.ts | 4 +- test/src/test_sha1.ts | 4 +- test/src/test_sha256.ts | 6 +-- test/src/test_sha3.ts | 8 ++-- test/src/test_sha512.ts | 39 ++----------------- 11 files changed, 68 insertions(+), 141 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 341a077..5f2de0d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,7 +4,7 @@ module.exports = { parserOptions: { project: "./tsconfig.json", }, - ignorePatterns: ["*.txt", "/dist", "/test/dist"], + ignorePatterns: ["*.txt", "/dist", "/test/dist", ".eslintrc.js"], plugins: ["@typescript-eslint"], overrides: [ { @@ -13,6 +13,13 @@ module.exports = { "@typescript-eslint/explicit-function-return-type": "off", }, }, + { + files: ["test/**"], + rules: { + "@typescript-eslint/no-unsafe-call": "off", + "@typescript-eslint/no-unsafe-return": "off", + }, + }, ], extends: [ "eslint:recommended", @@ -21,6 +28,10 @@ module.exports = { "plugin:@typescript-eslint/recommended-requiring-type-checking", ], rules: { + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-unsafe-argument": "off", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-unsafe-member-access": "off", "@typescript-eslint/camelcase": "off", "@typescript-eslint/class-name-casing": "off", "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }], diff --git a/src/common.ts b/src/common.ts index cb6c034..57add71 100644 --- a/src/common.ts +++ b/src/common.ts @@ -14,69 +14,13 @@ export const TWO_PWR_32 = 4294967296; /* Constant used in SHA-2 families */ export const K_sha2 = [ - 0x428a2f98, - 0x71374491, - 0xb5c0fbcf, - 0xe9b5dba5, - 0x3956c25b, - 0x59f111f1, - 0x923f82a4, - 0xab1c5ed5, - 0xd807aa98, - 0x12835b01, - 0x243185be, - 0x550c7dc3, - 0x72be5d74, - 0x80deb1fe, - 0x9bdc06a7, - 0xc19bf174, - 0xe49b69c1, - 0xefbe4786, - 0x0fc19dc6, - 0x240ca1cc, - 0x2de92c6f, - 0x4a7484aa, - 0x5cb0a9dc, - 0x76f988da, - 0x983e5152, - 0xa831c66d, - 0xb00327c8, - 0xbf597fc7, - 0xc6e00bf3, - 0xd5a79147, - 0x06ca6351, - 0x14292967, - 0x27b70a85, - 0x2e1b2138, - 0x4d2c6dfc, - 0x53380d13, - 0x650a7354, - 0x766a0abb, - 0x81c2c92e, - 0x92722c85, - 0xa2bfe8a1, - 0xa81a664b, - 0xc24b8b70, - 0xc76c51a3, - 0xd192e819, - 0xd6990624, - 0xf40e3585, - 0x106aa070, - 0x19a4c116, - 0x1e376c08, - 0x2748774c, - 0x34b0bcb5, - 0x391c0cb3, - 0x4ed8aa4a, - 0x5b9cca4f, - 0x682e6ff3, - 0x748f82ee, - 0x78a5636f, - 0x84c87814, - 0x8cc70208, - 0x90befffa, - 0xa4506ceb, - 0xbef9a3f7, + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, + 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, + 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, + 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, + 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, + 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, ]; @@ -200,7 +144,7 @@ export function parseInputOption( return getStrConverter( value["format"], - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - the value of encoding gets value checked by getStrConverter value["encoding"] || "UTF8", bigEndianMod @@ -261,7 +205,7 @@ export abstract class jsSHABase { this.utfType = inputOptions["encoding"] || "UTF8"; this.numRounds = inputOptions["numRounds"] || 1; - /* eslint-disable-next-line @typescript-eslint/ban-ts-ignore */ + /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ // @ts-ignore - The spec actually says ToString is called on the first parseInt argument so it's OK to use it here // to check if an arugment is an integer. This cheat would break if it's used to get the value of the argument. if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) { diff --git a/src/converters.ts b/src/converters.ts index dd0703c..43260fe 100644 --- a/src/converters.ts +++ b/src/converters.ts @@ -557,23 +557,36 @@ export function packed2uint8array(packed: number[], outputLength: number, bigEnd * @returns Function that will convert a packed integer array to desired format. */ export function getOutputConverter( - format: "HEX" | "B64" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY", + format: "HEX" | "B64" | "BYTES", outputBinLen: number, bigEndianMod: -1 | 1, outputOptions: { outputUpper: boolean; b64Pad: string } - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ -): (binarray: number[]) => any { +): (binarray: number[]) => string; +export function getOutputConverter( + format: "ARRAYBUFFER", + outputBinLen: number, + bigEndianMod: -1 | 1, + outputOptions: { outputUpper: boolean; b64Pad: string } +): (binarray: number[]) => ArrayBuffer; +export function getOutputConverter( + format: "UINT8ARRAY", + outputBinLen: number, + bigEndianMod: -1 | 1, + outputOptions: { outputUpper: boolean; b64Pad: string } +): (binarray: number[]) => Uint8Array; +/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ +export function getOutputConverter(format: any, outputBinLen: any, bigEndianMod: any, outputOptions: any): any { switch (format) { case "HEX": - return function (binarray): string { + return function (binarray: number[]): string { return packed2hex(binarray, outputBinLen, bigEndianMod, outputOptions); }; case "B64": - return function (binarray): string { + return function (binarray: number[]): string { return packed2b64(binarray, outputBinLen, bigEndianMod, outputOptions); }; case "BYTES": - return function (binarray): string { + return function (binarray: number[]): string { return packed2bytes(binarray, outputBinLen, bigEndianMod); }; case "ARRAYBUFFER": @@ -583,7 +596,7 @@ export function getOutputConverter( } catch (ignore) { throw new Error(arraybuffer_error); } - return function (binarray): ArrayBuffer { + return function (binarray: number[]): ArrayBuffer { return packed2arraybuffer(binarray, outputBinLen, bigEndianMod); }; case "UINT8ARRAY": @@ -593,7 +606,7 @@ export function getOutputConverter( } catch (ignore) { throw new Error(uint8array_error); } - return function (binarray): Uint8Array { + return function (binarray: number[]): Uint8Array { return packed2uint8array(binarray, outputBinLen, bigEndianMod); }; default: diff --git a/test/src/common.ts b/test/src/common.ts index 00f82ef..bc26c7d 100644 --- a/test/src/common.ts +++ b/test/src/common.ts @@ -28,7 +28,7 @@ export function runHashTests( if (test.hmacKey) { it(test.name + " - Old Style", () => { const hashObj = new jsSHA(variant, test.input.format); - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore hashObj.setHMACKey(test.hmacKey.value, test.hmacKey.format); hashObj.update(test.input.value); diff --git a/test/src/test_common.ts b/test/src/test_common.ts index 1daf5a5..2b8cee8 100644 --- a/test/src/test_common.ts +++ b/test/src/test_common.ts @@ -56,7 +56,7 @@ describe("Test parseInputOption", () => { it("For Value Missing value Key", () => { assert.throws(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberately bad value for test parseInputOption("kmacKey", { format: "HEX" }, 1); }, "kmacKey must include a value and format"); @@ -64,7 +64,7 @@ describe("Test parseInputOption", () => { it("For Value Missing binLen Key", () => { assert.throws(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberately bad value for test parseInputOption("kmacKey", { value: "TEST" }, 1); }, "kmacKey must include a value and format"); @@ -102,7 +102,7 @@ describe("Test getOutputOpts", () => { it("Invalid b64Pad", () => { assert.throws(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad b64Pad value to test exceptions getOutputOpts({ b64Pad: 1 }); }, "Invalid b64Pad formatting option"); @@ -110,7 +110,7 @@ describe("Test getOutputOpts", () => { it("Invalid outputUpper", () => { assert.throws(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad outputUpper value to test exceptions getOutputOpts({ outputUpper: 1 }); }, "Invalid outputUpper formatting option"); @@ -124,18 +124,8 @@ describe("Test jsSHABase", () => { stubbedFinalize = sinon.stub(), stubbedStateClone = sinon.stub(), dummyVals = [ - 0x11223344, - 0xaabbccdd, - 0xdeadbeef, - 0xfacefeed, - 0xbaddcafe, - 0xdeadcafe, - 0xdead2bad, - 0xdeaddead, - 0xcafed00d, - 0xdecafbad, - 0xfee1dead, - 0xdeadfa11, + 0x11223344, 0xaabbccdd, 0xdeadbeef, 0xfacefeed, 0xbaddcafe, 0xdeadcafe, 0xdead2bad, 0xdeaddead, 0xcafed00d, + 0xdecafbad, 0xfee1dead, 0xdeadfa11, ]; class jsSHAATest extends jsSHABase { @@ -164,7 +154,7 @@ describe("Test jsSHABase", () => { this.converterFunc = stubbedStrConverter; this.roundFunc = stubbedRound; this.stateCloneFunc = stubbedStateClone; - this.newStateFunc = (stubbedNewState as unknown) as (variant: "SHA-TEST") => number[]; + this.newStateFunc = stubbedNewState as unknown as (variant: "SHA-TEST") => number[]; this.finalizeFunc = stubbedFinalize; // eslint-disable-next-line @typescript-eslint/unbound-method this.getMAC = this._getHMAC; @@ -181,7 +171,7 @@ describe("Test jsSHABase", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getter(propName: string): any { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing return this[propName]; } @@ -191,7 +181,7 @@ describe("Test jsSHABase", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any setter(propName: string, value: any): void { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing this[propName] = value; } diff --git a/test/src/test_converters.ts b/test/src/test_converters.ts index c42ae3d..539a934 100644 --- a/test/src/test_converters.ts +++ b/test/src/test_converters.ts @@ -545,7 +545,7 @@ describe("Test getStrConverter", () => { it("Invalid UTF Exception", () => { assert.throws(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad UTF value to test exceptions getStrConverter("HEX", "UTF32", -1); }, "encoding must be UTF8, UTF16BE, or UTF16LE"); diff --git a/test/src/test_sha.ts b/test/src/test_sha.ts index 670da7f..26567fb 100644 --- a/test/src/test_sha.ts +++ b/test/src/test_sha.ts @@ -17,14 +17,14 @@ import { runHashTests } from "./common"; "SHAKE128", "SHAKE256", ].forEach((variant) => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Typescript doesn't understand the above array contains only valid values runHashTests(variant, jsSHA); }); describe("Test jsSHA Constructor", () => { it("Invalid Variant", () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad variant value assert.throws(() => new jsSHA("SHA-TEST", "HEX"), "Chosen SHA variant is not supported"); }); diff --git a/test/src/test_sha1.ts b/test/src/test_sha1.ts index 9c5dcb0..cf00c30 100644 --- a/test/src/test_sha1.ts +++ b/test/src/test_sha1.ts @@ -62,7 +62,7 @@ describe("Test jsSHA(SHA-1)", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getter(propName: string): any { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing return this[propName]; } @@ -107,7 +107,7 @@ describe("Test jsSHA(SHA-1)", () => { }); it("With Invalid Variant", () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad variant value to test exceptions assert.throws(() => new jsSHA("SHA-TEST", "HEX"), "Chosen SHA variant is not supported"); }); diff --git a/test/src/test_sha256.ts b/test/src/test_sha256.ts index 848f099..7c04761 100644 --- a/test/src/test_sha256.ts +++ b/test/src/test_sha256.ts @@ -95,7 +95,7 @@ describe("Test jsSHA(SHA-256)", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getter(propName: string): any { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing return this[propName]; } @@ -118,7 +118,7 @@ describe("Test jsSHA(SHA-256)", () => { newStateFuncSpy = sinon.spy(); sha256.__with__({ roundSHA256: roundFuncSpy, finalizeSHA256: finalizeFuncSpy, getNewState256: newStateFuncSpy })( () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const hash = new jsSHAATest(test.variant, "HEX"); @@ -149,7 +149,7 @@ describe("Test jsSHA(SHA-256)", () => { }); it("With Invalid Variant", () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad variant value to test exceptions assert.throws(() => new jsSHA("SHA-TEST", "HEX"), "Chosen SHA variant is not supported"); }); diff --git a/test/src/test_sha3.ts b/test/src/test_sha3.ts index bde51c8..d9e1906 100644 --- a/test/src/test_sha3.ts +++ b/test/src/test_sha3.ts @@ -306,7 +306,7 @@ describe("Test jsSHA(SHA3)", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getter(propName: string): any { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing return this[propName]; } @@ -315,7 +315,7 @@ describe("Test jsSHA(SHA3)", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any setter(propName: string, value: any): void { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing this[propName] = value; } @@ -439,7 +439,7 @@ describe("Test jsSHA(SHA3)", () => { finalizeFuncSpy = sinon.spy(), newStateFuncSpy = sinon.spy(); sha3.__with__({ roundSHA3: roundFuncSpy, finalizeSHA3: finalizeFuncSpy, getNewState: newStateFuncSpy })(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const hash = new jsSHAATest(test.variant, "HEX", { customization: test.customization, kmacKey: test.kmacKey }); @@ -521,7 +521,7 @@ describe("Test jsSHA(SHA3)", () => { }); it("With Invalid Variant", () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad variant value to test exceptions assert.throws(() => new jsSHA("SHA-TEST", "HEX"), "Chosen SHA variant is not supported"); }); diff --git a/test/src/test_sha512.ts b/test/src/test_sha512.ts index ddca512..779c1a5 100644 --- a/test/src/test_sha512.ts +++ b/test/src/test_sha512.ts @@ -34,38 +34,7 @@ const sha512 = rewire("../../src/sha512"), new Int_64(H_full[7], 0x137e2179), ], abcPostProcessed = [ - 0x61626380, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0x00000018, + 0x61626380, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000018, ], abcPacked = [0x61626300]; @@ -158,7 +127,7 @@ describe("Test jsSHA(SHA-512)", () => { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getter(propName: string): any { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Override "any" ban as this is only used in testing return this[propName]; } @@ -184,7 +153,7 @@ describe("Test jsSHA(SHA-512)", () => { finalizeSHA512: finalizeFuncSpy, getNewState512: newStateFuncSpy, })(() => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const hash = new jsSHAATest(test.variant, "HEX"); @@ -216,7 +185,7 @@ describe("Test jsSHA(SHA-512)", () => { }); it("With Invalid Variant", () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Deliberate bad variant value to test exceptions assert.throws(() => new jsSHA("SHA-TEST", "HEX"), "Chosen SHA variant is not supported"); });