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:
parent
92ff26e4ff
commit
a722ca4de5
@ -1595,12 +1595,10 @@ class CipherTransformFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#buildObjectKey(num, gen, encryptionKey, isAes = false) {
|
#buildObjectKey(num, gen, encryptionKey, isAes = false) {
|
||||||
const key = new Uint8Array(encryptionKey.length + 9);
|
|
||||||
const n = encryptionKey.length;
|
const n = encryptionKey.length;
|
||||||
let i;
|
const key = new Uint8Array(n + 9);
|
||||||
for (i = 0; i < n; ++i) {
|
key.set(encryptionKey);
|
||||||
key[i] = encryptionKey[i];
|
let i = n;
|
||||||
}
|
|
||||||
key[i++] = num & 0xff;
|
key[i++] = num & 0xff;
|
||||||
key[i++] = (num >> 8) & 0xff;
|
key[i++] = (num >> 8) & 0xff;
|
||||||
key[i++] = (num >> 16) & 0xff;
|
key[i++] = (num >> 16) & 0xff;
|
||||||
@ -1613,7 +1611,7 @@ class CipherTransformFactory {
|
|||||||
key[i++] = 0x54;
|
key[i++] = 0x54;
|
||||||
}
|
}
|
||||||
const hash = calculateMD5(key, 0, i);
|
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) {
|
#buildCipherConstructor(cf, name, num, gen, key) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user