Impliclity decrypt data if key is present

This commit is contained in:
Daniel Gasienica 2018-04-03 22:47:23 -04:00
parent 94c75762b5
commit a61c905146

View file

@ -455,7 +455,7 @@ function _getAnonymousAttachmentFileName(message, index) {
async function readAttachment(dir, attachment, name, options) { async function readAttachment(dir, attachment, name, options) {
options = options || {}; options = options || {};
const { key, encrypted } = options; const { key } = options;
const anonymousName = _sanitizeFileName(name); const anonymousName = _sanitizeFileName(name);
const targetPath = path.join(dir, anonymousName); const targetPath = path.join(dir, anonymousName);
@ -467,7 +467,8 @@ async function readAttachment(dir, attachment, name, options) {
const data = await readFileAsArrayBuffer(targetPath); const data = await readFileAsArrayBuffer(targetPath);
if (encrypted && key) { const isEncrypted = !_.isUndefined(key);
if (isEncrypted) {
attachment.data = await crypto.decryptSymmetric(key, data); attachment.data = await crypto.decryptSymmetric(key, data);
} else { } else {
attachment.data = data; attachment.data = data;
@ -1208,9 +1209,7 @@ async function importFromDirectory(directory, options) {
attachmentsDir, attachmentsDir,
}); });
const result = await importNonMessages(db, stagingDir, options); const result = await importNonMessages(db, stagingDir, options);
await importConversations(db, stagingDir, Object.assign({}, options, { await importConversations(db, stagingDir, Object.assign({}, options));
encrypted: true,
}));
console.log('Done importing from backup!'); console.log('Done importing from backup!');
return result; return result;