mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #19650 from Snuffleupagus/shorten-crypto
Shorten the `src/core/crypto.js` file a little bit
This commit is contained in:
commit
78b310afb1
2 changed files with 13 additions and 20 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) {
|
||||
|
@ -1133,12 +1125,13 @@ class CipherTransformFactory {
|
|||
perms
|
||||
);
|
||||
}
|
||||
if (!encryptionKey && !password) {
|
||||
throw new PasswordException(
|
||||
"No password given",
|
||||
PasswordResponses.NEED_PASSWORD
|
||||
);
|
||||
} else if (!encryptionKey && password) {
|
||||
if (!encryptionKey) {
|
||||
if (!password) {
|
||||
throw new PasswordException(
|
||||
"No password given",
|
||||
PasswordResponses.NEED_PASSWORD
|
||||
);
|
||||
}
|
||||
// Attempting use the password as an owner password
|
||||
const decodedPassword = this.#decodeUserPassword(
|
||||
passwordBytes,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue