mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
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
1 changed files with 3 additions and 11 deletions
|
@ -916,23 +916,15 @@ class CipherTransformFactory {
|
|||
cipher = new ARCFourCipher(derivedKey);
|
||||
checkData = cipher.encryptBlock(checkData);
|
||||
}
|
||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
||||
if (userPassword[j] !== checkData[j]) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cipher = new ARCFourCipher(encryptionKey);
|
||||
checkData = cipher.encryptBlock(
|
||||
CipherTransformFactory._defaultPasswordBytes
|
||||
);
|
||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
||||
if (userPassword[j] !== checkData[j]) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return encryptionKey;
|
||||
return checkData.every((data, k) => userPassword[k] === data)
|
||||
? encryptionKey
|
||||
: null;
|
||||
}
|
||||
|
||||
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue