Don't use array indexing on strings it is nonstandard and doesn't work on IE

This commit is contained in:
Robert Nelson 2013-11-29 16:10:56 -08:00
parent 1cd7b542a0
commit e4e69749a6
12 changed files with 140 additions and 146 deletions

View File

@ -60,14 +60,14 @@ function _openpgp () {
while (mypos != input.length) { while (mypos != input.length) {
var first_packet = openpgp_packet.read_packet(input, mypos, l); var first_packet = openpgp_packet.read_packet(input, mypos, l);
// public key parser // 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] = new openpgp_msg_publickey();
publicKeys[publicKeyCount].header = input.substring(mypos,mypos+3); 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 // parse the length and read a tag6 packet
mypos++; mypos++;
var l = (input[mypos++].charCodeAt() << 8) var l = (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
publicKeys[publicKeyCount].publicKeyPacket = new openpgp_packet_keymaterial(); publicKeys[publicKeyCount].publicKeyPacket = new openpgp_packet_keymaterial();
publicKeys[publicKeyCount].publicKeyPacket.header = publicKeys[publicKeyCount].header; publicKeys[publicKeyCount].publicKeyPacket.header = publicKeys[publicKeyCount].header;
publicKeys[publicKeyCount].publicKeyPacket.read_tag6(input, mypos, l); publicKeys[publicKeyCount].publicKeyPacket.read_tag6(input, mypos, l);

View File

@ -49,7 +49,7 @@ function openpgp_packet_encryptedintegrityprotecteddata() {
this.packetLength = len; this.packetLength = len;
// - A one-octet version number. The only currently defined value is // - A one-octet version number. The only currently defined value is
// 1. // 1.
this.version = input[position].charCodeAt(); this.version = input.charCodeAt(position);
if (this.version != 1) { if (this.version != 1) {
util util
.print_error('openpgp.packet.encryptedintegrityprotecteddata.js\nunknown encrypted integrity protected data packet version: ' .print_error('openpgp.packet.encryptedintegrityprotecteddata.js\nunknown encrypted integrity protected data packet version: '

View File

@ -52,11 +52,11 @@ function openpgp_packet_encryptedsessionkey() {
return null; return null;
} }
this.version = input[mypos++].charCodeAt(); this.version = input.charCodeAt(mypos++);
this.keyId = new openpgp_type_keyid(); this.keyId = new openpgp_type_keyid();
this.keyId.read_packet(input, mypos); this.keyId.read_packet(input, mypos);
mypos += 8; mypos += 8;
this.publicKeyAlgorithmUsed = input[mypos++].charCodeAt(); this.publicKeyAlgorithmUsed = input.charCodeAt(mypos++);
switch (this.publicKeyAlgorithmUsed) { switch (this.publicKeyAlgorithmUsed) {
case 1: case 1:

View File

@ -106,7 +106,7 @@ function _openpgp_packet() {
// some sanity checks // some sanity checks
if (input == null || input.length <= position if (input == null || input.length <= position
|| input.substring(position).length < 2 || input.substring(position).length < 2
|| (input[position].charCodeAt() & 0x80) == 0) { || (input.charCodeAt(position) & 0x80) == 0) {
util util
.print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format."); .print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
return null; return null;
@ -116,18 +116,18 @@ function _openpgp_packet() {
var format = -1; var format = -1;
format = 0; // 0 = old format; 1 = new format format = 0; // 0 = old format; 1 = new format
if ((input[mypos].charCodeAt() & 0x40) != 0) { if ((input.charCodeAt(mypos) & 0x40) != 0) {
format = 1; format = 1;
} }
var packet_length_type; var packet_length_type;
if (format) { if (format) {
// new format header // new format header
tag = input[mypos].charCodeAt() & 0x3F; // bit 5-0 tag = input.charCodeAt(mypos) & 0x3F; // bit 5-0
} else { } else {
// old format header // old format header
tag = (input[mypos].charCodeAt() & 0x3F) >> 2; // bit 5-2 tag = (input.charCodeAt(mypos) & 0x3F) >> 2; // bit 5-2
packet_length_type = input[mypos].charCodeAt() & 0x03; // bit 1-0 packet_length_type = input.charCodeAt(mypos) & 0x03; // bit 1-0
} }
// header octet parsing done // header octet parsing done
@ -143,19 +143,19 @@ function _openpgp_packet() {
switch (packet_length_type) { switch (packet_length_type) {
case 0: // The packet has a one-octet length. The header is 2 octets case 0: // The packet has a one-octet length. The header is 2 octets
// long. // long.
packet_length = input[mypos++].charCodeAt(); packet_length = input.charCodeAt(mypos++);
break; break;
case 1: // The packet has a two-octet length. The header is 3 octets case 1: // The packet has a two-octet length. The header is 3 octets
// long. // long.
packet_length = (input[mypos++].charCodeAt() << 8) packet_length = (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
break; break;
case 2: // The packet has a four-octet length. The header is 5 case 2: // The packet has a four-octet length. The header is 5
// octets long. // octets long.
packet_length = (input[mypos++].charCodeAt() << 24) packet_length = (input.charCodeAt(mypos++) << 24)
| (input[mypos++].charCodeAt() << 16) | (input.charCodeAt(mypos++) << 16)
| (input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
break; break;
default: default:
// 3 - The packet is of indeterminate length. The header is 1 // 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 // 4.2.2.1. One-Octet Lengths
if (input[mypos].charCodeAt() < 192) { if (input.charCodeAt(mypos) < 192) {
packet_length = input[mypos++].charCodeAt(); packet_length = input.charCodeAt(mypos++);
util.print_debug("1 byte length:" + packet_length); util.print_debug("1 byte length:" + packet_length);
// 4.2.2.2. Two-Octet Lengths // 4.2.2.2. Two-Octet Lengths
} else if (input[mypos].charCodeAt() >= 192 } else if (input.charCodeAt(mypos) >= 192
&& input[mypos].charCodeAt() < 224) { && input.charCodeAt(mypos) < 224) {
packet_length = ((input[mypos++].charCodeAt() - 192) << 8) packet_length = ((input.charCodeAt(mypos++) - 192) << 8)
+ (input[mypos++].charCodeAt()) + 192; + (input.charCodeAt(mypos++)) + 192;
util.print_debug("2 byte length:" + packet_length); util.print_debug("2 byte length:" + packet_length);
// 4.2.2.4. Partial Body Lengths // 4.2.2.4. Partial Body Lengths
} else if (input[mypos].charCodeAt() > 223 } else if (input.charCodeAt(mypos) > 223
&& input[mypos].charCodeAt() < 255) { && input.charCodeAt(mypos) < 255) {
packet_length = 1 << (input[mypos++].charCodeAt() & 0x1F); packet_length = 1 << (input.charCodeAt(mypos++) & 0x1F);
util.print_debug("4 byte length:" + packet_length); util.print_debug("4 byte length:" + packet_length);
// EEEK, we're reading the full data here... // EEEK, we're reading the full data here...
var mypos2 = mypos + packet_length; var mypos2 = mypos + packet_length;
bodydata = input.substring(mypos, mypos + packet_length); bodydata = input.substring(mypos, mypos + packet_length);
while (true) { while (true) {
if (input[mypos2].charCodeAt() < 192) { if (input.charCodeAt(mypos2) < 192) {
var tmplen = input[mypos2++].charCodeAt(); var tmplen = input.charCodeAt(mypos2++);
packet_length += tmplen; packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen); bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen; mypos2 += tmplen;
break; break;
} else if (input[mypos2].charCodeAt() >= 192 } else if (input.charCodeAt(mypos2) >= 192
&& input[mypos2].charCodeAt() < 224) { && input.charCodeAt(mypos2) < 224) {
var tmplen = ((input[mypos2++].charCodeAt() - 192) << 8) var tmplen = ((input.charCodeAt(mypos2++) - 192) << 8)
+ (input[mypos2++].charCodeAt()) + 192; + (input.charCodeAt(mypos2++)) + 192;
packet_length += tmplen; packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen); bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen; mypos2 += tmplen;
break; break;
} else if (input[mypos2].charCodeAt() > 223 } else if (input.charCodeAt(mypos2) > 223
&& input[mypos2].charCodeAt() < 255) { && input.charCodeAt(mypos2) < 255) {
var tmplen = 1 << (input[mypos2++].charCodeAt() & 0x1F); var tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F);
packet_length += tmplen; packet_length += tmplen;
bodydata += input.substring(mypos2, mypos2 + tmplen); bodydata += input.substring(mypos2, mypos2 + tmplen);
mypos2 += tmplen; mypos2 += tmplen;
} else { } else {
mypos2++; mypos2++;
var tmplen = (input[mypos2++].charCodeAt() << 24) var tmplen = (input.charCodeAt(mypos2++) << 24)
| (input[mypos2++].charCodeAt() << 16) | (input.charCodeAt(mypos2++) << 16)
| (input[mypos2++].charCodeAt() << 8) | (input.charCodeAt(mypos2++) << 8)
| input[mypos2++].charCodeAt(); | input.charCodeAt(mypos2++);
bodydata += input.substring(mypos2, mypos2 + tmplen); bodydata += input.substring(mypos2, mypos2 + tmplen);
packet_length += tmplen; packet_length += tmplen;
mypos2 += tmplen; mypos2 += tmplen;
@ -230,10 +230,10 @@ function _openpgp_packet() {
// 4.2.2.3. Five-Octet Lengths // 4.2.2.3. Five-Octet Lengths
} else { } else {
mypos++; mypos++;
packet_length = (input[mypos++].charCodeAt() << 24) packet_length = (input.charCodeAt(mypos++) << 24)
| (input[mypos++].charCodeAt() << 16) | (input.charCodeAt(mypos++) << 16)
| (input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
} }
} }
@ -249,7 +249,7 @@ function _openpgp_packet() {
// alert('tag type: '+this.tag+' length: '+packet_length); // alert('tag type: '+this.tag+' length: '+packet_length);
var version = 1; // (old format; 2= new format) var version = 1; // (old format; 2= new format)
// if (input[mypos++].charCodeAt() > 15) // if (input.charCodeAt(mypos++) > 15)
// version = 2; // version = 2;
switch (tag) { switch (tag) {

View File

@ -125,20 +125,20 @@ function openpgp_packet_keymaterial() {
function read_pub_key(input, position, len) { function read_pub_key(input, position, len) {
var mypos = position; var mypos = position;
// A one-octet version number (3 or 4). // A one-octet version number (3 or 4).
this.version = input[mypos++].charCodeAt(); this.version = input.charCodeAt(mypos++);
if (this.version == 3) { if (this.version == 3) {
// A four-octet number denoting the time that the key was created. // A four-octet number denoting the time that the key was created.
this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) |
(input[mypos++].charCodeAt() << 16) | (input.charCodeAt(mypos++) << 16) |
(input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 8) |
(input[mypos++].charCodeAt()))*1000); (input.charCodeAt(mypos++)))*1000);
// - A two-octet number denoting the time in days that this key is // - A two-octet number denoting the time in days that this key is
// valid. If this number is zero, then it does not expire. // 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. // - 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; var mpicount = 0;
// - A series of multiprecision integers comprising the key material: // - A series of multiprecision integers comprising the key material:
// Algorithm-Specific Fields for RSA public keys: // Algorithm-Specific Fields for RSA public keys:
@ -174,13 +174,13 @@ function openpgp_packet_keymaterial() {
this.packetLength = mypos-position; this.packetLength = mypos-position;
} else if (this.version == 4) { } else if (this.version == 4) {
// - A four-octet number denoting the time that the key was created. // - A four-octet number denoting the time that the key was created.
this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) |
(input[mypos++].charCodeAt() << 16) | (input.charCodeAt(mypos++) << 16) |
(input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 8) |
(input[mypos++].charCodeAt()))*1000); (input.charCodeAt(mypos++)))*1000);
// - A one-octet number denoting the public-key algorithm of this key. // - 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; var mpicount = 0;
// - A series of multiprecision integers comprising the key material: // - A series of multiprecision integers comprising the key material:
// Algorithm-Specific Fields for RSA public keys: // 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. // - A Public-Key or Public-Subkey packet, as described above.
this.publicKey = new openpgp_packet_keymaterial(); this.publicKey = new openpgp_packet_keymaterial();
if (this.publicKey.read_pub_key(input,position, len) == null) { 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; return null;
} }
this.publicKey.header = openpgp_packet.write_old_packet_header(6,this.publicKey.packetLength); 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 the secret-key data is not encrypted. 255 or 254
// indicates that a string-to-key specifier is being given. Any // indicates that a string-to-key specifier is being given. Any
// other value is a symmetric-key encryption algorithm identifier. // other value is a symmetric-key encryption algorithm identifier.
this.s2kUsageConventions = input[mypos++].charCodeAt(); this.s2kUsageConventions = input.charCodeAt(mypos++);
if (this.s2kUsageConventions == 0) if (this.s2kUsageConventions == 0)
this.hasUnencryptedSecretKeyData = true; this.hasUnencryptedSecretKeyData = true;
@ -256,7 +256,7 @@ function openpgp_packet_keymaterial() {
// - [Optional] If string-to-key usage octet was 255 or 254, a one- // - [Optional] If string-to-key usage octet was 255 or 254, a one-
// octet symmetric encryption algorithm. // octet symmetric encryption algorithm.
if (this.s2kUsageConventions == 255 || this.s2kUsageConventions == 254) { 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 // - [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 // checksum because s2k usage convention is 0
this.checksum = new Array(); this.checksum = new Array();
this.checksum[0] = input[mypos++].charCodeAt(); this.checksum[0] = input.charCodeAt(mypos++);
this.checksum[1] = input[mypos++].charCodeAt(); this.checksum[1] = input.charCodeAt(mypos++);
} }
return this; return this;
} }

View File

@ -41,9 +41,9 @@ function openpgp_packet_marker() {
*/ */
function read_packet(input, position, len) { function read_packet(input, position, len) {
this.packetLength = 3; this.packetLength = 3;
if (input[position].charCodeAt() == 0x50 && // P if (input.charCodeAt(position) == 0x50 && // P
input[position + 1].charCodeAt() == 0x47 && // G input.charCodeAt(position + 1) == 0x47 && // G
input[position + 2].charCodeAt() == 0x50) // P input.charCodeAt(position + 2) == 0x50) // P
return this; return this;
// marker packet does not contain "PGP" // marker packet does not contain "PGP"
return null; return null;

View File

@ -84,21 +84,21 @@ function openpgp_packet_signature() {
var mypos = position; var mypos = position;
this.packetLength = len; this.packetLength = len;
// alert('starting parsing signature: '+position+' '+this.packetLength); // alert('starting parsing signature: '+position+' '+this.packetLength);
this.version = input[mypos++].charCodeAt(); this.version = input.charCodeAt(mypos++);
// switch on version (3 and 4) // switch on version (3 and 4)
switch (this.version) { switch (this.version) {
case 3: case 3:
// One-octet length of following hashed material. MUST be 5. // 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)); util.print_debug("openpgp.packet.signature.js\n"+'invalid One-octet length of following hashed material. MUST be 5. @:'+(mypos-1));
var sigpos = mypos; var sigpos = mypos;
// One-octet signature type. // One-octet signature type.
this.signatureType = input[mypos++].charCodeAt(); this.signatureType = input.charCodeAt(mypos++);
// Four-octet creation time. // Four-octet creation time.
this.creationTime = new Date(((input[mypos++].charCodeAt()) << 24 | this.creationTime = new Date(((input.charCodeAt(mypos++)) << 24 |
(input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8) |
input[mypos++].charCodeAt())* 1000); input.charCodeAt(mypos++))* 1000);
// storing data appended to data which gets verified // storing data appended to data which gets verified
this.signatureData = input.substring(position, mypos); this.signatureData = input.substring(position, mypos);
@ -108,13 +108,13 @@ function openpgp_packet_signature() {
mypos += 8; mypos += 8;
// One-octet public-key algorithm. // One-octet public-key algorithm.
this.publicKeyAlgorithm = input[mypos++].charCodeAt(); this.publicKeyAlgorithm = input.charCodeAt(mypos++);
// One-octet hash algorithm. // 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. // 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; var mpicount = 0;
// Algorithm-Specific Fields for RSA signatures: // Algorithm-Specific Fields for RSA signatures:
// - multiprecision integer (MPI) of RSA signature value m**d mod n. // - multiprecision integer (MPI) of RSA signature value m**d mod n.
@ -138,13 +138,13 @@ function openpgp_packet_signature() {
} }
break; break;
case 4: case 4:
this.signatureType = input[mypos++].charCodeAt(); this.signatureType = input.charCodeAt(mypos++);
this.publicKeyAlgorithm = input[mypos++].charCodeAt(); this.publicKeyAlgorithm = input.charCodeAt(mypos++);
this.hashAlgorithm = input[mypos++].charCodeAt(); this.hashAlgorithm = input.charCodeAt(mypos++);
// Two-octet scalar octet count for following hashed subpacket // Two-octet scalar octet count for following hashed subpacket
// data. // 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) // Hashed subpacket data set (zero or more subpackets)
var subpacket_length = 0; var subpacket_length = 0;
@ -164,7 +164,7 @@ function openpgp_packet_signature() {
// alert("signatureData: "+util.hexstrdump(this.signatureData)); // alert("signatureData: "+util.hexstrdump(this.signatureData));
// Two-octet scalar octet count for the following unhashed subpacket // 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). // Unhashed subpacket data set (zero or more subpackets).
subpacket_length = 0; subpacket_length = 0;
@ -180,7 +180,7 @@ function openpgp_packet_signature() {
mypos += subpacket_count; mypos += subpacket_count;
// Two-octet field holding the left 16 bits of the signed hash // Two-octet field holding the left 16 bits of the signed hash
// value. // 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. // One or more multiprecision integers comprising the signature.
// This portion is algorithm specific, as described above. // This portion is algorithm specific, as described above.
var mpicount = 0; var mpicount = 0;
@ -276,39 +276,39 @@ function openpgp_packet_signature() {
var mypos = position; var mypos = position;
var subplen = 0; var subplen = 0;
// alert('starting signature subpackage read at position:'+position+' length:'+len); // alert('starting signature subpackage read at position:'+position+' length:'+len);
if (input[mypos].charCodeAt() < 192) { if (input.charCodeAt(mypos) < 192) {
subplen = input[mypos++].charCodeAt(); subplen = input.charCodeAt(mypos++);
} else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) { } else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) {
subplen = ((input[mypos++].charCodeAt() - 192) << 8) + (input[mypos++].charCodeAt()) + 192; subplen = ((input.charCodeAt(mypos++) - 192) << 8) + (input.charCodeAt(mypos++)) + 192;
} else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) { } else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) {
subplen = 1 << (input[mypos++].charCodeAt() & 0x1F); subplen = 1 << (input.charCodeAt(mypos++) & 0x1F);
} else if (input[mypos].charCodeAt() < 255) { } else if (input.charCodeAt(mypos) < 255) {
mypos++; mypos++;
subplen = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) subplen = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16)
| (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); | (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); // alert('signature subpacket type '+type+" with length: "+subplen);
// subpacket type // subpacket type
switch (type) { switch (type) {
case 2: // Signature Creation Time case 2: // Signature Creation Time
this.creationTime = new Date(((input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) this.creationTime = new Date(((input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16)
| (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt())*1000); | (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++))*1000);
break; break;
case 3: // Signature Expiration Time case 3: // Signature Expiration Time
this.signatureExpirationTime = (input[mypos++].charCodeAt() << 24) this.signatureExpirationTime = (input.charCodeAt(mypos++) << 24)
| (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
this.signatureNeverExpires = (this.signature_expiration_time == 0); this.signatureNeverExpires = (this.signature_expiration_time == 0);
break; break;
case 4: // Exportable Certification case 4: // Exportable Certification
this.exportable = input[mypos++].charCodeAt() == 1; this.exportable = input.charCodeAt(mypos++) == 1;
break; break;
case 5: // Trust Signature case 5: // Trust Signature
this.trustLevel = input[mypos++].charCodeAt(); this.trustLevel = input.charCodeAt(mypos++);
this.trustAmount = input[mypos++].charCodeAt(); this.trustAmount = input.charCodeAt(mypos++);
break; break;
case 6: // Regular Expression case 6: // Regular Expression
this.regular_expression = new String(); this.regular_expression = new String();
@ -316,29 +316,29 @@ function openpgp_packet_signature() {
this.regular_expression += (input[mypos++]); this.regular_expression += (input[mypos++]);
break; break;
case 7: // Revocable case 7: // Revocable
this.revocable = input[mypos++].charCodeAt() == 1; this.revocable = input.charCodeAt(mypos++) == 1;
break; break;
case 9: // Key Expiration Time case 9: // Key Expiration Time
this.keyExpirationTime = (input[mypos++].charCodeAt() << 24) this.keyExpirationTime = (input.charCodeAt(mypos++) << 24)
| (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << 8)
| input[mypos++].charCodeAt(); | input.charCodeAt(mypos++);
this.keyNeverExpires = (this.keyExpirationTime == 0); this.keyNeverExpires = (this.keyExpirationTime == 0);
break; break;
case 11: // Preferred Symmetric Algorithms case 11: // Preferred Symmetric Algorithms
this.preferredSymmetricAlgorithms = new Array(); this.preferredSymmetricAlgorithms = new Array();
for (var i = 0; i < subplen-1; i++) { for (var i = 0; i < subplen-1; i++) {
this.preferredSymmetricAlgorithms = input[mypos++].charCodeAt(); this.preferredSymmetricAlgorithms = input.charCodeAt(mypos++);
} }
break; break;
case 12: // Revocation Key case 12: // Revocation Key
// (1 octet of class, 1 octet of public-key algorithm ID, 20 // (1 octet of class, 1 octet of public-key algorithm ID, 20
// octets of // octets of
// fingerprint) // fingerprint)
this.revocationKeyClass = input[mypos++].charCodeAt(); this.revocationKeyClass = input.charCodeAt(mypos++);
this.revocationKeyAlgorithm = input[mypos++].charCodeAt(); this.revocationKeyAlgorithm = input.charCodeAt(mypos++);
this.revocationKeyFingerprint = new Array(); this.revocationKeyFingerprint = new Array();
for ( var i = 0; i < 20; i++) { for ( var i = 0; i < 20; i++) {
this.revocationKeyFingerprint = input[mypos++].charCodeAt(); this.revocationKeyFingerprint = input.charCodeAt(mypos++);
} }
break; break;
case 16: // Issuer case 16: // Issuer
@ -346,12 +346,12 @@ function openpgp_packet_signature() {
mypos += 8; mypos += 8;
break; break;
case 20: // Notation Data case 20: // Notation Data
this.notationFlags = (input[mypos++].charCodeAt() << 24) | this.notationFlags = (input.charCodeAt(mypos++) << 24) |
(input[mypos++].charCodeAt() << 16) | (input.charCodeAt(mypos++) << 16) |
(input[mypos++].charCodeAt() << 8) | (input.charCodeAt(mypos++) << 8) |
(input[mypos++].charCodeAt()); (input.charCodeAt(mypos++));
var nameLength = (input[mypos++].charCodeAt() << 8) | (input[mypos++].charCodeAt()); var nameLength = (input.charCodeAt(mypos++) << 8) | (input.charCodeAt(mypos++));
var valueLength = (input[mypos++].charCodeAt() << 8) | (input[mypos++].charCodeAt()); var valueLength = (input.charCodeAt(mypos++) << 8) | (input.charCodeAt(mypos++));
this.notationName = ""; this.notationName = "";
for (var i = 0; i < nameLength; i++) { for (var i = 0; i < nameLength; i++) {
this.notationName += input[mypos++]; this.notationName += input[mypos++];
@ -364,19 +364,19 @@ function openpgp_packet_signature() {
case 21: // Preferred Hash Algorithms case 21: // Preferred Hash Algorithms
this.preferredHashAlgorithms = new Array(); this.preferredHashAlgorithms = new Array();
for (var i = 0; i < subplen-1; i++) { for (var i = 0; i < subplen-1; i++) {
this.preferredHashAlgorithms = input[mypos++].charCodeAt(); this.preferredHashAlgorithms = input.charCodeAt(mypos++);
} }
break; break;
case 22: // Preferred Compression Algorithms case 22: // Preferred Compression Algorithms
this.preferredCompressionAlgorithms = new Array(); this.preferredCompressionAlgorithms = new Array();
for ( var i = 0; i < subplen-1; i++) { for ( var i = 0; i < subplen-1; i++) {
this.preferredCompressionAlgorithms = input[mypos++].charCodeAt(); this.preferredCompressionAlgorithms = input.charCodeAt(mypos++);
} }
break; break;
case 23: // Key Server Preferences case 23: // Key Server Preferences
this.keyServerPreferences = new Array(); this.keyServerPreferences = new Array();
for ( var i = 0; i < subplen-1; i++) { for ( var i = 0; i < subplen-1; i++) {
this.keyServerPreferences = input[mypos++].charCodeAt(); this.keyServerPreferences = input.charCodeAt(mypos++);
} }
break; break;
case 24: // Preferred Key Server case 24: // Preferred Key Server
@ -397,7 +397,7 @@ function openpgp_packet_signature() {
case 27: // Key Flags case 27: // Key Flags
this.keyFlags = new Array(); this.keyFlags = new Array();
for ( var i = 0; i < subplen-1; i++) { for ( var i = 0; i < subplen-1; i++) {
this.keyFlags = input[mypos++].charCodeAt(); this.keyFlags = input.charCodeAt(mypos++);
} }
break; break;
case 28: // Signer's User ID case 28: // Signer's User ID
@ -407,7 +407,7 @@ function openpgp_packet_signature() {
} }
break; break;
case 29: // Reason for Revocation case 29: // Reason for Revocation
this.reasonForRevocationFlag = input[mypos++].charCodeAt(); this.reasonForRevocationFlag = input.charCodeAt(mypos++);
this.reasonForRevocationString = new String(); this.reasonForRevocationString = new String();
for ( var i = 0; i < subplen -2; i++) { for ( var i = 0; i < subplen -2; i++) {
this.reasonForRevocationString += input[mypos++]; this.reasonForRevocationString += input[mypos++];
@ -418,8 +418,8 @@ function openpgp_packet_signature() {
return subplen+1; return subplen+1;
case 31: // Signature Target case 31: // Signature Target
// (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
this.signatureTargetPublicKeyAlgorithm = input[mypos++].charCodeAt(); this.signatureTargetPublicKeyAlgorithm = input.charCodeAt(mypos++);
this.signatureTargetHashAlgorithm = input[mypos++].charCodeAt(); this.signatureTargetHashAlgorithm = input.charCodeAt(mypos++);
var signatureTargetHashAlgorithmLength = 0; var signatureTargetHashAlgorithmLength = 0;
switch(this.signatureTargetHashAlgorithm) { switch(this.signatureTargetHashAlgorithm) {
case 1: // - MD5 [HAC] "MD5" case 1: // - MD5 [HAC] "MD5"

View File

@ -55,27 +55,27 @@ function openpgp_packet_userattribute() {
while (len != total_len) { while (len != total_len) {
var current_len = 0; var current_len = 0;
// 4.2.2.1. One-Octet Lengths // 4.2.2.1. One-Octet Lengths
if (input[mypos].charCodeAt() < 192) { if (input.charCodeAt(mypos) < 192) {
packet_length = input[mypos++].charCodeAt(); packet_length = input.charCodeAt(mypos++);
current_len = 1; current_len = 1;
// 4.2.2.2. Two-Octet Lengths // 4.2.2.2. Two-Octet Lengths
} else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) { } else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) {
packet_length = ((input[mypos++].charCodeAt() - 192) << 8) packet_length = ((input.charCodeAt(mypos++) - 192) << 8)
+ (input[mypos++].charCodeAt()) + 192; + (input.charCodeAt(mypos++)) + 192;
current_len = 2; current_len = 2;
// 4.2.2.4. Partial Body Lengths // 4.2.2.4. Partial Body Lengths
} else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) { } else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) {
packet_length = 1 << (input[mypos++].charCodeAt() & 0x1F); packet_length = 1 << (input.charCodeAt(mypos++) & 0x1F);
current_len = 1; current_len = 1;
// 4.2.2.3. Five-Octet Lengths // 4.2.2.3. Five-Octet Lengths
} else { } else {
current_len = 5; current_len = 5;
mypos++; mypos++;
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16)
| (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); | (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++);
} }
var subpackettype = input[mypos++].charCodeAt(); var subpackettype = input.charCodeAt(mypos++);
packet_length--; packet_length--;
current_len++; current_len++;
this.userattributes[count] = new Array(); this.userattributes[count] = new Array();

View File

@ -70,13 +70,7 @@ function openpgp_packet_userid() {
*/ */
this.read_packet = function(input, position, len) { this.read_packet = function(input, position, len) {
this.packetLength = len; this.packetLength = len;
this.set_text_bytes(input.substr(position, len));
var bytes = '';
for ( var i = 0; i < len; i++) {
bytes += input[position + i];
}
this.set_text_bytes(bytes);
return this; return this;
} }

View File

@ -47,7 +47,7 @@ function openpgp_type_mpi() {
function read(input, position, len) { function read(input, position, len) {
var mypos = position; var mypos = position;
this.mpiBitLength = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt(); this.mpiBitLength = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++);
// Additional rules: // Additional rules:
// //

View File

@ -33,17 +33,17 @@ function openpgp_type_s2k() {
*/ */
function read(input, position) { function read(input, position) {
var mypos = position; var mypos = position;
this.type = input[mypos++].charCodeAt(); this.type = input.charCodeAt(mypos++);
switch (this.type) { switch (this.type) {
case 0: // Simple S2K case 0: // Simple S2K
// Octet 1: hash algorithm // Octet 1: hash algorithm
this.hashAlgorithm = input[mypos++].charCodeAt(); this.hashAlgorithm = input.charCodeAt(mypos++);
this.s2kLength = 1; this.s2kLength = 1;
break; break;
case 1: // Salted S2K case 1: // Salted S2K
// Octet 1: hash algorithm // Octet 1: hash algorithm
this.hashAlgorithm = input[mypos++].charCodeAt(); this.hashAlgorithm = input.charCodeAt(mypos++);
// Octets 2-9: 8-octet salt value // Octets 2-9: 8-octet salt value
this.saltValue = input.substring(mypos, mypos+8); this.saltValue = input.substring(mypos, mypos+8);
@ -53,7 +53,7 @@ function openpgp_type_s2k() {
case 3: // Iterated and Salted S2K case 3: // Iterated and Salted S2K
// Octet 1: hash algorithm // Octet 1: hash algorithm
this.hashAlgorithm = input[mypos++].charCodeAt(); this.hashAlgorithm = input.charCodeAt(mypos++);
// Octets 2-9: 8-octet salt value // Octets 2-9: 8-octet salt value
this.saltValue = input.substring(mypos, mypos+8); this.saltValue = input.substring(mypos, mypos+8);
@ -61,16 +61,16 @@ function openpgp_type_s2k() {
// Octet 10: count, a one-octet, coded value // Octet 10: count, a one-octet, coded value
this.EXPBIAS = 6; this.EXPBIAS = 6;
var c = input[mypos++].charCodeAt(); var c = input.charCodeAt(mypos++);
this.count = (16 + (c & 15)) << ((c >> 4) + this.EXPBIAS); this.count = (16 + (c & 15)) << ((c >> 4) + this.EXPBIAS);
this.s2kLength = 10; this.s2kLength = 10;
break; break;
case 101: case 101:
if(input.substring(mypos+1, mypos+4) == "GNU") { if(input.substring(mypos+1, mypos+4) == "GNU") {
this.hashAlgorithm = input[mypos++].charCodeAt(); this.hashAlgorithm = input.charCodeAt(mypos++);
mypos += 3; // GNU mypos += 3; // GNU
var gnuExtType = 1000 + input[mypos++].charCodeAt(); var gnuExtType = 1000 + input.charCodeAt(mypos++);
if(gnuExtType == 1001) { if(gnuExtType == 1001) {
this.type = gnuExtType; this.type = gnuExtType;
this.s2kLength = 5; this.s2kLength = 5;

View File

@ -49,7 +49,7 @@ var Util = function() {
var c=0; var c=0;
var h; var h;
while(c<e){ while(c<e){
h=str[c++].charCodeAt().toString(16); h=str.charCodeAt(c++).toString(16);
while(h.length<2) h="0"+h; while(h.length<2) h="0"+h;
r.push(""+h); r.push(""+h);
} }