1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Shorten the CipherTransformFactory.prototype.#buildObjectKey method

- Use `TypedArray.prototype.set()` rather than a manual loop when building the `key`.

 - Use an existing local variable to avoid re-computing the length of the `encryptionKey`.
This commit is contained in:
Jonas Jenwald 2025-02-15 13:00:42 +01:00
parent 92ff26e4ff
commit a722ca4de5

View file

@ -1595,12 +1595,10 @@ class CipherTransformFactory {
}
#buildObjectKey(num, gen, encryptionKey, isAes = false) {
const key = new Uint8Array(encryptionKey.length + 9);
const n = encryptionKey.length;
let i;
for (i = 0; i < n; ++i) {
key[i] = encryptionKey[i];
}
const key = new Uint8Array(n + 9);
key.set(encryptionKey);
let i = n;
key[i++] = num & 0xff;
key[i++] = (num >> 8) & 0xff;
key[i++] = (num >> 16) & 0xff;
@ -1613,7 +1611,7 @@ class CipherTransformFactory {
key[i++] = 0x54;
}
const hash = calculateMD5(key, 0, i);
return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
return hash.subarray(0, Math.min(n + 5, 16));
}
#buildCipherConstructor(cf, name, num, gen, key) {