Merge pull request #137 from Robert-Nelson/devel-signature-fixes

Merge signature changes from master
This commit is contained in:
Thomas Oberndörfer 2013-12-08 02:01:49 -08:00
commit 5d6e1a9506
20 changed files with 666 additions and 595 deletions

View File

@ -1,4 +1,4 @@
[![Build Status](https://secure.travis-ci.org/openpgpjs/openpgpjs.png)](http://travis-ci.org/openpgpjs/openpgpjs)
[![Build Status](https://secure.travis-ci.org/openpgpjs/openpgpjs.png?branch=master,devel)](http://travis-ci.org/openpgpjs/openpgpjs)
# What is OpenPGP.js?
[OpenPGP.js](http://openpgpjs.org/) is a Javascript implementation of the OpenPGP protocol. This is defined in [RFC 4880](http://tools.ietf.org/html/rfc4880).

File diff suppressed because one or more lines are too long

View File

@ -33,7 +33,7 @@ function CleartextMessage(text, packetlist) {
if (!(this instanceof CleartextMessage)) {
return new CleartextMessage(packetlist);
}
this.text = text;
this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n");
this.packets = packetlist || new packet.list();
}
@ -56,6 +56,8 @@ CleartextMessage.prototype.getSigningKeyIds = function() {
*/
CleartextMessage.prototype.sign = function(privateKeys) {
var packetlist = new packet.list();
var literalDataPacket = new packet.literal();
literalDataPacket.setBytes(this.text, enums.read(enums.literal, enums.literal.utf8));
for (var i = 0; i < privateKeys.length; i++) {
var signaturePacket = new packet.signature();
signaturePacket.signatureType = enums.signature.text;
@ -63,9 +65,6 @@ CleartextMessage.prototype.sign = function(privateKeys) {
var signingKeyPacket = privateKeys[i].getSigningKeyPacket();
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
if (!signingKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.');
// use literal data packet to convert to canonical <CR><LF> line endings
var literalDataPacket = new packet.literal();
literalDataPacket.setBytes(this.text, enums.read(enums.literal, enums.literal.text));
signaturePacket.sign(signingKeyPacket, literalDataPacket);
packetlist.push(signaturePacket);
}
@ -81,15 +80,14 @@ CleartextMessage.prototype.verify = function(publicKeys) {
var result = [];
var signatureList = this.packets.filterByTag(enums.packet.signature);
var that = this;
var literalDataPacket = new packet.literal();
literalDataPacket.setBytes(that.text, enums.read(enums.literal, enums.literal.utf8));
publicKeys.forEach(function(pubKey) {
for (var i = 0; i < signatureList.length; i++) {
var publicKeyPacket = pubKey.getPublicKeyPacket([signatureList[i].issuerKeyId]);
if (publicKeyPacket) {
var verifiedSig = {};
verifiedSig.keyid = signatureList[i].issuerKeyId;
// use literal data packet to convert to canonical <CR><LF> line endings
var literalDataPacket = new packet.literal();
literalDataPacket.setBytes(that.text, enums.read(enums.literal, enums.literal.text));
verifiedSig.status = signatureList[i].verify(publicKeyPacket, literalDataPacket);
result.push(verifiedSig);
break;

View File

@ -353,9 +353,6 @@ JXG.Util.Unzip = function(barray) {
X = currentTree[xtreepos];
}
}
if (debug)
document.write("ret3");
return -1;
};
function DeflateLoop() {
@ -797,7 +794,7 @@ JXG.Util.Unzip = function(barray) {
CRC = 0xffffffff;
SIZE = 0;
if (size = 0 && fileOut.charAt(fileout.length - 1) == "/") {
if (size == 0 && fileOut.charAt(fileout.length - 1) == "/") {
//skipdir
if (debug)
alert("skipdir");

View File

@ -31,18 +31,21 @@ var config = require('../config');
* null = unknown
*/
function get_type(text) {
var splittedtext = text.split('-----');
var reHeader = /^-----([^-]+)-----$\n/m;
var header = text.match(reHeader);
// BEGIN PGP MESSAGE, PART X/Y
// Used for multi-part messages, where the armor is split amongst Y
// parts, and this is the Xth part out of Y.
if (splittedtext[1].match(/BEGIN PGP MESSAGE, PART \d+\/\d+/)) {
if (header[1].match(/BEGIN PGP MESSAGE, PART \d+\/\d+/)) {
return enums.armor.multipart_section;
} else
// BEGIN PGP MESSAGE, PART X
// Used for multi-part messages, where this is the Xth part of an
// unspecified number of parts. Requires the MESSAGE-ID Armor
// Header to be used.
if (splittedtext[1].match(/BEGIN PGP MESSAGE, PART \d+/)) {
if (header[1].match(/BEGIN PGP MESSAGE, PART \d+/)) {
return enums.armor.multipart_last;
} else
@ -50,25 +53,25 @@ function get_type(text) {
// Used for detached signatures, OpenPGP/MIME signatures, and
// cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE
// for detached signatures.
if (splittedtext[1].match(/BEGIN PGP SIGNED MESSAGE/)) {
if (header[1].match(/BEGIN PGP SIGNED MESSAGE/)) {
return enums.armor.signed;
} else
// BEGIN PGP MESSAGE
// Used for signed, encrypted, or compressed files.
if (splittedtext[1].match(/BEGIN PGP MESSAGE/)) {
if (header[1].match(/BEGIN PGP MESSAGE/)) {
return enums.armor.message;
} else
// BEGIN PGP PUBLIC KEY BLOCK
// Used for armoring public keys.
if (splittedtext[1].match(/BEGIN PGP PUBLIC KEY BLOCK/)) {
if (header[1].match(/BEGIN PGP PUBLIC KEY BLOCK/)) {
return enums.armor.public_key;
} else
// BEGIN PGP PRIVATE KEY BLOCK
// Used for armoring private keys.
if (splittedtext[1].match(/BEGIN PGP PRIVATE KEY BLOCK/)) {
if (header[1].match(/BEGIN PGP PRIVATE KEY BLOCK/)) {
return enums.armor.private_key;
}
}
@ -108,7 +111,7 @@ function getCheckSum(data) {
}
/**
* Calculates the checksum over the given data and compares it with the
* Calculates the checksum over the given data and compares it with the
* given base64 encoded checksum
* @param {String} data Data to create a CRC-24 checksum for
* @param {String} checksum Base64 encoded checksum
@ -190,66 +193,109 @@ function createcrc24(input) {
}
/**
* DeArmor an OpenPGP armored message; verify the checksum and return
* Splits a message into two parts, the headers and the body. This is an internal function
* @param {String} text OpenPGP armored message part
* @returns {(Boolean|Object)} Either false in case of an error
* or an object with attribute "headers" containing the headers and
* and an attribute "body" containing the body.
*/
function split_headers(text) {
var reEmptyLine = /^[\t ]*\n/m;
var headers = "";
var body = text;
var matchResult = reEmptyLine.exec(text);
if (matchResult != null) {
headers = text.slice(0, matchResult.index);
body = text.slice(matchResult.index + matchResult[0].length);
}
return { headers: headers, body: body };
}
/**
* Splits a message into two parts, the body and the checksum. This is an internal function
* @param {String} text OpenPGP armored message part
* @returns {(Boolean|Object)} Either false in case of an error
* or an object with attribute "body" containing the body
* and an attribute "checksum" containing the checksum.
*/
function split_checksum(text) {
var reChecksumStart = /^=/m;
var body = text;
var checksum = "";
var matchResult = reChecksumStart.exec(text);
if (matchResult != null) {
body = text.slice(0, matchResult.index);
checksum = text.slice(matchResult.index + 1);
}
return { body: body, checksum: checksum };
}
/**
* DeArmor an OpenPGP armored message; verify the checksum and return
* the encoded bytes
* @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
* and an attribute "data" containing the bytes.
*/
function dearmor(text) {
var reSplit = /^-----[^-]+-----$\n/m;
text = text.replace(/\r/g, '');
var type = get_type(text);
var splittext = text.split(reSplit);
// IE has a bug in split with a re. If the pattern matches the beginning of the
// string it doesn't create an empty array element 0. So we need to detect this
// so we know the index of the data we are interested in.
var indexBase = 1;
var result, checksum;
if (text.search(reSplit) != splittext[0].length) {
indexBase = 0;
}
if (type != 2) {
var splittedtext = text.split('-----');
var msg = split_headers(splittext[indexBase].replace(/^- /mg, ''));
var msg_sum = split_checksum(msg.body);
var result = {
data: base64.decode(
splittedtext[2]
.split('\n\n')[1]
.split("\n=")[0]
.replace(/\n- /g, "\n")),
result = {
data: base64.decode(msg_sum.body),
type: type
};
if (verifyCheckSum(result.data,
splittedtext[2]
.split('\n\n')[1]
.split("\n=")[1]
.split('\n')[0]))
return result;
else {
util.print_error("Ascii armor integrity check on message failed: '" + splittedtext[2]
.split('\n\n')[1]
.split("\n=")[1]
.split('\n')[0] + "' should be '" + getCheckSum(result.data)) + "'";
return false;
}
checksum = msg_sum.checksum;
} else {
var splittedtext = text.split('-----');
var msg = split_headers(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
var sig = split_headers(splittext[indexBase + 1].replace(/^- /mg, ''));
var sig_sum = split_checksum(sig.body);
var result = {
text: splittedtext[2]
.replace(/\n- /g, "\n")
.split("\n\n")[1],
data: base64.decode(splittedtext[4]
.split("\n\n")[1]
.split("\n=")[0]),
result = {
text: msg.body.replace(/\n$/, '').replace(/\n/g, "\r\n"),
data: base64.decode(sig_sum.body),
type: type
};
if (verifyCheckSum(result.data, splittedtext[4]
.split("\n\n")[1]
.split("\n=")[1]))
checksum = sig_sum.checksum;
}
return result;
else {
util.print_error("Ascii armor integrity check on message failed");
return false;
}
if (!verifyCheckSum(result.data, checksum)) {
util.print_error("Ascii armor integrity check on message failed: '"
+ checksum
+ "' should be '"
+ getCheckSum(result) + "'");
return false;
} else {
return result;
}
}

View File

@ -288,4 +288,4 @@ function fromText(text) {
exports.Message = Message;
exports.readArmored = readArmored;
exports.fromText = fromText;
exports.fromText = fromText;

View File

@ -51,38 +51,19 @@ module.exports = function packet_literal() {
*/
this.setBytes = function(bytes, format) {
this.format = format;
switch (format) {
case 'utf8':
bytes = util.decode_utf8(bytes);
bytes = bytes.replace(/\r\n/g, '\n');
break;
case 'text':
bytes = bytes.replace(/\r\n/g, '\n');
break;
}
this.data = bytes;
this.data = format == 'utf8' ? util.decode_utf8(bytes) : bytes;
}
/**
* Get the byte sequence representing the literal packet data
* @returns {String} A sequence of bytes
*/
this.getBytes = function() {
var bytes = this.data;
switch (this.format) {
case 'utf8':
bytes = bytes.replace(/\n/g, '\r\n');
bytes = util.encode_utf8(bytes);
break;
case 'text':
bytes = bytes.replace(/\n/g, '\r\n');
break;
}
return bytes;
return this.format == 'utf8' ? util.encode_utf8(this.data) : this.data;
}
/**
* Parsing function for a literal data packet (tag 11).
*
@ -97,7 +78,7 @@ module.exports = function packet_literal() {
this.read = function(bytes) {
// - A one-octet field that describes how the data is formatted.
var format = enums.read(enums.literal, bytes[0].charCodeAt());
var format = enums.read(enums.literal, bytes.charCodeAt(0));
var filename_len = bytes.charCodeAt(1);
this.filename = util.decode_utf8(bytes.substr(2, filename_len));

View File

@ -39,9 +39,9 @@ function packet_marker() {
* @return {openpgp_packet_encrypteddata} Object representation
*/
this.read = function(bytes) {
if (bytes[0].charCodeAt() == 0x50 && // P
bytes[1].charCodeAt() == 0x47 && // G
bytes[2].charCodeAt() == 0x50) // P
if (bytes.charCodeAt(0) == 0x50 && // P
bytes.charCodeAt(1) == 0x47 && // G
bytes.charCodeAt(2) == 0x50) // P
return true;
// marker packet does not contain "PGP"
return false;

View File

@ -23,14 +23,14 @@ module.exports = {
readSimpleLength: function(bytes) {
var len = 0,
offset,
type = bytes[0].charCodeAt();
type = bytes.charCodeAt(0);
if (type < 192) {
len = bytes[0].charCodeAt();
len = bytes.charCodeAt(0);
offset = 1;
} else if (type < 255) {
len = ((bytes[0].charCodeAt() - 192) << 8) + (bytes[1].charCodeAt()) + 192;
len = ((bytes.charCodeAt(0) - 192) << 8) + (bytes.charCodeAt(1)) + 192;
offset = 2;
} else if (type == 255) {
len = util.readNumber(bytes.substr(1, 4));
@ -117,7 +117,7 @@ module.exports = {
*/
read: function(input, position, len) {
// some sanity checks
if (input == null || input.length <= position || input.substring(position).length < 2 || (input[position].charCodeAt() &
if (input == null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) &
0x80) == 0) {
util
.print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
@ -129,18 +129,18 @@ module.exports = {
var packet_length;
format = 0; // 0 = old format; 1 = new format
if ((input[mypos].charCodeAt() & 0x40) != 0) {
if ((input.charCodeAt(mypos) & 0x40) != 0) {
format = 1;
}
var packet_length_type;
if (format) {
// new format header
tag = input[mypos].charCodeAt() & 0x3F; // bit 5-0
tag = input.charCodeAt(mypos) & 0x3F; // bit 5-0
} else {
// old format header
tag = (input[mypos].charCodeAt() & 0x3F) >> 2; // bit 5-2
packet_length_type = input[mypos].charCodeAt() & 0x03; // bit 1-0
tag = (input.charCodeAt(mypos) & 0x3F) >> 2; // bit 5-2
packet_length_type = input.charCodeAt(mypos) & 0x03; // bit 1-0
}
// header octet parsing done
@ -157,18 +157,18 @@ module.exports = {
case 0:
// The packet has a one-octet length. The header is 2 octets
// long.
packet_length = input[mypos++].charCodeAt();
packet_length = input.charCodeAt(mypos++);
break;
case 1:
// The packet has a two-octet length. The header is 3 octets
// long.
packet_length = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt();
packet_length = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++);
break;
case 2:
// The packet has a four-octet length. The header is 5
// octets long.
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() <<
8) | input[mypos++].charCodeAt();
packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) <<
8) | input.charCodeAt(mypos++);
break;
default:
// 3 - The packet is of indeterminate length. The header is 1
@ -189,42 +189,42 @@ module.exports = {
{
// 4.2.2.1. One-Octet Lengths
if (input[mypos].charCodeAt() < 192) {
packet_length = input[mypos++].charCodeAt();
if (input.charCodeAt(mypos) < 192) {
packet_length = input.charCodeAt(mypos++);
util.print_debug("1 byte length:" + packet_length);
// 4.2.2.2. Two-Octet Lengths
} else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) {
packet_length = ((input[mypos++].charCodeAt() - 192) << 8) + (input[mypos++].charCodeAt()) + 192;
} else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) {
packet_length = ((input.charCodeAt(mypos++) - 192) << 8) + (input.charCodeAt(mypos++)) + 192;
util.print_debug("2 byte length:" + packet_length);
// 4.2.2.4. Partial Body Lengths
} else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) {
packet_length = 1 << (input[mypos++].charCodeAt() & 0x1F);
} else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) {
packet_length = 1 << (input.charCodeAt(mypos++) & 0x1F);
util.print_debug("4 byte length:" + packet_length);
// EEEK, we're reading the full data here...
var mypos2 = mypos + packet_length;
bodydata = input.substring(mypos, mypos + packet_length);
while (true) {
if (input[mypos2].charCodeAt() < 192) {
var tmplen = input[mypos2++].charCodeAt();
if (input.charCodeAt(mypos2) < 192) {
var tmplen = input.charCodeAt(mypos2++);
packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen;
break;
} else if (input[mypos2].charCodeAt() >= 192 && input[mypos2].charCodeAt() < 224) {
var tmplen = ((input[mypos2++].charCodeAt() - 192) << 8) + (input[mypos2++].charCodeAt()) + 192;
} else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) {
var tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192;
packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen;
break;
} else if (input[mypos2].charCodeAt() > 223 && input[mypos2].charCodeAt() < 255) {
var tmplen = 1 << (input[mypos2++].charCodeAt() & 0x1F);
} else if (input.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) {
var tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F);
packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen;
} else {
mypos2++;
var tmplen = (input[mypos2++].charCodeAt() << 24) | (input[mypos2++].charCodeAt() << 16) | (input[mypos2++]
.charCodeAt() << 8) | input[mypos2++].charCodeAt();
var tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input[mypos2++]
.charCodeAt() << 8) | input.charCodeAt(mypos2++);
bodydata += input.substring(mypos2, mypos2 + tmplen);
packet_length += tmplen;
mypos2 += tmplen;
@ -235,8 +235,8 @@ module.exports = {
// 4.2.2.3. Five-Octet Lengths
} else {
mypos++;
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() <<
8) | input[mypos++].charCodeAt();
packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) <<
8) | input.charCodeAt(mypos++);
}
}

View File

@ -53,14 +53,14 @@ module.exports = function packet_public_key() {
*/
this.readPublicKey = this.read = function(bytes) {
// A one-octet version number (3 or 4).
var version = bytes[0].charCodeAt();
var version = bytes.charCodeAt(0);
if (version == 4) {
// - A four-octet number denoting the time that the key was created.
this.created = util.readDate(bytes.substr(1, 4));
// - A one-octet number denoting the public-key algorithm of this key.
this.algorithm = enums.read(enums.publicKey, bytes[5].charCodeAt());
this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(5));
var mpicount = crypto.getPublicMpiCount(this.algorithm);
this.mpi = [];

View File

@ -61,9 +61,9 @@ module.exports = function packet_public_key_encrypted_session_key() {
*/
this.read = function(bytes) {
this.version = bytes[0].charCodeAt();
this.version = bytes.charCodeAt(0);
this.publicKeyId.read(bytes.substr(1));
this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes[9].charCodeAt());
this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
var i = 10;

View File

@ -114,7 +114,7 @@ function packet_secret_key() {
// indicates that the secret-key data is not encrypted. 255 or 254
// indicates that a string-to-key specifier is being given. Any
// other value is a symmetric-key encryption algorithm identifier.
var isEncrypted = bytes[0].charCodeAt();
var isEncrypted = bytes.charCodeAt(0);
if (isEncrypted) {
this.encrypted = bytes;
@ -199,12 +199,12 @@ function packet_secret_key() {
symmetric,
key;
var s2k_usage = this.encrypted[i++].charCodeAt();
var s2k_usage = this.encrypted.charCodeAt(i++);
// - [Optional] If string-to-key usage octet was 255 or 254, a one-
// octet symmetric encryption algorithm.
if (s2k_usage == 255 || s2k_usage == 254) {
symmetric = this.encrypted[i++].charCodeAt();
symmetric = this.encrypted.charCodeAt(i++);
symmetric = enums.read(enums.symmetric, symmetric);
// - [Optional] If string-to-key usage octet was 255 or 254, a

View File

@ -86,19 +86,19 @@ module.exports = function packet_signature() {
this.read = function(bytes) {
var i = 0;
this.version = bytes[i++].charCodeAt();
this.version = bytes.charCodeAt(i++);
// switch on version (3 and 4)
switch (this.version) {
case 3:
// One-octet length of following hashed material. MUST be 5.
if (bytes[i++].charCodeAt() != 5)
if (bytes.charCodeAt(i++) != 5)
util.print_debug("openpgp.packet.signature.js\n" +
'invalid One-octet length of following hashed material.' +
'MUST be 5. @:' + (i - 1));
var sigpos = i;
// One-octet signature type.
this.signatureType = bytes[i++].charCodeAt();
this.signatureType = bytes.charCodeAt(i++);
// Four-octet creation time.
this.created = util.readDate(bytes.substr(i, 4));
@ -112,15 +112,15 @@ module.exports = function packet_signature() {
i += 8;
// One-octet public-key algorithm.
this.publicKeyAlgorithm = bytes[i++].charCodeAt();
this.publicKeyAlgorithm = bytes.charCodeAt(i++);
// One-octet hash algorithm.
this.hashAlgorithm = bytes[i++].charCodeAt();
this.hashAlgorithm = bytes.charCodeAt(i++);
break;
case 4:
this.signatureType = bytes[i++].charCodeAt();
this.publicKeyAlgorithm = bytes[i++].charCodeAt();
this.hashAlgorithm = bytes[i++].charCodeAt();
this.signatureType = bytes.charCodeAt(i++);
this.publicKeyAlgorithm = bytes.charCodeAt(i++);
this.hashAlgorithm = bytes.charCodeAt(i++);
function subpackets(bytes) {
// Two-octet scalar octet count for following subpacket data.
@ -347,12 +347,12 @@ module.exports = function packet_signature() {
this[prop] = [];
for (var i = 0; i < bytes.length; i++) {
this[prop].push(bytes[i].charCodeAt());
this[prop].push(bytes.charCodeAt(i));
}
}
// The leftwost bit denotes a "critical" packet, but we ignore it.
var type = bytes[mypos++].charCodeAt() & 0x7F;
var type = bytes.charCodeAt(mypos++) & 0x7F;
// subpacket type
switch (type) {
@ -370,12 +370,12 @@ module.exports = function packet_signature() {
break;
case 4:
// Exportable Certification
this.exportable = bytes[mypos++].charCodeAt() == 1;
this.exportable = bytes.charCodeAt(mypos++) == 1;
break;
case 5:
// Trust Signature
this.trustLevel = bytes[mypos++].charCodeAt();
this.trustAmount = bytes[mypos++].charCodeAt();
this.trustLevel = bytes.charCodeAt(mypos++);
this.trustAmount = bytes.charCodeAt(mypos++);
break;
case 6:
// Regular Expression
@ -383,7 +383,7 @@ module.exports = function packet_signature() {
break;
case 7:
// Revocable
this.revocable = bytes[mypos++].charCodeAt() == 1;
this.revocable = bytes.charCodeAt(mypos++) == 1;
break;
case 9:
// Key Expiration Time
@ -398,7 +398,7 @@ module.exports = function packet_signature() {
this.preferredSymmetricAlgorithms = [];
while (mypos != bytes.length) {
this.preferredSymmetricAlgorithms.push(bytes[mypos++].charCodeAt());
this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
}
break;
@ -407,8 +407,8 @@ module.exports = function packet_signature() {
// (1 octet of class, 1 octet of public-key algorithm ID, 20
// octets of
// fingerprint)
this.revocationKeyClass = bytes[mypos++].charCodeAt();
this.revocationKeyAlgorithm = bytes[mypos++].charCodeAt();
this.revocationKeyClass = bytes.charCodeAt(mypos++);
this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
this.revocationKeyFingerprint = bytes.substr(mypos, 20);
break;
@ -420,7 +420,7 @@ module.exports = function packet_signature() {
case 20:
// Notation Data
// We don't know how to handle anything but a text flagged data.
if (bytes[mypos].charCodeAt() == 0x80) {
if (bytes.charCodeAt(mypos) == 0x80) {
// We extract key/value tuple from the byte stream.
mypos += 4;
@ -470,7 +470,7 @@ module.exports = function packet_signature() {
break;
case 29:
// Reason for Revocation
this.reasonForRevocationFlag = bytes[mypos++].charCodeAt();
this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
this.reasonForRevocationString = bytes.substr(mypos);
break;
case 30:
@ -480,8 +480,8 @@ module.exports = function packet_signature() {
case 31:
// Signature Target
// (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
this.signatureTargetPublicKeyAlgorithm = bytes[mypos++].charCodeAt();
this.signatureTargetHashAlgorithm = bytes[mypos++].charCodeAt();
this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
@ -506,10 +506,11 @@ module.exports = function packet_signature() {
switch (type) {
case t.binary:
// conversion to CRLF line endings done in literal data packet
case t.text:
return data.getBytes();
case t.text:
return data.getBytes().replace(/\r/g, '').replace(/\n/g, "\r\n");
case t.standalone:
return '';

View File

@ -45,7 +45,7 @@ module.exports = function packet_sym_encrypted_integrity_protected() {
this.read = function(bytes) {
// - A one-octet version number. The only currently defined value is
// 1.
var version = bytes[0].charCodeAt();
var version = bytes.charCodeAt(0);
if (version != 1) {
throw new Error('Invalid packet version.');

View File

@ -54,10 +54,10 @@ module.exports = function packet_sym_encrypted_session_key() {
*/
this.read = function(bytes) {
// A one-octet version number. The only currently defined version is 4.
this.version = bytes[0].charCodeAt();
this.version = bytes.charCodeAt(0);
// A one-octet number describing the symmetric algorithm used.
var algo = enums.read(enums.symmetric, bytes[1].charCodeAt());
var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
// A string-to-key (S2K) specifier, length as defined above.
var s2klength = this.s2k.read(bytes.substr(2));

View File

@ -47,7 +47,7 @@ module.exports = function mpi() {
* @return {openpgp_type_mpi} Object representation
*/
this.read = function(bytes) {
var bits = (bytes[0].charCodeAt() << 8) | bytes[1].charCodeAt();
var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
// Additional rules:
//

View File

@ -53,8 +53,8 @@ module.exports = function s2k() {
*/
this.read = function(bytes) {
var i = 0;
this.type = enums.read(enums.s2k, bytes[i++].charCodeAt());
this.algorithm = enums.read(enums.hash, bytes[i++].charCodeAt());
this.type = enums.read(enums.s2k, bytes.charCodeAt(i++));
this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++));
switch (this.type) {
case 'simple':
@ -70,13 +70,13 @@ module.exports = function s2k() {
i += 8;
// Octet 10: count, a one-octet, coded value
this.c = bytes[i++].charCodeAt();
this.c = bytes.charCodeAt(i++);
break;
case 'gnu':
if (bytes.substr(i, 3) == "GNU") {
i += 3; // GNU
var gnuExtType = 1000 + bytes[i++].charCodeAt();
var gnuExtType = 1000 + bytes.charCodeAt(i++);
if (gnuExtType == 1001) {
this.type = gnuExtType;
// GnuPG extension mode 1001 -- don't write secret key at all

View File

@ -24,7 +24,7 @@ var Util = function() {
for (var i = 0; i < bytes.length; i++) {
n <<= 8;
n += bytes[i].charCodeAt();
n += bytes.charCodeAt(i);
}
return n;
@ -88,7 +88,7 @@ var Util = function() {
var c = 0;
var h;
while (c < e) {
h = str[c++].charCodeAt().toString(16);
h = str.charCodeAt(c++).toString(16);
while (h.length < 2) h = "0" + h;
r.push("" + h);
}

View File

@ -310,7 +310,7 @@ var pub_key_arm3 =
'=nx90',
'-----END PGP MESSAGE-----'].join('\n');
var plaintext = 'short message\nnext line\n한국어/조선말\n\n';
var plaintext = 'short message\r\nnext line\r\n한국어/조선말\r\n\r\n';
var esMsg = openpgp.message.readArmored(msg_armor);
var pubKey = openpgp.key.readArmored(pub_key_arm2);
var privKey = openpgp.key.readArmored(priv_key_arm2);
@ -394,7 +394,7 @@ var pub_key_arm3 =
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey2, pubKey3], csMsg);
verified = verified && cleartextSig.text == plaintext;
verified = verified && cleartextSig.text == plaintext.replace(/\r/g,'').replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");
verified = verified && cleartextSig.signatures[0].status && cleartextSig.signatures[1].status;
@ -412,7 +412,7 @@ var pub_key_arm3 =
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey], csMsg);
var verified = cleartextSig.text == plaintext;
var verified = cleartextSig.text == plaintext.replace(/\r/g,'').replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");
verified = verified && cleartextSig.signatures[0].status;

File diff suppressed because one or more lines are too long