Commit 99475c51 authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

fix encryption of 0-length files

parent cc9b4e26
......@@ -280,12 +280,17 @@ class EncryptStream extends TransformStream {
this._hmac = crypto.createHmac('sha256', Buffer.from(encryption.dataHmacKey, 'hex'));
}
_transform(chunk, ignoredEncoding, callback) {
pushIvIfNeeded() {
if (!this._ivPushed) {
this.push(this._iv);
this._hmac.update(this._iv);
this._ivPushed = true;
}
}
_transform(chunk, ignoredEncoding, callback) {
this.pushIvIfNeeded();
try {
const crypt = this._cipher.update(chunk);
this._hmac.update(crypt);
......@@ -297,6 +302,7 @@ class EncryptStream extends TransformStream {
_flush(callback) {
try {
this.pushIvIfNeeded(); // for 0-length files
const crypt = this._cipher.final();
this.push(crypt);
this._hmac.update(crypt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment