Skip to content

Commit fe5268d

Browse files
committed
Fix new eslint errors and warnings
1 parent d86c61c commit fe5268d

13 files changed

Lines changed: 91 additions & 116 deletions

src/common.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function parseInputOption(
128128
key: string,
129129
value: GenericInputType | undefined,
130130
bigEndianMod: -1 | 1,
131-
fallback?: packedValue
131+
fallback?: packedValue,
132132
): packedValue {
133133
const errStr = key + " must include a value and format";
134134
if (!value) {
@@ -144,10 +144,9 @@ export function parseInputOption(
144144

145145
return getStrConverter(
146146
value["format"],
147-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
148147
// @ts-ignore - the value of encoding gets value checked by getStrConverter
149148
value["encoding"] || "UTF8",
150-
bigEndianMod
149+
bigEndianMod,
151150
)(value["value"]);
152151
}
153152

@@ -189,7 +188,7 @@ export abstract class jsSHABase<StateT, VariantT> {
189188
remainderBinLen: number,
190189
processedBinLen: number,
191190
H: StateT,
192-
outputLen: number
191+
outputLen: number,
193192
) => number[];
194193
protected abstract readonly stateCloneFunc: (state: StateT) => StateT;
195194
protected abstract readonly newStateFunc: (variant: VariantT) => StateT;
@@ -205,7 +204,6 @@ export abstract class jsSHABase<StateT, VariantT> {
205204
this.utfType = inputOptions["encoding"] || "UTF8";
206205
this.numRounds = inputOptions["numRounds"] || 1;
207206

208-
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
209207
// @ts-ignore - The spec actually says ToString is called on the first parseInt argument so it's OK to use it here
210208
// to check if an arugment is an integer. This cheat would break if it's used to get the value of the argument.
211209
if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) {
@@ -289,7 +287,7 @@ export abstract class jsSHABase<StateT, VariantT> {
289287
this.remainderLen,
290288
this.processedLen,
291289
this.stateCloneFunc(this.intermediateState),
292-
outputBinLen
290+
outputBinLen,
293291
);
294292
for (i = 1; i < this.numRounds; i += 1) {
295293
/* Need to mask out bits that should be zero due to output not being a multiple of 32 */
@@ -301,7 +299,7 @@ export abstract class jsSHABase<StateT, VariantT> {
301299
outputBinLen,
302300
0,
303301
this.newStateFunc(this.shaVariant),
304-
outputBinLen
302+
outputBinLen,
305303
);
306304
}
307305

@@ -360,7 +358,7 @@ export abstract class jsSHABase<StateT, VariantT> {
360358
key["binLen"],
361359
0,
362360
this.newStateFunc(this.shaVariant),
363-
this.outputBinLen
361+
this.outputBinLen,
364362
);
365363
}
366364
while (key["value"].length <= lastArrayIndex) {
@@ -413,15 +411,15 @@ export abstract class jsSHABase<StateT, VariantT> {
413411
this.remainderLen,
414412
this.processedLen,
415413
this.stateCloneFunc(this.intermediateState),
416-
this.outputBinLen
414+
this.outputBinLen,
417415
);
418416
finalizedState = this.roundFunc(this.keyWithOPad, this.newStateFunc(this.shaVariant));
419417
finalizedState = this.finalizeFunc(
420418
firstHash,
421419
this.outputBinLen,
422420
this.variantBlockSize,
423421
finalizedState,
424-
this.outputBinLen
422+
this.outputBinLen,
425423
);
426424

427425
return finalizedState;

src/converters.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function str2packed(
2626
utfType: EncodingType,
2727
existingPacked: number[] | undefined,
2828
existingPackedLen: number | undefined,
29-
bigEndianMod: -1 | 1
29+
bigEndianMod: -1 | 1,
3030
): packedValue {
3131
let codePnt,
3232
codePntArr,
@@ -62,7 +62,7 @@ function str2packed(
6262
0xf0 | (codePnt >>> 18),
6363
0x80 | ((codePnt >>> 12) & 0x3f),
6464
0x80 | ((codePnt >>> 6) & 0x3f),
65-
0x80 | (codePnt & 0x3f)
65+
0x80 | (codePnt & 0x3f),
6666
);
6767
}
6868

@@ -116,7 +116,7 @@ function hex2packed(
116116
str: string,
117117
existingPacked: number[] | undefined,
118118
existingPackedLen: number | undefined,
119-
bigEndianMod: -1 | 1
119+
bigEndianMod: -1 | 1,
120120
): packedValue {
121121
let i, num, intOffset, byteOffset;
122122

@@ -159,7 +159,7 @@ function bytes2packed(
159159
str: string,
160160
existingPacked: number[] | undefined,
161161
existingPackedLen: number | undefined,
162-
bigEndianMod: -1 | 1
162+
bigEndianMod: -1 | 1,
163163
): packedValue {
164164
let codePnt, i, intOffset, byteOffset;
165165

@@ -195,7 +195,7 @@ function b642packed(
195195
str: string,
196196
existingPacked: number[] | undefined,
197197
existingPackedLen: number | undefined,
198-
bigEndianMod: -1 | 1
198+
bigEndianMod: -1 | 1,
199199
): packedValue {
200200
let byteCnt = 0,
201201
index,
@@ -258,7 +258,7 @@ function uint8array2packed(
258258
arr: Uint8Array,
259259
existingPacked: number[] | undefined,
260260
existingPackedLen: number | undefined,
261-
bigEndianMod: -1 | 1
261+
bigEndianMod: -1 | 1,
262262
): packedValue {
263263
let i, intOffset, byteOffset;
264264

@@ -292,7 +292,7 @@ function arraybuffer2packed(
292292
arr: ArrayBuffer,
293293
existingPacked: number[] | undefined,
294294
existingPackedLen: number | undefined,
295-
bigEndianMod: -1 | 1
295+
bigEndianMod: -1 | 1,
296296
): packedValue {
297297
return uint8array2packed(new Uint8Array(arr), existingPacked, existingPackedLen, bigEndianMod);
298298
}
@@ -308,7 +308,7 @@ function arraybuffer2packed(
308308
export function getStrConverter(
309309
format: FormatType,
310310
utfType: EncodingType,
311-
bigEndianMod: -1 | 1
311+
bigEndianMod: -1 | 1,
312312
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
313313
): (input: any, existingBin?: number[], existingBinLen?: number) => packedValue {
314314
/* Validate encoding */
@@ -369,7 +369,7 @@ export function getStrConverter(
369369
case "ARRAYBUFFER":
370370
try {
371371
new ArrayBuffer(0);
372-
} catch (ignore) {
372+
} catch {
373373
throw new Error(arraybuffer_error);
374374
}
375375
/**
@@ -384,7 +384,7 @@ export function getStrConverter(
384384
case "UINT8ARRAY":
385385
try {
386386
new Uint8Array(0);
387-
} catch (ignore) {
387+
} catch {
388388
throw new Error(uint8array_error);
389389
}
390390
/**
@@ -417,7 +417,7 @@ export function packed2hex(
417417
packed: number[],
418418
outputLength: number,
419419
bigEndianMod: -1 | 1,
420-
formatOpts: { outputUpper: boolean; b64Pad: string }
420+
formatOpts: { outputUpper: boolean; b64Pad: string },
421421
): string {
422422
const hex_tab = "0123456789abcdef";
423423
let str = "",
@@ -449,7 +449,7 @@ export function packed2b64(
449449
packed: number[],
450450
outputLength: number,
451451
bigEndianMod: -1 | 1,
452-
formatOpts: { outputUpper: boolean; b64Pad: string }
452+
formatOpts: { outputUpper: boolean; b64Pad: string },
453453
): string {
454454
let str = "",
455455
i,
@@ -560,19 +560,19 @@ export function getOutputConverter(
560560
format: "HEX" | "B64" | "BYTES",
561561
outputBinLen: number,
562562
bigEndianMod: -1 | 1,
563-
outputOptions: { outputUpper: boolean; b64Pad: string }
563+
outputOptions: { outputUpper: boolean; b64Pad: string },
564564
): (binarray: number[]) => string;
565565
export function getOutputConverter(
566566
format: "ARRAYBUFFER",
567567
outputBinLen: number,
568568
bigEndianMod: -1 | 1,
569-
outputOptions: { outputUpper: boolean; b64Pad: string }
569+
outputOptions: { outputUpper: boolean; b64Pad: string },
570570
): (binarray: number[]) => ArrayBuffer;
571571
export function getOutputConverter(
572572
format: "UINT8ARRAY",
573573
outputBinLen: number,
574574
bigEndianMod: -1 | 1,
575-
outputOptions: { outputUpper: boolean; b64Pad: string }
575+
outputOptions: { outputUpper: boolean; b64Pad: string },
576576
): (binarray: number[]) => Uint8Array;
577577
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
578578
export function getOutputConverter(format: any, outputBinLen: any, bigEndianMod: any, outputOptions: any): any {
@@ -593,7 +593,7 @@ export function getOutputConverter(format: any, outputBinLen: any, bigEndianMod:
593593
try {
594594
/* Need to test ArrayBuffer support */
595595
new ArrayBuffer(0);
596-
} catch (ignore) {
596+
} catch {
597597
throw new Error(arraybuffer_error);
598598
}
599599
return function (binarray: number[]): ArrayBuffer {
@@ -603,7 +603,7 @@ export function getOutputConverter(format: any, outputBinLen: any, bigEndianMod:
603603
try {
604604
/* Need to test Uint8Array support */
605605
new Uint8Array(0);
606-
} catch (ignore) {
606+
} catch {
607607
throw new Error(uint8array_error);
608608
}
609609
return function (binarray: number[]): Uint8Array {

src/sha3.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function roundSHA3(block: number[] | null, state: Int_64[][]): Int_64[][] {
104104
for (x = 0; x < block.length; x += 2) {
105105
state[(x >>> 1) % 5][((x >>> 1) / 5) | 0] = xor_64_2(
106106
state[(x >>> 1) % 5][((x >>> 1) / 5) | 0],
107-
new Int_64(block[x + 1], block[x])
107+
new Int_64(block[x + 1], block[x]),
108108
);
109109
}
110110
}
@@ -140,8 +140,8 @@ function roundSHA3(block: number[] | null, state: Int_64[][]): Int_64[][] {
140140
B[x][y],
141141
new Int_64(
142142
~B[(x + 1) % 5][y].highOrder & B[(x + 2) % 5][y].highOrder,
143-
~B[(x + 1) % 5][y].lowOrder & B[(x + 2) % 5][y].lowOrder
144-
)
143+
~B[(x + 1) % 5][y].lowOrder & B[(x + 2) % 5][y].lowOrder,
144+
),
145145
);
146146
}
147147
}
@@ -172,7 +172,7 @@ function finalizeSHA3(
172172
state: Int_64[][],
173173
blockSize: number,
174174
delimiter: number,
175-
outputLen: number
175+
outputLen: number,
176176
): number[] {
177177
let i,
178178
state_offset = 0,
@@ -362,7 +362,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
362362
remainderBinLen: number,
363363
processedBinLen: number,
364364
H: Int_64[][],
365-
outputLen: number
365+
outputLen: number,
366366
) => number[];
367367
stateCloneFunc: (state: Int_64[][]) => Int_64[][];
368368
newStateFunc: (variant: VariantType) => Int_64[][];
@@ -372,7 +372,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
372372
constructor(
373373
variant: FixedLengthVariantType,
374374
inputFormat: FormatNoTextType,
375-
options?: FixedLengthOptionsNoEncodingType
375+
options?: FixedLengthOptionsNoEncodingType,
376376
);
377377
constructor(variant: "SHAKE128" | "SHAKE256", inputFormat: "TEXT", options?: SHAKEOptionsEncodingType);
378378
constructor(variant: "SHAKE128" | "SHAKE256", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);
@@ -505,7 +505,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
505505
state,
506506
variantBlockSize,
507507
delimiter,
508-
outputBinLen
508+
outputBinLen,
509509
);
510510
};
511511

@@ -528,7 +528,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
528528
}
529529
const packedParams = packedLEConcat(
530530
encode_string(resolvedOptions["funcName"]),
531-
encode_string(resolvedOptions["customization"])
531+
encode_string(resolvedOptions["customization"]),
532532
);
533533

534534
/* CSHAKE is defined to be a call to SHAKE iff both the customization and function-name string are both empty. This
@@ -538,7 +538,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
538538
for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {
539539
this.intermediateState = this.roundFunc(
540540
byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),
541-
this.intermediateState
541+
this.intermediateState,
542542
);
543543
this.processedLen += this.variantBlockSize;
544544
}
@@ -561,7 +561,7 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
561561
for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {
562562
this.intermediateState = this.roundFunc(
563563
byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),
564-
this.intermediateState
564+
this.intermediateState,
565565
);
566566
this.processedLen += this.variantBlockSize;
567567
}
@@ -574,19 +574,18 @@ export default class jsSHA extends jsSHABase<Int_64[][], VariantType> {
574574
* @param options Hashmap of extra outputs options. `outputLen` must be specified.
575575
* @returns The KMAC in the format specified.
576576
*/
577-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
578577
protected _getKMAC(options: { outputLen: number }): number[] {
579578
const concatedRemainder = packedLEConcat(
580579
{ value: this.remainder.slice(), binLen: this.remainderLen },
581-
right_encode(options["outputLen"])
580+
right_encode(options["outputLen"]),
582581
);
583582

584583
return this.finalizeFunc(
585584
concatedRemainder["value"],
586585
concatedRemainder["binLen"],
587586
this.processedLen,
588587
this.stateCloneFunc(this.intermediateState),
589-
options["outputLen"]
588+
options["outputLen"],
590589
);
591590
}
592591
}

src/sha512.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function finalizeSHA512(
204204
remainderBinLen: number,
205205
processedBinLen: number,
206206
H: Int_64[],
207-
variant: VariantType
207+
variant: VariantType,
208208
): number[] {
209209
let i, retVal;
210210

@@ -236,7 +236,6 @@ function finalizeSHA512(
236236
}
237237

238238
if ("SHA-384" === variant) {
239-
H = (H as unknown) as Int_64[];
240239
retVal = [
241240
H[0].highOrder,
242241
H[0].lowOrder,

test/hash_data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* globals module, define, self */
22
(function (global, factory) {
3+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions */
34
typeof exports === "object" && typeof module !== "undefined"
45
? (module.exports = factory())
56
: typeof define === "function" && define.amd
6-
? define(factory)
7-
: ((global = global || self), (global.hashData = factory()));
7+
? define(factory)
8+
: ((global = global || self), (global.hashData = factory()));
89
})(this, function () {
910
"use strict";
1011

test/src/common.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ export function runHashTests(
2020
| "KMAC128"
2121
| "KMAC256",
2222
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
jsSHA: any
23+
jsSHA: any,
2424
): void {
2525
describe(`Test jsSHA(${variant}) Using NIST Tests`, () => {
2626
hashData[variant].forEach((test) => {
2727
test.outputs.forEach((output) => {
2828
if (test.hmacKey) {
2929
it(test.name + " - Old Style", () => {
3030
const hashObj = new jsSHA(variant, test.input.format);
31-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3231
// @ts-ignore
3332
hashObj.setHMACKey(test.hmacKey.value, test.hmacKey.format);
3433
hashObj.update(test.input.value);

0 commit comments

Comments
 (0)