diff --git a/src/packet/openpgp.packet.compressed.js b/src/packet/openpgp.packet.compressed.js index e02ee4da..9dcfec27 100644 --- a/src/packet/openpgp.packet.compressed.js +++ b/src/packet/openpgp.packet.compressed.js @@ -25,9 +25,14 @@ * a Signature or One-Pass Signature packet, and contains a literal data * packet. */ -function openpgp_packet_compressed() { +function openpgp_packet_compressed(bytes) { this.tagType = 8; this.decompressedData = null; + this.compressedData = null; + this.type = 0; + + if(bytes != undefined) + this.read(bytes); /** * Parsing function for the packet. @@ -46,6 +51,21 @@ function openpgp_packet_compressed() { this.compressedData = input.substring(position+1, position+len); return this; } + + this.read = function(bytes) { + this.type = input.charCodeAt(mypos++); + this.compressedData = input.substring(position+1, position+len); + this.decompressedData = null; + } + + this.write = function() { + if(this.compressedData == null) + this.compress(); + + return String.fromCharCode(this.type) + this.compress(); + } + + /** * Decompression method for decompressing the compressed data * read by read_packet @@ -104,9 +124,7 @@ function openpgp_packet_compressed() { * @param {String} data Data to be compressed * @return {String} The compressed data stored in attribute compressedData */ - function compress(type, data) { - this.type = type; - this.decompressedData = data; + function compress() { switch (this.type) { case 0: // - Uncompressed this.compressedData = this.decompressedData; diff --git a/src/packet/openpgp.packet.encrypteddata.js b/src/packet/openpgp.packet.encrypteddata.js index be31467e..22cce82c 100644 --- a/src/packet/openpgp.packet.encrypteddata.js +++ b/src/packet/openpgp.packet.encrypteddata.js @@ -50,6 +50,15 @@ function openpgp_packet_encrypteddata() { return this; } + this.read = function(bytes) { + this.encryptedData = bytes; + this.decryptedData = null; + } + + this.write = function() { + return this.encryptedData; + } + /** * Symmetrically decrypt the packet data * @@ -68,6 +77,11 @@ function openpgp_packet_encrypteddata() { return this.decryptedData; } + this.encrypt = function(algo, key) { + this.encryptedData = openpgp_crypto_symmetricEncrypt( + openpgp_crypto_getPrefixRandom(algo), algo, key, this.decryptedData, true); + } + /** * Creates a string representation of the packet * diff --git a/src/packet/openpgp.packet.js b/src/packet/openpgp.packet.js index cefb838e..36f84449 100644 --- a/src/packet/openpgp.packet.js +++ b/src/packet/openpgp.packet.js @@ -402,6 +402,32 @@ function _openpgp_packet() { } this.read_packet = read_packet; + + + /** + * @enum {Integer} + * A list of packet type and numeric tags associated with them. + */ + this.type = { + reserved: 0, + public_key_encrypted_session_key: 1, + signature: 2, + symmetric_key_encrypted_session_key: 3, + one_pass_signature: 4, + secret_key: 5, + public_key: 6, + secret_subkey: 7, + compressed: 8, + symmetrically_encrypted_data: 9, + marker: 10, + literal: 11, + trust: 12, + userid: 13, + public_subkey: 14, + user_attribute: 17, + sym_encrypted_and_integrity_protected_data: 18, + modification_detection_code: 19 + }; } var openpgp_packet = new _openpgp_packet(); diff --git a/src/packet/openpgp.packetlist.js b/src/packet/openpgp.packetlist.js new file mode 100644 index 00000000..ff113873 --- /dev/null +++ b/src/packet/openpgp.packetlist.js @@ -0,0 +1,40 @@ + + +/** + * @class + * @classdesc This class represents a list of openpgp packets. + */ +function openpgp_packetlist(bytes) { + + /** @type {openpgp_packet_[]} A list of packets */ + this.list = [] + + + /** + * Reads a stream of binary data and interprents it as a list of packets. + * @param {openpgp_bytearray} An array of bytes. + */ + this.read = function(bytes) { + var i = 0; + + while(i < bytes.length) { + var packet = openpgp_packet.read_packet(bytes, i, bytes.length - i); + i += packet.headerLength + packet.packetLength; + + list.push(packet); + } + } + + /** + * Creates a binary representation of openpgp objects contained within the + * class instance. + * @returns {openpgp_bytearray} An array of bytes containing valid openpgp packets. + */ + this.write = function() { + var bytes = ''; + + for(var i in this.list) { + bytes += openpgp_packet.write_header + } + +}