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() {
|
||||
function calculatePDF20Hash(password, input, userBytes) {
|
||||
class PDF20 {
|
||||
_hash(password, input, userBytes) {
|
||||
// This refers to Algorithm 2.B as defined in ISO 32000-2.
|
||||
let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
|
||||
let e = [0];
|
||||
@ -1321,57 +1321,43 @@ const PDF20 = (function PDF20Closure() {
|
||||
return k.subarray(0, 32);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class PDF20 {
|
||||
hash(password, concatBytes, userBytes) {
|
||||
return calculatePDF20Hash(password, concatBytes, userBytes);
|
||||
}
|
||||
|
||||
checkOwnerPassword(
|
||||
password,
|
||||
ownerValidationSalt,
|
||||
userBytes,
|
||||
ownerPassword
|
||||
) {
|
||||
const hashData = new Uint8Array(password.length + 56);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(ownerValidationSalt, password.length);
|
||||
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
||||
const result = calculatePDF20Hash(password, hashData, userBytes);
|
||||
return isArrayEqual(result, ownerPassword);
|
||||
}
|
||||
|
||||
checkUserPassword(password, userValidationSalt, userPassword) {
|
||||
const hashData = new Uint8Array(password.length + 8);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(userValidationSalt, password.length);
|
||||
const result = calculatePDF20Hash(password, hashData, []);
|
||||
return isArrayEqual(result, userPassword);
|
||||
}
|
||||
|
||||
getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
|
||||
const hashData = new Uint8Array(password.length + 56);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(ownerKeySalt, password.length);
|
||||
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
||||
const key = calculatePDF20Hash(password, hashData, userBytes);
|
||||
const cipher = new AES256Cipher(key);
|
||||
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
||||
}
|
||||
|
||||
getUserKey(password, userKeySalt, userEncryption) {
|
||||
const hashData = new Uint8Array(password.length + 8);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(userKeySalt, password.length);
|
||||
// `key` is the decryption key for the UE string.
|
||||
const key = calculatePDF20Hash(password, hashData, []);
|
||||
const cipher = new AES256Cipher(key);
|
||||
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
||||
}
|
||||
checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
|
||||
const hashData = new Uint8Array(password.length + 56);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(ownerValidationSalt, password.length);
|
||||
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
||||
const result = this._hash(password, hashData, userBytes);
|
||||
return isArrayEqual(result, ownerPassword);
|
||||
}
|
||||
|
||||
return PDF20;
|
||||
})();
|
||||
checkUserPassword(password, userValidationSalt, userPassword) {
|
||||
const hashData = new Uint8Array(password.length + 8);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(userValidationSalt, password.length);
|
||||
const result = this._hash(password, hashData, []);
|
||||
return isArrayEqual(result, userPassword);
|
||||
}
|
||||
|
||||
getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
|
||||
const hashData = new Uint8Array(password.length + 56);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(ownerKeySalt, password.length);
|
||||
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
||||
const key = this._hash(password, hashData, userBytes);
|
||||
const cipher = new AES256Cipher(key);
|
||||
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
||||
}
|
||||
|
||||
getUserKey(password, userKeySalt, userEncryption) {
|
||||
const hashData = new Uint8Array(password.length + 8);
|
||||
hashData.set(password, 0);
|
||||
hashData.set(userKeySalt, password.length);
|
||||
// `key` is the decryption key for the UE string.
|
||||
const key = this._hash(password, hashData, []);
|
||||
const cipher = new AES256Cipher(key);
|
||||
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
||||
}
|
||||
}
|
||||
|
||||
class CipherTransform {
|
||||
constructor(stringCipherConstructor, streamCipherConstructor) {
|
||||
|
Loading…
Reference in New Issue
Block a user