This commit is contained in:
Bart Butler 2015-04-14 13:14:35 -07:00 committed by Tankred Hase
parent 11a8a99aef
commit b310877c7d
3 changed files with 16 additions and 6 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);