Skip to content

Commit

Permalink
Updates for newer version of eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Caligatio committed Oct 9, 2022
1 parent eb7d93a commit 191964a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 141 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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",
Expand All @@ -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: "^_" }],
Expand Down
74 changes: 9 additions & 65 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -261,7 +205,7 @@ export abstract class jsSHABase<StateT, VariantT> {
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) {
Expand Down
29 changes: 21 additions & 8 deletions src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 9 additions & 19 deletions test/src/test_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ 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");
});

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");
Expand Down Expand Up @@ -102,15 +102,15 @@ 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");
});

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");
Expand All @@ -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<number[], "SHA-TEST"> {
Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/test_converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_sha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_sha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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");
});
Expand Down
6 changes: 3 additions & 3 deletions test/src/test_sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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");

Expand Down Expand Up @@ -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");
});
Expand Down
8 changes: 4 additions & 4 deletions test/src/test_sha3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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");
});
Expand Down
Loading

0 comments on commit 191964a

Please sign in to comment.