🐛 Do not read beyond stream in decryptor
This commit is contained in:
parent
26467816f0
commit
050f82b382
1 changed files with 9 additions and 5 deletions
|
@ -8,16 +8,20 @@ export default function decryptStream(inputStream: stream.Readable, decryptionKe
|
||||||
read(size) {
|
read(size) {
|
||||||
//There are 12 random bytes at the beginning, we need to use them to initialize the decryption keys, but we can ignore the decrypted bytes.
|
//There are 12 random bytes at the beginning, we need to use them to initialize the decryption keys, but we can ignore the decrypted bytes.
|
||||||
if (!skippedRandomHeader) {
|
if (!skippedRandomHeader) {
|
||||||
const encryptedHeader = inputStream.read(12);
|
const encryptedHeader: Buffer = inputStream.read(12);
|
||||||
decryptChunk(encryptedHeader, decryptionKeys);
|
decryptChunk(encryptedHeader, decryptionKeys);
|
||||||
skippedRandomHeader = true;
|
skippedRandomHeader = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Decrypt chunk
|
//Decrypt chunk
|
||||||
const encryptedChunk = inputStream.read(size);
|
const encryptedChunk: Buffer = inputStream.read(size);
|
||||||
|
if (encryptedChunk === null) {
|
||||||
|
//If end has been reached, stop
|
||||||
|
this.push(null);
|
||||||
|
} else {
|
||||||
const decryptedChunk = decryptChunk(encryptedChunk, decryptionKeys);
|
const decryptedChunk = decryptChunk(encryptedChunk, decryptionKeys);
|
||||||
|
|
||||||
this.push(decryptedChunk);
|
this.push(decryptedChunk);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue