Reduce duplication when checking the userPassword, in CipherTransformFactory.prototype.#prepareKeyData
Currently we duplicate the exact same code in both the `if`- and `else`-branches, which seems unnecessary, and we can also replace the manual loop.
This commit is contained in:
parent
a8ad7d6485
commit
cc63ffa6bb
@ -916,23 +916,15 @@ class CipherTransformFactory {
|
|||||||
cipher = new ARCFourCipher(derivedKey);
|
cipher = new ARCFourCipher(derivedKey);
|
||||||
checkData = cipher.encryptBlock(checkData);
|
checkData = cipher.encryptBlock(checkData);
|
||||||
}
|
}
|
||||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
||||||
if (userPassword[j] !== checkData[j]) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cipher = new ARCFourCipher(encryptionKey);
|
cipher = new ARCFourCipher(encryptionKey);
|
||||||
checkData = cipher.encryptBlock(
|
checkData = cipher.encryptBlock(
|
||||||
CipherTransformFactory._defaultPasswordBytes
|
CipherTransformFactory._defaultPasswordBytes
|
||||||
);
|
);
|
||||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
||||||
if (userPassword[j] !== checkData[j]) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
return checkData.every((data, k) => userPassword[k] === data)
|
||||||
}
|
? encryptionKey
|
||||||
return encryptionKey;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user