diff --git a/src/message.js b/src/message.js index 6c868e6a..d0ed2608 100644 --- a/src/message.js +++ b/src/message.js @@ -170,6 +170,15 @@ Message.prototype.getLiteralData = function() { return literal && literal.data || null; }; +/** + * Get filename from literal data packet + * @return {(String|null)} filename of literal data packet as string + */ +Message.prototype.getFilename = function() { + var literal = this.packets.findPacket(enums.packet.literal); + return literal && literal.getFilename() || null; +}; + /** * Get literal data as text * @return {(String|null)} literal body of the message interpreted as text diff --git a/src/openpgp.js b/src/openpgp.js index 7e0441c1..7414aa64 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -105,11 +105,12 @@ function encryptMessage(keys, data, passwords, params) { msg = msg.encrypt(keys, passwords); if(packets) { - var arr = []; var dataIndex = msg.packets.indexOfTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected)[0]; - arr.push(msg.packets.slice(0,dataIndex).write()); // Keys - arr.push(msg.packets.slice(dataIndex,msg.packets.length).write()); // Data - return arr; + var obj = { + keys: msg.packets.slice(0,dataIndex).write(), + data: msg.packets.slice(dataIndex,msg.packets.length).write() + }; + return obj; } else { return armor.encode(enums.armor.message, msg.packets.write()); @@ -195,7 +196,7 @@ function decryptMessage(privateKey, msg, params) { if(binary) { var obj = { data: msg.getLiteralData(), - filename: msg.filename + filename: msg.getFilename() }; return obj; } diff --git a/test/general/basic.js b/test/general/basic.js index 3fdcffe7..21598ff8 100644 --- a/test/general/basic.js +++ b/test/general/basic.js @@ -266,7 +266,7 @@ describe('Basic', function() { openpgp.encryptMessage([pubKey], plaintext, [password1, password2], params).then(function(encrypted) { expect(encrypted).to.exist; - encrypted = encrypted.join(''); + encrypted = encrypted.keys+encrypted.data; encrypted = openpgp.armor.encode(openpgp.enums.armor.message, encrypted); message = openpgp.message.readArmored(encrypted);