Skip to content

Commit

Permalink
Simplify logic statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Caligatio committed Apr 29, 2020
1 parent 5ba442b commit 1dc3758
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ export abstract class jsSHABase<StateT, VariantT> {

const outputOptions = getOutputOpts(options);

if (this.isVariableLen === true) {
if (this.isVariableLen) {
if (outputOptions["outputLen"] === -1) {
throw new Error("Output length must be specified in options");
}
outputBinLen = outputOptions["outputLen"];
}

const formatFunc = getOutputConverter(format, outputBinLen, this.bigEndianMod, outputOptions);
if (this.macKeySet === true && this.getMAC) {
if (this.macKeySet && this.getMAC) {
return formatFunc(this.getMAC(outputOptions));
}

Expand All @@ -346,7 +346,7 @@ export abstract class jsSHABase<StateT, VariantT> {
);
for (i = 1; i < this.numRounds; i += 1) {
/* Need to mask out bits that should be zero due to output not being a multiple of 32 */
if (this.isVariableLen === true && outputBinLen % 32 !== 0) {
if (this.isVariableLen && outputBinLen % 32 !== 0) {
finalizedState[finalizedState.length - 1] &= 0x00ffffff >>> (24 - (outputBinLen % 32));
}
finalizedState = this.finalizeFunc(
Expand Down Expand Up @@ -374,11 +374,11 @@ export abstract class jsSHABase<StateT, VariantT> {
setHMACKey(key: Uint8Array, inputFormat: "UINT8ARRAY"): void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setHMACKey(key: any, inputFormat: any, options?: any): void {
if (this.HMACSupported !== true) {
if (!this.HMACSupported) {
throw new Error("Variant does not support HMAC");
}

if (true === this.updateCalled) {
if (this.updateCalled) {
throw new Error("Cannot set MAC key after calling update");
}

Expand All @@ -401,7 +401,7 @@ export abstract class jsSHABase<StateT, VariantT> {
throw new Error(mac_rounds_error);
}

if (true === this.macKeySet) {
if (this.macKeySet) {
throw new Error("MAC key already set");
}

Expand Down Expand Up @@ -457,7 +457,7 @@ export abstract class jsSHABase<StateT, VariantT> {
protected _getHMAC(): number[] {
let finalizedState;

if (false === this.macKeySet) {
if (!this.macKeySet) {
throw new Error("Cannot call getHMAC without first setting MAC key");
}

Expand Down
2 changes: 1 addition & 1 deletion src/sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default class jsSHA extends jsSHABase<number[], VariantType> {
constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(variant: any, inputFormat: any, options?: any) {
if (false === ("SHA-224" === variant || "SHA-256" === variant)) {
if (!("SHA-224" === variant || "SHA-256" === variant)) {
throw new Error(sha_variant_error);
}
super(variant, inputFormat, options);
Expand Down
2 changes: 1 addition & 1 deletion src/sha512.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default class jsSHA extends jsSHABase<Int_64[], VariantType> {
constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(variant: any, inputFormat: any, options?: any) {
if (false === ("SHA-384" === variant || "SHA-512" === variant)) {
if (!("SHA-384" === variant || "SHA-512" === variant)) {
throw new Error(sha_variant_error);
}
super(variant, inputFormat, options);
Expand Down

0 comments on commit 1dc3758

Please sign in to comment.