1
0
Fork 0
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:
Jonas Jenwald 2025-03-13 09:57:50 +01:00
parent a8ad7d6485
commit cc63ffa6bb

View file

@ -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) {