Rename attribute for data of armored message from .openpgp to .data

This commit is contained in:
Thomas Oberndörfer 2013-12-02 11:27:14 +01:00
parent c2a79368dc
commit 89eb5dff2a
7 changed files with 103 additions and 100 deletions

File diff suppressed because one or more lines are too long

View File

@ -195,7 +195,7 @@ function createcrc24(input) {
* @param {String} text OpenPGP armored message * @param {String} text OpenPGP armored message
* @returns {(Boolean|Object)} Either false in case of an error * @returns {(Boolean|Object)} Either false in case of an error
* or an object with attribute "text" containing the message text * or an object with attribute "text" containing the message text
* and an attribute "openpgp" containing the bytes. * and an attribute "data" containing the bytes.
*/ */
function dearmor(text) { function dearmor(text) {
text = text.replace(/\r/g, ''); text = text.replace(/\r/g, '');
@ -205,8 +205,8 @@ function dearmor(text) {
if (type != 2) { if (type != 2) {
var splittedtext = text.split('-----'); var splittedtext = text.split('-----');
var data = { var result = {
openpgp: base64.decode( data: base64.decode(
splittedtext[2] splittedtext[2]
.split('\n\n')[1] .split('\n\n')[1]
.split("\n=")[0] .split("\n=")[0]
@ -214,18 +214,18 @@ function dearmor(text) {
type: type type: type
}; };
if (verifyCheckSum(data.openpgp, if (verifyCheckSum(result.data,
splittedtext[2] splittedtext[2]
.split('\n\n')[1] .split('\n\n')[1]
.split("\n=")[1] .split("\n=")[1]
.split('\n')[0])) .split('\n')[0]))
return data; return result;
else { else {
util.print_error("Ascii armor integrity check on message failed: '" + splittedtext[2] util.print_error("Ascii armor integrity check on message failed: '" + splittedtext[2]
.split('\n\n')[1] .split('\n\n')[1]
.split("\n=")[1] .split("\n=")[1]
.split('\n')[0] + "' should be '" + getCheckSum(data)) + "'"; .split('\n')[0] + "' should be '" + getCheckSum(result.data)) + "'";
return false; return false;
} }
} else { } else {
@ -235,13 +235,13 @@ function dearmor(text) {
text: splittedtext[2] text: splittedtext[2]
.replace(/\n- /g, "\n") .replace(/\n- /g, "\n")
.split("\n\n")[1], .split("\n\n")[1],
openpgp: base64.decode(splittedtext[4] data: base64.decode(splittedtext[4]
.split("\n\n")[1] .split("\n\n")[1]
.split("\n=")[0]), .split("\n=")[0]),
type: type type: type
}; };
if (verifyCheckSum(result.openpgp, splittedtext[4] if (verifyCheckSum(result.data, splittedtext[4]
.split("\n\n")[1] .split("\n\n")[1]
.split("\n=")[1])) .split("\n=")[1]))
@ -257,56 +257,57 @@ function dearmor(text) {
/** /**
* Armor an OpenPGP binary packet block * Armor an OpenPGP binary packet block
* @param {Integer} messagetype type of the message * @param {Integer} messagetype type of the message
* @param data * @param body
* @param {Integer} partindex * @param {Integer} partindex
* @param {Integer} parttotal * @param {Integer} parttotal
* @returns {String} Armored text * @returns {String} Armored text
*/ */
function armor(messagetype, data, partindex, parttotal) { function armor(messagetype, body, partindex, parttotal) {
var result = ""; var result = "";
switch (messagetype) { switch (messagetype) {
case enums.armor.multipart_section: case enums.armor.multipart_section:
result += "-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"; result += "-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data); result += base64.encode(body);
result += "\r\n=" + getCheckSum(data) + "\r\n"; result += "\r\n=" + getCheckSum(body) + "\r\n";
result += "-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"; result += "-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n";
break; break;
case enums.armor.mutlipart_last: case enums.armor.mutlipart_last:
result += "-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n"; result += "-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data); result += base64.encode(body);
result += "\r\n=" + getCheckSum(data) + "\r\n"; result += "\r\n=" + getCheckSum(body) + "\r\n";
result += "-----END PGP MESSAGE, PART " + partindex + "-----\r\n"; result += "-----END PGP MESSAGE, PART " + partindex + "-----\r\n";
break; break;
case enums.armor.signed: case enums.armor.signed:
result += "\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: " + data.hash + "\r\n\r\n"; result += "\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n";
result += data.text.replace(/\n-/g, "\n- -"); result += "Hash: " + body.hash + "\r\n\r\n";
result += body.text.replace(/\n-/g, "\n- -");
result += "\r\n-----BEGIN PGP SIGNATURE-----\r\n"; result += "\r\n-----BEGIN PGP SIGNATURE-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data.openpgp); result += base64.encode(body.data);
result += "\r\n=" + getCheckSum(data.openpgp) + "\r\n"; result += "\r\n=" + getCheckSum(body.data) + "\r\n";
result += "-----END PGP SIGNATURE-----\r\n"; result += "-----END PGP SIGNATURE-----\r\n";
break; break;
case enums.armor.message: case enums.armor.message:
result += "-----BEGIN PGP MESSAGE-----\r\n"; result += "-----BEGIN PGP MESSAGE-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data); result += base64.encode(body);
result += "\r\n=" + getCheckSum(data) + "\r\n"; result += "\r\n=" + getCheckSum(body) + "\r\n";
result += "-----END PGP MESSAGE-----\r\n"; result += "-----END PGP MESSAGE-----\r\n";
break; break;
case enums.armor.public_key: case enums.armor.public_key:
result += "-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n"; result += "-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data); result += base64.encode(body);
result += "\r\n=" + getCheckSum(data) + "\r\n"; result += "\r\n=" + getCheckSum(body) + "\r\n";
result += "-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n"; result += "-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n";
break; break;
case enums.armor.private_key: case enums.armor.private_key:
result += "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n"; result += "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n";
result += armor_addheader(); result += armor_addheader();
result += base64.encode(data); result += base64.encode(body);
result += "\r\n=" + getCheckSum(data) + "\r\n"; result += "\r\n=" + getCheckSum(body) + "\r\n";
result += "-----END PGP PRIVATE KEY BLOCK-----\r\n"; result += "-----END PGP PRIVATE KEY BLOCK-----\r\n";
break; break;
} }

View File

@ -283,7 +283,7 @@ var config = require('./config');
key.readArmored = function(armoredText) { key.readArmored = function(armoredText) {
//TODO how do we want to handle bad text? Exception throwing //TODO how do we want to handle bad text? Exception throwing
//TODO don't accept non-key armored texts //TODO don't accept non-key armored texts
var input = armor.decode(armoredText).openpgp; var input = armor.decode(armoredText).data;
var packetlist = new packet.list(); var packetlist = new packet.list();
packetlist.read(input); packetlist.read(input);
var newKey = new key(packetlist); var newKey = new key(packetlist);

View File

@ -150,7 +150,7 @@ var keyring = function() {
function importPacketlist(armored) { function importPacketlist(armored) {
this.armoredPacketlists.push(armored); this.armoredPacketlists.push(armored);
var dearmored = armor.decode(armored.replace(/\r/g, '')).openpgp; var dearmored = armor.decode(armored.replace(/\r/g, '')).data;
packetlist = new packet.list(); packetlist = new packet.list();
packetlist.read(dearmored); packetlist.read(dearmored);

View File

@ -336,7 +336,7 @@ function message(packetlist) {
message.readArmored = function(armoredText) { message.readArmored = function(armoredText) {
//TODO how do we want to handle bad text? Exception throwing //TODO how do we want to handle bad text? Exception throwing
//TODO don't accept non-message armored texts //TODO don't accept non-message armored texts
var input = armor.decode(armoredText).openpgp; var input = armor.decode(armoredText).data;
var packetlist = new packet.list(); var packetlist = new packet.list();
packetlist.read(input); packetlist.read(input);
var newMessage = new message(packetlist); var newMessage = new message(packetlist);

View File

@ -103,7 +103,7 @@ unit.register("Packet testing", function() {
var msgbytes = openpgp.armor.decode(msg).openpgp; var msgbytes = openpgp.armor.decode(msg).data;
var parsed = new openpgp.packet.list(); var parsed = new openpgp.packet.list();
parsed.read(msgbytes); parsed.read(msgbytes);
@ -175,7 +175,7 @@ unit.register("Packet testing", function() {
'-----END PGP PRIVATE KEY BLOCK-----'; '-----END PGP PRIVATE KEY BLOCK-----';
key = new openpgp.packet.list(); key = new openpgp.packet.list();
key.read(openpgp.armor.decode(armored_key).openpgp); key.read(openpgp.armor.decode(armored_key).data);
key = key[0]; key = key[0];
var enc = new openpgp.packet.public_key_encrypted_session_key(), var enc = new openpgp.packet.public_key_encrypted_session_key(),
@ -243,11 +243,11 @@ unit.register("Packet testing", function() {
var key = new openpgp.packet.list(); var key = new openpgp.packet.list();
key.read(openpgp.armor.decode(armored_key).openpgp); key.read(openpgp.armor.decode(armored_key).data);
key = key[3]; key = key[3];
var msg = new openpgp.packet.list(); var msg = new openpgp.packet.list();
msg.read(openpgp.armor.decode(armored_msg).openpgp); msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key); msg[0].decrypt(key);
msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey); msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey);
@ -305,12 +305,12 @@ unit.register("Packet testing", function() {
'-----END PGP MESSAGE-----'; '-----END PGP MESSAGE-----';
var key = new openpgp.packet.list(); var key = new openpgp.packet.list();
key.read(openpgp.armor.decode(armored_key).openpgp); key.read(openpgp.armor.decode(armored_key).data);
key = key[3]; key = key[3];
key.decrypt('test'); key.decrypt('test');
var msg = new openpgp.packet.list(); var msg = new openpgp.packet.list();
msg.read(openpgp.armor.decode(armored_msg).openpgp); msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key); msg[0].decrypt(key);
msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey); msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey);
@ -325,7 +325,7 @@ unit.register("Packet testing", function() {
var key = new openpgp.packet.list(); var key = new openpgp.packet.list();
key.read(openpgp.armor.decode(armored_key).openpgp); key.read(openpgp.armor.decode(armored_key).data);
var verified = key[2].verify(key[0], var verified = key[2].verify(key[0],
@ -362,11 +362,11 @@ unit.register("Packet testing", function() {
'-----END PGP MESSAGE-----' '-----END PGP MESSAGE-----'
var key = new openpgp.packet.list(); var key = new openpgp.packet.list();
key.read(openpgp.armor.decode(armored_key).openpgp); key.read(openpgp.armor.decode(armored_key).data);
key[3].decrypt('test') key[3].decrypt('test')
var msg = new openpgp.packet.list(); var msg = new openpgp.packet.list();
msg.read(openpgp.armor.decode(armored_msg).openpgp); msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key[3]); msg[0].decrypt(key[3]);

File diff suppressed because one or more lines are too long