From e4e69749a68f3d117500ff9c62383873badcdd54 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Fri, 29 Nov 2013 16:10:56 -0800 Subject: [PATCH] Don't use array indexing on strings it is nonstandard and doesn't work on IE --- src/openpgp.js | 8 +- ....packet.encryptedintegrityprotecteddata.js | 2 +- .../openpgp.packet.encryptedsessionkey.js | 4 +- src/packet/openpgp.packet.js | 78 ++++++------- src/packet/openpgp.packet.keymaterial.js | 34 +++--- src/packet/openpgp.packet.marker.js | 6 +- src/packet/openpgp.packet.signature.js | 108 +++++++++--------- src/packet/openpgp.packet.userattribute.js | 20 ++-- src/packet/openpgp.packet.userid.js | 8 +- src/type/openpgp.type.mpi.js | 2 +- src/type/openpgp.type.s2k.js | 14 +-- src/util/util.js | 2 +- 12 files changed, 140 insertions(+), 146 deletions(-) diff --git a/src/openpgp.js b/src/openpgp.js index 53c4a992..6774ae42 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -60,14 +60,14 @@ function _openpgp () { while (mypos != input.length) { var first_packet = openpgp_packet.read_packet(input, mypos, l); // public key parser - if (input[mypos].charCodeAt() == 0x99 || first_packet.tagType == 6) { + if (input.charCodeAt(mypos) == 0x99 || first_packet.tagType == 6) { publicKeys[publicKeyCount] = new openpgp_msg_publickey(); publicKeys[publicKeyCount].header = input.substring(mypos,mypos+3); - if (input[mypos].charCodeAt() == 0x99) { + if (input.charCodeAt(mypos) == 0x99) { // parse the length and read a tag6 packet mypos++; - var l = (input[mypos++].charCodeAt() << 8) - | input[mypos++].charCodeAt(); + var l = (input.charCodeAt(mypos++) << 8) + | input.charCodeAt(mypos++); publicKeys[publicKeyCount].publicKeyPacket = new openpgp_packet_keymaterial(); publicKeys[publicKeyCount].publicKeyPacket.header = publicKeys[publicKeyCount].header; publicKeys[publicKeyCount].publicKeyPacket.read_tag6(input, mypos, l); diff --git a/src/packet/openpgp.packet.encryptedintegrityprotecteddata.js b/src/packet/openpgp.packet.encryptedintegrityprotecteddata.js index c1bcdca5..f823f42c 100644 --- a/src/packet/openpgp.packet.encryptedintegrityprotecteddata.js +++ b/src/packet/openpgp.packet.encryptedintegrityprotecteddata.js @@ -49,7 +49,7 @@ function openpgp_packet_encryptedintegrityprotecteddata() { this.packetLength = len; // - A one-octet version number. The only currently defined value is // 1. - this.version = input[position].charCodeAt(); + this.version = input.charCodeAt(position); if (this.version != 1) { util .print_error('openpgp.packet.encryptedintegrityprotecteddata.js\nunknown encrypted integrity protected data packet version: ' diff --git a/src/packet/openpgp.packet.encryptedsessionkey.js b/src/packet/openpgp.packet.encryptedsessionkey.js index 24a4961c..e8d3817a 100644 --- a/src/packet/openpgp.packet.encryptedsessionkey.js +++ b/src/packet/openpgp.packet.encryptedsessionkey.js @@ -52,11 +52,11 @@ function openpgp_packet_encryptedsessionkey() { return null; } - this.version = input[mypos++].charCodeAt(); + this.version = input.charCodeAt(mypos++); this.keyId = new openpgp_type_keyid(); this.keyId.read_packet(input, mypos); mypos += 8; - this.publicKeyAlgorithmUsed = input[mypos++].charCodeAt(); + this.publicKeyAlgorithmUsed = input.charCodeAt(mypos++); switch (this.publicKeyAlgorithmUsed) { case 1: diff --git a/src/packet/openpgp.packet.js b/src/packet/openpgp.packet.js index cefb838e..840e9ef2 100644 --- a/src/packet/openpgp.packet.js +++ b/src/packet/openpgp.packet.js @@ -106,7 +106,7 @@ function _openpgp_packet() { // some sanity checks if (input == null || input.length <= position || input.substring(position).length < 2 - || (input[position].charCodeAt() & 0x80) == 0) { + || (input.charCodeAt(position) & 0x80) == 0) { util .print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format."); return null; @@ -116,18 +116,18 @@ function _openpgp_packet() { var format = -1; 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 @@ -143,19 +143,19 @@ function _openpgp_packet() { switch (packet_length_type) { 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 @@ -176,50 +176,50 @@ function _openpgp_packet() { { // 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.charCodeAt(mypos2++) << 8) + | input.charCodeAt(mypos2++); bodydata += input.substring(mypos2, mypos2 + tmplen); packet_length += tmplen; mypos2 += tmplen; @@ -230,10 +230,10 @@ function _openpgp_packet() { // 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++); } } @@ -249,7 +249,7 @@ function _openpgp_packet() { // alert('tag type: '+this.tag+' length: '+packet_length); var version = 1; // (old format; 2= new format) - // if (input[mypos++].charCodeAt() > 15) + // if (input.charCodeAt(mypos++) > 15) // version = 2; switch (tag) { diff --git a/src/packet/openpgp.packet.keymaterial.js b/src/packet/openpgp.packet.keymaterial.js index b0357bba..f553773e 100644 --- a/src/packet/openpgp.packet.keymaterial.js +++ b/src/packet/openpgp.packet.keymaterial.js @@ -125,20 +125,20 @@ function openpgp_packet_keymaterial() { function read_pub_key(input, position, len) { var mypos = position; // A one-octet version number (3 or 4). - this.version = input[mypos++].charCodeAt(); + this.version = input.charCodeAt(mypos++); if (this.version == 3) { // A four-octet number denoting the time that the key was created. - this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | - (input[mypos++].charCodeAt() << 16) | - (input[mypos++].charCodeAt() << 8) | - (input[mypos++].charCodeAt()))*1000); + this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) | + (input.charCodeAt(mypos++) << 16) | + (input.charCodeAt(mypos++) << 8) | + (input.charCodeAt(mypos++)))*1000); // - A two-octet number denoting the time in days that this key is // valid. If this number is zero, then it does not expire. - this.expiration = (input[mypos++].charCodeAt() << 8) & input[mypos++].charCodeAt(); + this.expiration = (input.charCodeAt(mypos++) << 8) & input.charCodeAt(mypos++); // - A one-octet number denoting the public-key algorithm of this key. - this.publicKeyAlgorithm = input[mypos++].charCodeAt(); + this.publicKeyAlgorithm = input.charCodeAt(mypos++); var mpicount = 0; // - A series of multiprecision integers comprising the key material: // Algorithm-Specific Fields for RSA public keys: @@ -174,13 +174,13 @@ function openpgp_packet_keymaterial() { this.packetLength = mypos-position; } else if (this.version == 4) { // - A four-octet number denoting the time that the key was created. - this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | - (input[mypos++].charCodeAt() << 16) | - (input[mypos++].charCodeAt() << 8) | - (input[mypos++].charCodeAt()))*1000); + this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) | + (input.charCodeAt(mypos++) << 16) | + (input.charCodeAt(mypos++) << 8) | + (input.charCodeAt(mypos++)))*1000); // - A one-octet number denoting the public-key algorithm of this key. - this.publicKeyAlgorithm = input[mypos++].charCodeAt(); + this.publicKeyAlgorithm = input.charCodeAt(mypos++); var mpicount = 0; // - A series of multiprecision integers comprising the key material: // Algorithm-Specific Fields for RSA public keys: @@ -236,7 +236,7 @@ function openpgp_packet_keymaterial() { // - A Public-Key or Public-Subkey packet, as described above. this.publicKey = new openpgp_packet_keymaterial(); if (this.publicKey.read_pub_key(input,position, len) == null) { - util.print_error("openpgp.packet.keymaterial.js\n"+"Failed reading public key portion of a private key: "+input[position].charCodeAt()+" "+position+" "+len+"\n Aborting here..."); + util.print_error("openpgp.packet.keymaterial.js\n"+"Failed reading public key portion of a private key: "+input.charCodeAt(position)+" "+position+" "+len+"\n Aborting here..."); return null; } this.publicKey.header = openpgp_packet.write_old_packet_header(6,this.publicKey.packetLength); @@ -248,7 +248,7 @@ function openpgp_packet_keymaterial() { // 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. - this.s2kUsageConventions = input[mypos++].charCodeAt(); + this.s2kUsageConventions = input.charCodeAt(mypos++); if (this.s2kUsageConventions == 0) this.hasUnencryptedSecretKeyData = true; @@ -256,7 +256,7 @@ function openpgp_packet_keymaterial() { // - [Optional] If string-to-key usage octet was 255 or 254, a one- // octet symmetric encryption algorithm. if (this.s2kUsageConventions == 255 || this.s2kUsageConventions == 254) { - this.symmetricEncryptionAlgorithm = input[mypos++].charCodeAt(); + this.symmetricEncryptionAlgorithm = input.charCodeAt(mypos++); } // - [Optional] If string-to-key usage octet was 255 or 254, a @@ -354,8 +354,8 @@ function openpgp_packet_keymaterial() { } // checksum because s2k usage convention is 0 this.checksum = new Array(); - this.checksum[0] = input[mypos++].charCodeAt(); - this.checksum[1] = input[mypos++].charCodeAt(); + this.checksum[0] = input.charCodeAt(mypos++); + this.checksum[1] = input.charCodeAt(mypos++); } return this; } diff --git a/src/packet/openpgp.packet.marker.js b/src/packet/openpgp.packet.marker.js index 848f746a..a9d6bf87 100644 --- a/src/packet/openpgp.packet.marker.js +++ b/src/packet/openpgp.packet.marker.js @@ -41,9 +41,9 @@ function openpgp_packet_marker() { */ function read_packet(input, position, len) { this.packetLength = 3; - if (input[position].charCodeAt() == 0x50 && // P - input[position + 1].charCodeAt() == 0x47 && // G - input[position + 2].charCodeAt() == 0x50) // P + if (input.charCodeAt(position) == 0x50 && // P + input.charCodeAt(position + 1) == 0x47 && // G + input.charCodeAt(position + 2) == 0x50) // P return this; // marker packet does not contain "PGP" return null; diff --git a/src/packet/openpgp.packet.signature.js b/src/packet/openpgp.packet.signature.js index 7f19e3a5..32eb465d 100644 --- a/src/packet/openpgp.packet.signature.js +++ b/src/packet/openpgp.packet.signature.js @@ -84,21 +84,21 @@ function openpgp_packet_signature() { var mypos = position; this.packetLength = len; // alert('starting parsing signature: '+position+' '+this.packetLength); - this.version = input[mypos++].charCodeAt(); + this.version = input.charCodeAt(mypos++); // switch on version (3 and 4) switch (this.version) { case 3: // One-octet length of following hashed material. MUST be 5. - if (input[mypos++].charCodeAt() != 5) + if (input.charCodeAt(mypos++) != 5) util.print_debug("openpgp.packet.signature.js\n"+'invalid One-octet length of following hashed material. MUST be 5. @:'+(mypos-1)); var sigpos = mypos; // One-octet signature type. - this.signatureType = input[mypos++].charCodeAt(); + this.signatureType = input.charCodeAt(mypos++); // Four-octet creation time. - this.creationTime = new Date(((input[mypos++].charCodeAt()) << 24 | - (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) | - input[mypos++].charCodeAt())* 1000); + this.creationTime = new Date(((input.charCodeAt(mypos++)) << 24 | + (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8) | + input.charCodeAt(mypos++))* 1000); // storing data appended to data which gets verified this.signatureData = input.substring(position, mypos); @@ -108,13 +108,13 @@ function openpgp_packet_signature() { mypos += 8; // One-octet public-key algorithm. - this.publicKeyAlgorithm = input[mypos++].charCodeAt(); + this.publicKeyAlgorithm = input.charCodeAt(mypos++); // One-octet hash algorithm. - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.hashAlgorithm = input.charCodeAt(mypos++); // Two-octet field holding left 16 bits of signed hash value. - this.signedHashValue = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); + this.signedHashValue = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++); var mpicount = 0; // Algorithm-Specific Fields for RSA signatures: // - multiprecision integer (MPI) of RSA signature value m**d mod n. @@ -138,13 +138,13 @@ function openpgp_packet_signature() { } break; case 4: - this.signatureType = input[mypos++].charCodeAt(); - this.publicKeyAlgorithm = input[mypos++].charCodeAt(); - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.signatureType = input.charCodeAt(mypos++); + this.publicKeyAlgorithm = input.charCodeAt(mypos++); + this.hashAlgorithm = input.charCodeAt(mypos++); // Two-octet scalar octet count for following hashed subpacket // data. - var hashed_subpacket_count = (input[mypos++].charCodeAt() << 8) + input[mypos++].charCodeAt(); + var hashed_subpacket_count = (input.charCodeAt(mypos++) << 8) + input.charCodeAt(mypos++); // Hashed subpacket data set (zero or more subpackets) var subpacket_length = 0; @@ -164,7 +164,7 @@ function openpgp_packet_signature() { // alert("signatureData: "+util.hexstrdump(this.signatureData)); // Two-octet scalar octet count for the following unhashed subpacket - var subpacket_count = (input[mypos++].charCodeAt() << 8) + input[mypos++].charCodeAt(); + var subpacket_count = (input.charCodeAt(mypos++) << 8) + input.charCodeAt(mypos++); // Unhashed subpacket data set (zero or more subpackets). subpacket_length = 0; @@ -180,7 +180,7 @@ function openpgp_packet_signature() { mypos += subpacket_count; // Two-octet field holding the left 16 bits of the signed hash // value. - this.signedHashValue = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); + this.signedHashValue = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++); // One or more multiprecision integers comprising the signature. // This portion is algorithm specific, as described above. var mpicount = 0; @@ -276,39 +276,39 @@ function openpgp_packet_signature() { var mypos = position; var subplen = 0; // alert('starting signature subpackage read at position:'+position+' length:'+len); - if (input[mypos].charCodeAt() < 192) { - subplen = input[mypos++].charCodeAt(); - } else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) { - subplen = ((input[mypos++].charCodeAt() - 192) << 8) + (input[mypos++].charCodeAt()) + 192; - } else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) { - subplen = 1 << (input[mypos++].charCodeAt() & 0x1F); - } else if (input[mypos].charCodeAt() < 255) { + if (input.charCodeAt(mypos) < 192) { + subplen = input.charCodeAt(mypos++); + } else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) { + subplen = ((input.charCodeAt(mypos++) - 192) << 8) + (input.charCodeAt(mypos++)) + 192; + } else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) { + subplen = 1 << (input.charCodeAt(mypos++) & 0x1F); + } else if (input.charCodeAt(mypos) < 255) { mypos++; - subplen = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) - | (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); + subplen = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) + | (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++); } - var type = input[mypos++].charCodeAt() & 0x7F; + var type = input.charCodeAt(mypos++) & 0x7F; // alert('signature subpacket type '+type+" with length: "+subplen); // subpacket type switch (type) { case 2: // Signature Creation Time - this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) - | (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt())*1000); + this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) + | (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++))*1000); break; case 3: // Signature Expiration Time - this.signatureExpirationTime = (input[mypos++].charCodeAt() << 24) - | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) - | input[mypos++].charCodeAt(); + this.signatureExpirationTime = (input.charCodeAt(mypos++) << 24) + | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8) + | input.charCodeAt(mypos++); this.signatureNeverExpires = (this.signature_expiration_time == 0); break; case 4: // Exportable Certification - this.exportable = input[mypos++].charCodeAt() == 1; + this.exportable = input.charCodeAt(mypos++) == 1; break; case 5: // Trust Signature - this.trustLevel = input[mypos++].charCodeAt(); - this.trustAmount = input[mypos++].charCodeAt(); + this.trustLevel = input.charCodeAt(mypos++); + this.trustAmount = input.charCodeAt(mypos++); break; case 6: // Regular Expression this.regular_expression = new String(); @@ -316,29 +316,29 @@ function openpgp_packet_signature() { this.regular_expression += (input[mypos++]); break; case 7: // Revocable - this.revocable = input[mypos++].charCodeAt() == 1; + this.revocable = input.charCodeAt(mypos++) == 1; break; case 9: // Key Expiration Time - this.keyExpirationTime = (input[mypos++].charCodeAt() << 24) - | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) - | input[mypos++].charCodeAt(); + this.keyExpirationTime = (input.charCodeAt(mypos++) << 24) + | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8) + | input.charCodeAt(mypos++); this.keyNeverExpires = (this.keyExpirationTime == 0); break; case 11: // Preferred Symmetric Algorithms this.preferredSymmetricAlgorithms = new Array(); for (var i = 0; i < subplen-1; i++) { - this.preferredSymmetricAlgorithms = input[mypos++].charCodeAt(); + this.preferredSymmetricAlgorithms = input.charCodeAt(mypos++); } break; case 12: // Revocation Key // (1 octet of class, 1 octet of public-key algorithm ID, 20 // octets of // fingerprint) - this.revocationKeyClass = input[mypos++].charCodeAt(); - this.revocationKeyAlgorithm = input[mypos++].charCodeAt(); + this.revocationKeyClass = input.charCodeAt(mypos++); + this.revocationKeyAlgorithm = input.charCodeAt(mypos++); this.revocationKeyFingerprint = new Array(); for ( var i = 0; i < 20; i++) { - this.revocationKeyFingerprint = input[mypos++].charCodeAt(); + this.revocationKeyFingerprint = input.charCodeAt(mypos++); } break; case 16: // Issuer @@ -346,12 +346,12 @@ function openpgp_packet_signature() { mypos += 8; break; case 20: // Notation Data - this.notationFlags = (input[mypos++].charCodeAt() << 24) | - (input[mypos++].charCodeAt() << 16) | - (input[mypos++].charCodeAt() << 8) | - (input[mypos++].charCodeAt()); - var nameLength = (input[mypos++].charCodeAt() << 8) | (input[mypos++].charCodeAt()); - var valueLength = (input[mypos++].charCodeAt() << 8) | (input[mypos++].charCodeAt()); + this.notationFlags = (input.charCodeAt(mypos++) << 24) | + (input.charCodeAt(mypos++) << 16) | + (input.charCodeAt(mypos++) << 8) | + (input.charCodeAt(mypos++)); + var nameLength = (input.charCodeAt(mypos++) << 8) | (input.charCodeAt(mypos++)); + var valueLength = (input.charCodeAt(mypos++) << 8) | (input.charCodeAt(mypos++)); this.notationName = ""; for (var i = 0; i < nameLength; i++) { this.notationName += input[mypos++]; @@ -364,19 +364,19 @@ function openpgp_packet_signature() { case 21: // Preferred Hash Algorithms this.preferredHashAlgorithms = new Array(); for (var i = 0; i < subplen-1; i++) { - this.preferredHashAlgorithms = input[mypos++].charCodeAt(); + this.preferredHashAlgorithms = input.charCodeAt(mypos++); } break; case 22: // Preferred Compression Algorithms this.preferredCompressionAlgorithms = new Array(); for ( var i = 0; i < subplen-1; i++) { - this.preferredCompressionAlgorithms = input[mypos++].charCodeAt(); + this.preferredCompressionAlgorithms = input.charCodeAt(mypos++); } break; case 23: // Key Server Preferences this.keyServerPreferences = new Array(); for ( var i = 0; i < subplen-1; i++) { - this.keyServerPreferences = input[mypos++].charCodeAt(); + this.keyServerPreferences = input.charCodeAt(mypos++); } break; case 24: // Preferred Key Server @@ -397,7 +397,7 @@ function openpgp_packet_signature() { case 27: // Key Flags this.keyFlags = new Array(); for ( var i = 0; i < subplen-1; i++) { - this.keyFlags = input[mypos++].charCodeAt(); + this.keyFlags = input.charCodeAt(mypos++); } break; case 28: // Signer's User ID @@ -407,7 +407,7 @@ function openpgp_packet_signature() { } break; case 29: // Reason for Revocation - this.reasonForRevocationFlag = input[mypos++].charCodeAt(); + this.reasonForRevocationFlag = input.charCodeAt(mypos++); this.reasonForRevocationString = new String(); for ( var i = 0; i < subplen -2; i++) { this.reasonForRevocationString += input[mypos++]; @@ -418,8 +418,8 @@ function openpgp_packet_signature() { return subplen+1; case 31: // Signature Target // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) - this.signatureTargetPublicKeyAlgorithm = input[mypos++].charCodeAt(); - this.signatureTargetHashAlgorithm = input[mypos++].charCodeAt(); + this.signatureTargetPublicKeyAlgorithm = input.charCodeAt(mypos++); + this.signatureTargetHashAlgorithm = input.charCodeAt(mypos++); var signatureTargetHashAlgorithmLength = 0; switch(this.signatureTargetHashAlgorithm) { case 1: // - MD5 [HAC] "MD5" diff --git a/src/packet/openpgp.packet.userattribute.js b/src/packet/openpgp.packet.userattribute.js index 9ccdfd17..26be64c8 100644 --- a/src/packet/openpgp.packet.userattribute.js +++ b/src/packet/openpgp.packet.userattribute.js @@ -55,27 +55,27 @@ function openpgp_packet_userattribute() { while (len != total_len) { var current_len = 0; // 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++); current_len = 1; // 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; current_len = 2; // 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); current_len = 1; // 4.2.2.3. Five-Octet Lengths } else { current_len = 5; 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++); } - var subpackettype = input[mypos++].charCodeAt(); + var subpackettype = input.charCodeAt(mypos++); packet_length--; current_len++; this.userattributes[count] = new Array(); diff --git a/src/packet/openpgp.packet.userid.js b/src/packet/openpgp.packet.userid.js index dadab892..427a035f 100644 --- a/src/packet/openpgp.packet.userid.js +++ b/src/packet/openpgp.packet.userid.js @@ -70,13 +70,7 @@ function openpgp_packet_userid() { */ this.read_packet = function(input, position, len) { this.packetLength = len; - - var bytes = ''; - for ( var i = 0; i < len; i++) { - bytes += input[position + i]; - } - - this.set_text_bytes(bytes); + this.set_text_bytes(input.substr(position, len)); return this; } diff --git a/src/type/openpgp.type.mpi.js b/src/type/openpgp.type.mpi.js index 82f56690..c766fa4a 100644 --- a/src/type/openpgp.type.mpi.js +++ b/src/type/openpgp.type.mpi.js @@ -47,7 +47,7 @@ function openpgp_type_mpi() { function read(input, position, len) { var mypos = position; - this.mpiBitLength = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); + this.mpiBitLength = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++); // Additional rules: // diff --git a/src/type/openpgp.type.s2k.js b/src/type/openpgp.type.s2k.js index b0d35afa..64360ee8 100644 --- a/src/type/openpgp.type.s2k.js +++ b/src/type/openpgp.type.s2k.js @@ -33,17 +33,17 @@ function openpgp_type_s2k() { */ function read(input, position) { var mypos = position; - this.type = input[mypos++].charCodeAt(); + this.type = input.charCodeAt(mypos++); switch (this.type) { case 0: // Simple S2K // Octet 1: hash algorithm - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.hashAlgorithm = input.charCodeAt(mypos++); this.s2kLength = 1; break; case 1: // Salted S2K // Octet 1: hash algorithm - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.hashAlgorithm = input.charCodeAt(mypos++); // Octets 2-9: 8-octet salt value this.saltValue = input.substring(mypos, mypos+8); @@ -53,7 +53,7 @@ function openpgp_type_s2k() { case 3: // Iterated and Salted S2K // Octet 1: hash algorithm - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.hashAlgorithm = input.charCodeAt(mypos++); // Octets 2-9: 8-octet salt value this.saltValue = input.substring(mypos, mypos+8); @@ -61,16 +61,16 @@ function openpgp_type_s2k() { // Octet 10: count, a one-octet, coded value this.EXPBIAS = 6; - var c = input[mypos++].charCodeAt(); + var c = input.charCodeAt(mypos++); this.count = (16 + (c & 15)) << ((c >> 4) + this.EXPBIAS); this.s2kLength = 10; break; case 101: if(input.substring(mypos+1, mypos+4) == "GNU") { - this.hashAlgorithm = input[mypos++].charCodeAt(); + this.hashAlgorithm = input.charCodeAt(mypos++); mypos += 3; // GNU - var gnuExtType = 1000 + input[mypos++].charCodeAt(); + var gnuExtType = 1000 + input.charCodeAt(mypos++); if(gnuExtType == 1001) { this.type = gnuExtType; this.s2kLength = 5; diff --git a/src/util/util.js b/src/util/util.js index b86884d3..3e487e54 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -49,7 +49,7 @@ var Util = function() { var c=0; var h; while(c