Array indexing on strings is nonstandard and doesn't work on IE

This commit is contained in:
Robert Nelson 2013-12-05 20:03:08 -08:00
parent f6176ed484
commit f0c2427895
12 changed files with 70 additions and 70 deletions

View File

@ -97,7 +97,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);

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