Merge pull request #16334 from Snuffleupagus/rm-PDF20-closure
Remove the `PDF20` closure, in the `src/core/crypto.js` file
This commit is contained in:
commit
bf01edb452
@ -1278,8 +1278,8 @@ class PDF17 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PDF20 = (function PDF20Closure() {
|
class PDF20 {
|
||||||
function calculatePDF20Hash(password, input, userBytes) {
|
_hash(password, input, userBytes) {
|
||||||
// This refers to Algorithm 2.B as defined in ISO 32000-2.
|
// This refers to Algorithm 2.B as defined in ISO 32000-2.
|
||||||
let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
|
let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
|
||||||
let e = [0];
|
let e = [0];
|
||||||
@ -1321,23 +1321,12 @@ const PDF20 = (function PDF20Closure() {
|
|||||||
return k.subarray(0, 32);
|
return k.subarray(0, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
|
||||||
class PDF20 {
|
|
||||||
hash(password, concatBytes, userBytes) {
|
|
||||||
return calculatePDF20Hash(password, concatBytes, userBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOwnerPassword(
|
|
||||||
password,
|
|
||||||
ownerValidationSalt,
|
|
||||||
userBytes,
|
|
||||||
ownerPassword
|
|
||||||
) {
|
|
||||||
const hashData = new Uint8Array(password.length + 56);
|
const hashData = new Uint8Array(password.length + 56);
|
||||||
hashData.set(password, 0);
|
hashData.set(password, 0);
|
||||||
hashData.set(ownerValidationSalt, password.length);
|
hashData.set(ownerValidationSalt, password.length);
|
||||||
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
||||||
const result = calculatePDF20Hash(password, hashData, userBytes);
|
const result = this._hash(password, hashData, userBytes);
|
||||||
return isArrayEqual(result, ownerPassword);
|
return isArrayEqual(result, ownerPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1345,7 +1334,7 @@ const PDF20 = (function PDF20Closure() {
|
|||||||
const hashData = new Uint8Array(password.length + 8);
|
const hashData = new Uint8Array(password.length + 8);
|
||||||
hashData.set(password, 0);
|
hashData.set(password, 0);
|
||||||
hashData.set(userValidationSalt, password.length);
|
hashData.set(userValidationSalt, password.length);
|
||||||
const result = calculatePDF20Hash(password, hashData, []);
|
const result = this._hash(password, hashData, []);
|
||||||
return isArrayEqual(result, userPassword);
|
return isArrayEqual(result, userPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1354,7 +1343,7 @@ const PDF20 = (function PDF20Closure() {
|
|||||||
hashData.set(password, 0);
|
hashData.set(password, 0);
|
||||||
hashData.set(ownerKeySalt, password.length);
|
hashData.set(ownerKeySalt, password.length);
|
||||||
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
||||||
const key = calculatePDF20Hash(password, hashData, userBytes);
|
const key = this._hash(password, hashData, userBytes);
|
||||||
const cipher = new AES256Cipher(key);
|
const cipher = new AES256Cipher(key);
|
||||||
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
||||||
}
|
}
|
||||||
@ -1364,15 +1353,12 @@ const PDF20 = (function PDF20Closure() {
|
|||||||
hashData.set(password, 0);
|
hashData.set(password, 0);
|
||||||
hashData.set(userKeySalt, password.length);
|
hashData.set(userKeySalt, password.length);
|
||||||
// `key` is the decryption key for the UE string.
|
// `key` is the decryption key for the UE string.
|
||||||
const key = calculatePDF20Hash(password, hashData, []);
|
const key = this._hash(password, hashData, []);
|
||||||
const cipher = new AES256Cipher(key);
|
const cipher = new AES256Cipher(key);
|
||||||
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PDF20;
|
|
||||||
})();
|
|
||||||
|
|
||||||
class CipherTransform {
|
class CipherTransform {
|
||||||
constructor(stringCipherConstructor, streamCipherConstructor) {
|
constructor(stringCipherConstructor, streamCipherConstructor) {
|
||||||
this.StringCipherConstructor = stringCipherConstructor;
|
this.StringCipherConstructor = stringCipherConstructor;
|
||||||
|
Loading…
Reference in New Issue
Block a user