add clone to packetlist support for signature objects

This commit is contained in:
Sanjana Rajan 2017-03-07 16:51:08 -08:00
parent 7d02154dc9
commit 465d4643a8

View File

@ -26,6 +26,7 @@
import * as key from '../key.js'; import * as key from '../key.js';
import * as message from '../message.js'; import * as message from '../message.js';
import * as cleartext from '../cleartext.js'; import * as cleartext from '../cleartext.js';
import * as signature from '../signature.js'
import Packetlist from './packetlist.js'; import Packetlist from './packetlist.js';
import type_keyid from '../type/keyid.js'; import type_keyid from '../type/keyid.js';
@ -55,6 +56,17 @@ export function clonePackets(options) {
if (options.key) { if (options.key) {
options.key = options.key.toPacketlist(); options.key = options.key.toPacketlist();
} }
if (options.message) {
//could be either a Message or CleartextMessage object
if (options.message instanceof message.Message) {
options.message = options.message.packets;
} else {
options.message.signature = options.message.signature.packets;
}
}
if (options.signature) {
options.signature = options.signature.packets;
}
return options; return options;
} }
@ -91,7 +103,10 @@ export function parseClonedPackets(options, method) {
options.message = packetlistCloneToMessage(options.message); options.message = packetlistCloneToMessage(options.message);
} }
if (options.signatures) { if (options.signatures) {
options.signatures = options.signatures.map(packetlistCloneToSignature); options.signatures = options.signatures.map(packetlistCloneToSignatures);
}
if (options.signature) {
options.signature = packetlistCloneToSignature(options.signature);
} }
return options; return options;
} }
@ -102,16 +117,22 @@ function packetlistCloneToKey(clone) {
} }
function packetlistCloneToMessage(clone) { function packetlistCloneToMessage(clone) {
const packetlist = Packetlist.fromStructuredClone(clone.packets); const packetlist = Packetlist.fromStructuredClone(clone);
return new message.Message(packetlist); return new message.Message(packetlist);
} }
function packetlistCloneToCleartextMessage(clone) { function packetlistCloneToCleartextMessage(clone) {
var packetlist = Packetlist.fromStructuredClone(clone.packets); var packetlist = Packetlist.fromStructuredClone(clone.signature);
return new cleartext.CleartextMessage(clone.text, packetlist); return new cleartext.CleartextMessage(clone.text, new signature.Signature(packetlist));
} }
function packetlistCloneToSignature(clone) { //verification objects
function packetlistCloneToSignatures(clone) {
clone.keyid = type_keyid.fromClone(clone.keyid); clone.keyid = type_keyid.fromClone(clone.keyid);
return clone; return clone;
} }
function packetlistCloneToSignature(clone) {
var packetlist = Packetlist.fromStructuredClone(clone);
return new signature.Signature(packetlist);
}