diff --git a/src/cleartext.js b/src/cleartext.js index 34924849..e7d8f260 100644 --- a/src/cleartext.js +++ b/src/cleartext.js @@ -124,7 +124,7 @@ CleartextMessage.prototype.armor = function() { hash: enums.read(enums.hash, config.prefer_hash_algorithm).toUpperCase(), text: this.text, data: this.packets.write() - } + }; return armor.encode(enums.armor.signed, body); }; diff --git a/src/compression/jxg.js b/src/compression/jxg.js index 814ceda2..f23632ea 100644 --- a/src/compression/jxg.js +++ b/src/compression/jxg.js @@ -2,7 +2,7 @@ JXG = { exists: (function(undefined) { return function(v) { return !(v === undefined || v === null); - } + }; })() }; JXG.decompress = function(str) { @@ -142,24 +142,24 @@ JXG.Util.Unzip = function(barray) { return bA[bytepos++]; } else return -1; - }; + } function byteAlign() { bb = 1; - }; + } function readBit() { var carry; bits++; carry = (bb & 1); bb >>= 1; - if (bb == 0) { + if (bb === 0) { bb = readByte(); carry = (bb & 1); bb = (bb >> 1) | 0x80; } return carry; - }; + } function readBits(a) { var res = 0, @@ -172,12 +172,12 @@ JXG.Util.Unzip = function(barray) { res = bitReverse[res] >> (8 - a); } return res; - }; + } function flushBuffer() { //document.write('FLUSHBUFFER:'+buf32k); bIdx = 0; - }; + } function addBuffer(a) { SIZE++; @@ -189,14 +189,14 @@ JXG.Util.Unzip = function(barray) { //document.write('ADDBUFFER:'+buf32k); bIdx = 0; } - }; + } function HufNode() { this.b0 = 0; this.b1 = 0; this.jump = null; this.jumppos = -1; - }; + } var LITERALS = 288; @@ -223,7 +223,7 @@ JXG.Util.Unzip = function(barray) { return fpos[len]++; fpos[len]++; } - }; + } function Rec() { var curplace = Places[treepos]; @@ -269,7 +269,7 @@ JXG.Util.Unzip = function(barray) { } len--; return 0; - }; + } function CreateTree(currentTree, numval, lengths, show) { var i; @@ -314,7 +314,7 @@ JXG.Util.Unzip = function(barray) { } }*/ return 0; - }; + } function DecodeValue(currentTree) { var len, i, @@ -353,10 +353,10 @@ JXG.Util.Unzip = function(barray) { X = currentTree[xtreepos]; } } - }; + } function DeflateLoop() { - var last, c, type, i, len; + var last, c, type, i, j, len, dist; do { /*if((last = readBit())){ @@ -389,7 +389,7 @@ JXG.Util.Unzip = function(barray) { break; } - if (type == 0) { + if (type === 0) { var blockLen, cSum; // Stored @@ -408,8 +408,6 @@ JXG.Util.Unzip = function(barray) { addBuffer(c); } } else if (type == 1) { - var j; - /* Fixed Huffman tables -- fixed decode routine */ while (1) { /* @@ -454,8 +452,6 @@ JXG.Util.Unzip = function(barray) { /* EOF */ break; } else { - var len, dist; - j -= 256 + 1; /* bytes + EOF */ len = readBits(cplext[j]) + cplens[j]; @@ -470,13 +466,13 @@ JXG.Util.Unzip = function(barray) { /*fprintf(errfp, "@%d (l%02x,d%04x)\n", SIZE, len, dist);*/ for (j = 0; j < len; j++) { - var c = buf32k[(bIdx - dist) & 0x7fff]; + c = buf32k[(bIdx - dist) & 0x7fff]; addBuffer(c); } } } // while } else if (type == 2) { - var j, n, literalCodes, distCodes, lenCodes; + var n, literalCodes, distCodes, lenCodes; var ll = new Array(288 + 32); // "static" just to preserve stack // Dynamic Huffman tables @@ -511,8 +507,8 @@ JXG.Util.Unzip = function(barray) { document.write("
" + distanceTree[a].b0 + " " + distanceTree[a].b1 + " " + distanceTree[a].jump + " " + distanceTree[a].jumppos); /*if (distanceTree[a].jumppos!=-1) - document.write(" "+distanceTree[a].jump.b0+" "+distanceTree[a].jump.b1); - */ + document.write(" "+distanceTree[a].jump.b0+" "+distanceTree[a].jump.b1); + */ } } //document.write('
tree created'); @@ -573,7 +569,7 @@ JXG.Util.Unzip = function(barray) { len = literalTree.length; for (i = 0; i < len; i++) distanceTree[i] = new HufNode(); - var ll2 = new Array(); + var ll2 = []; for (i = literalCodes; i < ll.length; i++) { ll2[i - literalCodes] = ll[i]; } @@ -586,9 +582,8 @@ JXG.Util.Unzip = function(barray) { outer: while (1) { j = DecodeValue(literalTree); if (j >= 256) { // In C64: if carry set - var len, dist; j -= 256; - if (j == 0) { + if (j === 0) { // EOF break; } @@ -607,7 +602,7 @@ JXG.Util.Unzip = function(barray) { if (bIdx - dist < 0) { break outer; } - var c = buf32k[(bIdx - dist) & 0x7fff]; + c = buf32k[(bIdx - dist) & 0x7fff]; addBuffer(c); } } else { @@ -620,7 +615,7 @@ JXG.Util.Unzip = function(barray) { byteAlign(); return 0; - }; + } JXG.Util.Unzip.prototype.unzipFile = function(name) { var i; @@ -631,7 +626,6 @@ JXG.Util.Unzip = function(barray) { return unzipped[i][0]; } } - }; JXG.Util.Unzip.prototype.deflate = function() { @@ -646,7 +640,7 @@ JXG.Util.Unzip = function(barray) { unzipped[files][1] = "DEFLATE"; files++; return unzipped; - } + }; JXG.Util.Unzip.prototype.unzip = function() { //convertToByteArray(input); @@ -771,8 +765,9 @@ JXG.Util.Unzip = function(barray) { alert("filelen " + filelen); i = 0; nameBuf = []; + var c; while (filelen--) { - var c = readByte(); + c = readByte(); if (c == "/" | c == ":") { i = 0; } else if (i < NAMEMAX - 1) @@ -794,7 +789,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"); @@ -812,7 +807,7 @@ JXG.Util.Unzip = function(barray) { skipdir(); } } - }; + } function skipdir() { var crc, @@ -925,7 +920,7 @@ JXG.Util.Unzip = function(barray) { if (modeZIP) nextFile(); - }; + } }; @@ -1069,7 +1064,7 @@ JXG.Util.Base64 = { lineno, i, destripped = []; - if (wrap == null) + if (wrap === null) wrap = 76; stripped.replace(/ /g, ""); @@ -1224,7 +1219,7 @@ JXG.Util.utf8Decode = function(utftext) { string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))); i += 3; } - }; + } return string.join(''); }; diff --git a/src/config/localStorage.js b/src/config/localStorage.js index 08de17f8..29434e69 100644 --- a/src/config/localStorage.js +++ b/src/config/localStorage.js @@ -20,12 +20,12 @@ module.exports = function () { this.write(); } else this.config = cf; - } + }; /** * Writes the config to HTML5 local storage */ this.write = function () { window.localStorage.setItem("config", JSON.stringify(this.config)); - } -} + }; +}; diff --git a/src/crypto/cfb.js b/src/crypto/cfb.js index a2147782..939d7d24 100644 --- a/src/crypto/cfb.js +++ b/src/crypto/cfb.js @@ -52,8 +52,9 @@ module.exports = { prefixrandom = prefixrandom + prefixrandom.charAt(block_size - 2) + prefixrandom.charAt(block_size - 1); util.print_debug("prefixrandom:" + util.hexstrdump(prefixrandom)); var ciphertext = ""; + var i; // 1. The feedback register (FR) is set to the IV, which is all zeros. - for (var i = 0; i < block_size; i++) FR[i] = 0; + for (i = 0; i < block_size; i++) FR[i] = 0; // 2. FR is encrypted to produce FRE (FR Encrypted). This is the // encryption of an all-zero value. @@ -61,13 +62,13 @@ module.exports = { // 3. FRE is xored with the first BS octets of random data prefixed to // the plaintext to produce C[1] through C[BS], the first BS octets // of ciphertext. - for (var i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ prefixrandom.charCodeAt(i)); + for (i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ prefixrandom.charCodeAt(i)); // 4. FR is loaded with C[1] through C[BS]. - for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i); + for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i); // 5. FR is encrypted to produce FRE, the encryption of the first BS - // octets of ciphertext. + // octets of ciphertext. FRE = cipherfn.encrypt(FR); // 6. The left two octets of FRE get xored with the next two octets of @@ -78,22 +79,22 @@ module.exports = { if (resync) { // 7. (The resync step) FR is loaded with C3-C10. - for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i + 2); + for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i + 2); } else { - for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i); + for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i); } // 8. FR is encrypted to produce FRE. FRE = cipherfn.encrypt(FR, key); if (resync) { // 9. FRE is xored with the first 8 octets of the given plaintext, now - // that we have finished encrypting the 10 octets of prefixed data. - // This produces C11-C18, the next 8 octets of ciphertext. - for (var i = 0; i < block_size; i++) + // that we have finished encrypting the 10 octets of prefixed data. + // This produces C11-C18, the next 8 octets of ciphertext. + for (i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i)); for (n = block_size + 2; n < plaintext.length; n += block_size) { // 10. FR is loaded with C11-C18 - for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(n + i); + for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(n + i); // 11. FR is encrypted to produce FRE. FRE = cipherfn.encrypt(FR); @@ -101,20 +102,20 @@ module.exports = { // 12. FRE is xored with the next 8 octets of plaintext, to produce the // next 8 octets of ciphertext. These are loaded into FR and the // process is repeated until the plaintext is used up. - for (var i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt((n - 2) + + for (i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt((n - 2) + i)); } } else { plaintext = " " + plaintext; // 9. FRE is xored with the first 8 octets of the given plaintext, now - // that we have finished encrypting the 10 octets of prefixed data. - // This produces C11-C18, the next 8 octets of ciphertext. - for (var i = 2; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i)); + // that we have finished encrypting the 10 octets of prefixed data. + // This produces C11-C18, the next 8 octets of ciphertext. + for (i = 2; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i)); var tempCiphertext = ciphertext.substring(0, 2 * block_size).split(''); var tempCiphertextString = ciphertext.substring(block_size); for (n = block_size; n < plaintext.length; n += block_size) { // 10. FR is loaded with C11-C18 - for (var i = 0; i < block_size; i++) FR[i] = tempCiphertextString.charCodeAt(i); + for (i = 0; i < block_size; i++) FR[i] = tempCiphertextString.charCodeAt(i); tempCiphertextString = ''; // 11. FR is encrypted to produce FRE. @@ -123,13 +124,12 @@ module.exports = { // 12. FRE is xored with the next 8 octets of plaintext, to produce the // next 8 octets of ciphertext. These are loaded into FR and the // process is repeated until the plaintext is used up. - for (var i = 0; i < block_size; i++) { + for (i = 0; i < block_size; i++) { tempCiphertext.push(String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i))); tempCiphertextString += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i)); } } ciphertext = tempCiphertext.join(''); - } ciphertext = ciphertext.substring(0, plaintext.length + 2 + block_size); @@ -239,7 +239,7 @@ module.exports = { } } - var n = resync ? 0 : 2; + n = resync ? 0 : 2; text = text.join(''); @@ -281,14 +281,15 @@ module.exports = { var pos = 0; var plaintext = []; var offset = 0; - if (iv == null) - for (var i = 0; i < block_size; i++) blockp += String.fromCharCode(0); + var i; + if (iv === null) + for (i = 0; i < block_size; i++) blockp += String.fromCharCode(0); else blockp = iv.substring(0, block_size); while (ciphertext.length > (block_size * pos)) { var decblock = cipherfn.encrypt(util.str2bin(blockp)); blockp = ciphertext.substring((pos * (block_size)) + offset, (pos * (block_size)) + (block_size) + offset); - for (var i = 0; i < blockp.length; i++) { + for (i = 0; i < blockp.length; i++) { plaintext.push(String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i])); } pos++; @@ -296,4 +297,4 @@ module.exports = { return plaintext.join(''); } -} +}; diff --git a/src/crypto/cipher/aes.js b/src/crypto/cipher/aes.js index a8f6e6cd..5d99d78e 100644 --- a/src/crypto/cipher/aes.js +++ b/src/crypto/cipher/aes.js @@ -493,8 +493,8 @@ function makeClass(length) { this.encrypt = function(block) { return AESencrypt(block, this.key); - } - } + }; + }; c.blockSize = c.prototype.blockSize = 16; c.keySize = c.prototype.keySize = length / 8; @@ -502,7 +502,7 @@ function makeClass(length) { return c; } -module.exports = {} +module.exports = {}; var types = [128, 192, 256]; diff --git a/src/crypto/cipher/blowfish.js b/src/crypto/cipher/blowfish.js index f6d2445d..a496c90e 100644 --- a/src/crypto/cipher/blowfish.js +++ b/src/crypto/cipher/blowfish.js @@ -14,7 +14,7 @@ * The constructor doesn't do much of anything. It's just here * so we can start defining properties and methods and such. */ -function Blowfish() {}; +function Blowfish() {} /* * Declare the block size so that protocols know what size @@ -407,7 +407,7 @@ function BF(key) { this.encrypt = function(block) { return this.bf.encrypt_block(block); - } + }; } diff --git a/src/crypto/cipher/cast5.js b/src/crypto/cipher/cast5.js index 782083d6..f875490f 100644 --- a/src/crypto/cipher/cast5.js +++ b/src/crypto/cipher/cast5.js @@ -252,19 +252,22 @@ function openpgp_symenc_cast5() { var t = new Array(8); var k = new Array(32); - for (var i = 0; i < 4; i++) { - var j = i * 4; + var i, j; + + for (i = 0; i < 4; i++) { + j = i * 4; t[i] = inn[j] << 24 | inn[j + 1] << 16 | inn[j + 2] << 8 | inn[j + 3]; } var x = [6, 7, 4, 5]; var ki = 0; + var w; for (var half = 0; half < 2; half++) { for (var round = 0; round < 4; round++) { - for (var j = 0; j < 4; j++) { + for (j = 0; j < 4; j++) { var a = scheduleA[round][j]; - var w = t[a[1]]; + w = t[a[1]]; w ^= sBox[4][(t[a[2] >>> 2] >>> (24 - 8 * (a[2] & 3))) & 0xff]; w ^= sBox[5][(t[a[3] >>> 2] >>> (24 - 8 * (a[3] & 3))) & 0xff]; @@ -274,9 +277,9 @@ function openpgp_symenc_cast5() { t[a[0]] = w; } - for (var j = 0; j < 4; j++) { + for (j = 0; j < 4; j++) { var b = scheduleB[round][j]; - var w = sBox[4][(t[b[0] >>> 2] >>> (24 - 8 * (b[0] & 3))) & 0xff]; + w = sBox[4][(t[b[0] >>> 2] >>> (24 - 8 * (b[0] & 3))) & 0xff]; w ^= sBox[5][(t[b[1] >>> 2] >>> (24 - 8 * (b[1] & 3))) & 0xff]; w ^= sBox[6][(t[b[2] >>> 2] >>> (24 - 8 * (b[2] & 3))) & 0xff]; @@ -288,7 +291,7 @@ function openpgp_symenc_cast5() { } } - for (var i = 0; i < 16; i++) { + for (i = 0; i < 16; i++) { this.masking[i] = k[i]; this.rotate[i] = k[16 + i] & 0x1f; } @@ -587,8 +590,7 @@ function openpgp_symenc_cast5() { 0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82, 0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e); -}; - +} var util = require('../../util'); function cast5(key) { @@ -597,7 +599,7 @@ function cast5(key) { this.encrypt = function(block) { return this.cast5.encrypt(block); - } + }; } module.exports = cast5; diff --git a/src/crypto/cipher/des.js b/src/crypto/cipher/des.js index 5cb2bf03..fdb67b32 100644 --- a/src/crypto/cipher/des.js +++ b/src/crypto/cipher/des.js @@ -81,7 +81,7 @@ function des(keys, message, encrypt, mode, iv, padding) { //create the 16 or 48 subkeys we will need var m = 0, i, j, temp, temp2, right1, right2, left, right, looping; - var cbcleft, cbcleft2, cbcright, cbcright2 + var cbcleft, cbcleft2, cbcright, cbcright2; var endloop, loopinc; var len = message.length; var chunk = 0; @@ -378,7 +378,7 @@ function Des(key) { des(des_createKeys(this.key[0]), util.bin2str(block), true, 0, null, null), false, 0, null, null), true, 0, null, null)); - } + }; } Des.keySize = Des.prototype.keySize = 24; @@ -393,12 +393,12 @@ function OriginalDes(key) { this.encrypt = function(block, padding) { var keys = des_createKeys(this.key); return util.str2bin(des(keys, util.bin2str(block), true, 0, null, padding)); - } + }; this.decrypt = function(block, padding) { var keys = des_createKeys(this.key); return util.str2bin(des(keys, util.bin2str(block), false, 0, null, padding)); - } + }; } module.exports = { @@ -406,4 +406,4 @@ module.exports = { des: Des, /** @static */ originalDes: OriginalDes -} +}; diff --git a/src/crypto/cipher/index.js b/src/crypto/cipher/index.js index 99462457..3d1206ef 100644 --- a/src/crypto/cipher/index.js +++ b/src/crypto/cipher/index.js @@ -10,16 +10,16 @@ var desModule = require('./des.js'); module.exports = { /** @see module:crypto/cipher/des.des */ - des: desModule['des'], + des: desModule.des, /** @see module:crypto/cipher/des.originalDes */ - originalDes: desModule['originalDes'], + originalDes: desModule.originalDes, /** @see module:crypto/cipher/cast5 */ cast5: require('./cast5.js'), /** @see module:crypto/cipher/twofish */ twofish: require('./twofish.js'), /** @see module:crypto/cipher/blowfish */ blowfish: require('./blowfish.js') -} +}; var aes = require('./aes.js'); diff --git a/src/crypto/cipher/twofish.js b/src/crypto/cipher/twofish.js index 5e99834f..fc27b17a 100644 --- a/src/crypto/cipher/twofish.js +++ b/src/crypto/cipher/twofish.js @@ -373,7 +373,7 @@ function TF(key) { this.encrypt = function(block) { return this.tf.encrypt([].concat(block), 0); - } + }; } diff --git a/src/crypto/crypto.js b/src/crypto/crypto.js index 5799cf2c..d6760ba7 100644 --- a/src/crypto/crypto.js +++ b/src/crypto/crypto.js @@ -42,13 +42,14 @@ module.exports = { */ publicKeyEncrypt: function(algo, publicMPIs, data) { var result = (function() { + var m; switch (algo) { case 'rsa_encrypt': case 'rsa_encrypt_sign': var rsa = new publicKey.rsa(); var n = publicMPIs[0].toBigInteger(); var e = publicMPIs[1].toBigInteger(); - var m = data.toBigInteger(); + m = data.toBigInteger(); return [rsa.encrypt(m, e, n)]; case 'elgamal': @@ -56,7 +57,7 @@ module.exports = { var p = publicMPIs[0].toBigInteger(); var g = publicMPIs[1].toBigInteger(); var y = publicMPIs[2].toBigInteger(); - var m = data.toBigInteger(); + m = data.toBigInteger(); return elgamal.encrypt(m, g, p, y); default: @@ -84,6 +85,8 @@ module.exports = { */ publicKeyDecrypt: function(algo, keyIntegers, dataIntegers) { + var p; + var bn = (function() { switch (algo) { case 'rsa_encrypt_sign': @@ -91,7 +94,7 @@ module.exports = { var rsa = new publicKey.rsa(); // 0 and 1 are the public key. var d = keyIntegers[2].toBigInteger(); - var p = keyIntegers[3].toBigInteger(); + p = keyIntegers[3].toBigInteger(); var q = keyIntegers[4].toBigInteger(); var u = keyIntegers[5].toBigInteger(); var m = dataIntegers[0].toBigInteger(); @@ -101,7 +104,7 @@ module.exports = { var x = keyIntegers[3].toBigInteger(); var c1 = dataIntegers[0].toBigInteger(); var c2 = dataIntegers[1].toBigInteger(); - var p = keyIntegers[0].toBigInteger(); + p = keyIntegers[0].toBigInteger(); return elgamal.decrypt(c1, c2, p, x); default: return null; diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index f6b7a97c..7086e037 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -74,7 +74,7 @@ module.exports = { return 32; case 9: // - SHA384 [FIPS180] - return 48 + return 48; case 10: // - SHA512 [FIPS180] return 64; @@ -85,4 +85,4 @@ module.exports = { throw new Error('Invalid hash algorithm.'); } } -} +}; diff --git a/src/crypto/hash/md5.js b/src/crypto/hash/md5.js index 07f70adc..1829aa75 100644 --- a/src/crypto/hash/md5.js +++ b/src/crypto/hash/md5.js @@ -27,7 +27,7 @@ module.exports = function (entree) { var hex = md5(entree); var bin = util.hex2bin(hex); return bin; -} +}; function md5cycle(x, k) { var a = x[0], diff --git a/src/crypto/hash/ripe-md.js b/src/crypto/hash/ripe-md.js index d93ba764..981d5a2c 100644 --- a/src/crypto/hash/ripe-md.js +++ b/src/crypto/hash/ripe-md.js @@ -25,7 +25,7 @@ */ var RMDsize = 160; -var X = new Array(); +var X = []; function ROL(x, n) { return new Number((x << n) | (x >>> (32 - n))); @@ -98,7 +98,7 @@ function mixOneRound(a, b, c, d, e, x, s, roundNumber) { d &= 0xffffffff; e &= 0xffffffff; - var retBlock = new Array(); + var retBlock = []; retBlock[0] = a; retBlock[1] = b; retBlock[2] = c; @@ -145,19 +145,21 @@ var indexes = [ ]; function compress(MDbuf, X) { - blockA = new Array(); - blockB = new Array(); + blockA = []; + blockB = []; var retBlock; - for (var i = 0; i < 5; i++) { + var i, j; + + for (i = 0; i < 5; i++) { blockA[i] = new Number(MDbuf[i]); blockB[i] = new Number(MDbuf[i]); } var step = 0; - for (var j = 0; j < 5; j++) { - for (var i = 0; i < 16; i++) { + for (j = 0; j < 5; j++) { + for (i = 0; i < 16; i++) { retBlock = mixOneRound( blockA[(step + 0) % 5], blockA[(step + 1) % 5], @@ -179,8 +181,8 @@ function compress(MDbuf, X) { } step = 0; - for (var j = 5; j < 10; j++) { - for (var i = 0; i < 16; i++) { + for (j = 5; j < 10; j++) { + for (i = 0; i < 16; i++) { retBlock = mixOneRound( blockB[(step + 0) % 5], blockB[(step + 1) % 5], @@ -228,7 +230,7 @@ function MDfinish(MDbuf, strptr, lswlen, mswlen) { if ((lswlen & 63) > 55) { compress(MDbuf, X); - var X = new Array(16); + X = new Array(16); zeroX(X); } @@ -259,9 +261,9 @@ function RMD(message) { var X = new Array(16); zeroX(X); - var j = 0; - for (var nbytes = length; nbytes > 63; nbytes -= 64) { - for (var i = 0; i < 16; i++) { + var i, j = 0; + for (nbytes = length; nbytes > 63; nbytes -= 64) { + for (i = 0; i < 16; i++) { X[i] = BYTES_TO_DWORD(message.substr(j, 4)); j += 4; } @@ -270,7 +272,7 @@ function RMD(message) { MDfinish(MDbuf, message.substr(j), length, 0); - for (var i = 0; i < RMDsize / 8; i += 4) { + for (i = 0; i < RMDsize / 8; i += 4) { hashcode[i] = MDbuf[i >>> 2] & 255; hashcode[i + 1] = (MDbuf[i >>> 2] >>> 8) & 255; hashcode[i + 2] = (MDbuf[i >>> 2] >>> 16) & 255; diff --git a/src/crypto/hash/sha.js b/src/crypto/hash/sha.js index f77b7efb..58c2ba13 100644 --- a/src/crypto/hash/sha.js +++ b/src/crypto/hash/sha.js @@ -99,7 +99,7 @@ var jsSHA = (function() { * * @private * @param {Array} binarray Array of integers to be converted to hexidecimal - * representation + * representation * @return Hexidecimal representation of the parameter in String form */ binb2hex = function(binarray) { @@ -122,7 +122,7 @@ var jsSHA = (function() { * * @private * @param {Array} binarray Array of integers to be converted to base-64 - * representation + * representation * @return Base-64 encoded representation of the parameter in String form */ binb2b64 = function(binarray) { @@ -562,7 +562,7 @@ var jsSHA = (function() { * * @private * @param {Array} message The binary array representation of the string to - * hash + * hash * @param {Number} messageLen The number of bits in the message * @return The array of integers representing the SHA-1 hash of message */ @@ -915,7 +915,7 @@ var jsSHA = (function() { * using the specified parameters * * @param {String} variant The desired SHA variant (SHA-1, SHA-224, - * SHA-256, SHA-384, or SHA-512) + * SHA-256, SHA-384, or SHA-512) * @param {String} format The desired output formatting (B64 or HEX) * @return The string representation of the hash in the format specified */ @@ -975,9 +975,9 @@ var jsSHA = (function() { * @param {String} key The key used to calculate the HMAC * @param {String} inputFormat The format of key, ASCII or HEX * @param {String} variant The desired SHA variant (SHA-1, SHA-224, - * SHA-256, SHA-384, or SHA-512) + * SHA-256, SHA-384, or SHA-512) * @param {String} outputFormat The desired output formatting - * (B64 or HEX) + * (B64 or HEX) * @return The string representation of the hash in the format specified */ getHMAC: function(key, inputFormat, variant, outputFormat) { @@ -1122,4 +1122,4 @@ module.exports = { var shaObj = new jsSHA(str, "ASCII"); return shaObj.getHash("SHA-512", "ASCII"); } -} +}; diff --git a/src/crypto/index.js b/src/crypto/index.js index ac1ddb79..88a7e0aa 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -17,8 +17,7 @@ module.exports = { random: require('./random.js'), /** @see module:crypto/pkcs1 */ pkcs1: require('./pkcs1.js') - -} +}; var crypto = require('./crypto.js'); diff --git a/src/crypto/pkcs1.js b/src/crypto/pkcs1.js index 86838366..330da878 100644 --- a/src/crypto/pkcs1.js +++ b/src/crypto/pkcs1.js @@ -28,7 +28,7 @@ /** * ASN1 object identifiers for hashes (See RFC4880 5.2.2) */ -hash_headers = new Array(); +hash_headers = []; hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 ]; @@ -83,10 +83,10 @@ module.exports = { decode: function(message, len) { if (message.length < len) message = String.fromCharCode(0) + message; - if (message.length < 12 || message.charCodeAt(0) != 0 || message.charCodeAt(1) != 2) + if (message.length < 12 || message.charCodeAt(0) !== 0 || message.charCodeAt(1) != 2) return -1; var i = 2; - while (message.charCodeAt(i) != 0 && message.length > i) + while (message.charCodeAt(i) !== 0 && message.length > i) i++; return message.substring(i + 1, message.length); } @@ -105,14 +105,15 @@ module.exports = { var data2 = ""; data2 += String.fromCharCode(0x00); data2 += String.fromCharCode(0x01); - for (var i = 0; i < (keylength - hash_headers[algo].length - 3 - + var i; + for (i = 0; i < (keylength - hash_headers[algo].length - 3 - hash.getHashByteLength(algo)); i++) data2 += String.fromCharCode(0xff); data2 += String.fromCharCode(0x00); - for (var i = 0; i < hash_headers[algo].length; i++) + for (i = 0; i < hash_headers[algo].length; i++) data2 += String.fromCharCode(hash_headers[algo][i]); data2 += hash.digest(algo, data); @@ -126,12 +127,12 @@ module.exports = { */ decode: function(algo, data) { var i = 0; - if (data.charCodeAt(0) == 0) i++; + if (data.charCodeAt(0) === 0) i++; else if (data.charCodeAt(0) != 1) return -1; else i++; while (data.charCodeAt(i) == 0xFF) i++; - if (data.charCodeAt(i++) != 0) return -1; + if (data.charCodeAt(i++) !== 0) return -1; var j = 0; for (j = 0; j < hash_headers[algo].length && j + i < data.length; j++) { if (data.charCodeAt(j + i) != hash_headers[algo][j]) return -1; @@ -141,4 +142,4 @@ module.exports = { return data.substring(i); } } -} +}; diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index d488e3dc..d9791096 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -45,7 +45,7 @@ function DSA() { var k = random.getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE), q.subtract(BigInteger.ONE)); var s1 = (g.modPow(k, p)).mod(q); var s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q); - var result = new Array(); + var result = []; result[0] = s1.toMPI(); result[1] = s2.toMPI(); return result; @@ -108,61 +108,61 @@ function DSA() { * unused code. This can be used as a start to write a key generator * function. - function generateKey(bitcount) { - var qi = new BigInteger(bitcount, primeCenterie); - var pi = generateP(q, 512); - var gi = generateG(p, q, bitcount); - var xi; - do { - xi = new BigInteger(q.bitCount(), rand); - } while (x.compareTo(BigInteger.ZERO) != 1 && x.compareTo(q) != -1); - var yi = g.modPow(x, p); - return {x: xi, q: qi, p: pi, g: gi, y: yi}; - } + function generateKey(bitcount) { + var qi = new BigInteger(bitcount, primeCenterie); + var pi = generateP(q, 512); + var gi = generateG(p, q, bitcount); + var xi; + do { + xi = new BigInteger(q.bitCount(), rand); + } while (x.compareTo(BigInteger.ZERO) != 1 && x.compareTo(q) != -1); + var yi = g.modPow(x, p); + return {x: xi, q: qi, p: pi, g: gi, y: yi}; + } - function generateP(q, bitlength, randomfn) { - if (bitlength % 64 != 0) { - return false; - } - var pTemp; - var pTemp2; - do { - pTemp = randomfn(bitcount, true); - pTemp2 = pTemp.subtract(BigInteger.ONE); - pTemp = pTemp.subtract(pTemp2.remainder(q)); - } while (!pTemp.isProbablePrime(primeCenterie) || pTemp.bitLength() != l); - return pTemp; - } + function generateP(q, bitlength, randomfn) { + if (bitlength % 64 != 0) { + return false; + } + var pTemp; + var pTemp2; + do { + pTemp = randomfn(bitcount, true); + pTemp2 = pTemp.subtract(BigInteger.ONE); + pTemp = pTemp.subtract(pTemp2.remainder(q)); + } while (!pTemp.isProbablePrime(primeCenterie) || pTemp.bitLength() != l); + return pTemp; + } - function generateG(p, q, bitlength, randomfn) { - var aux = p.subtract(BigInteger.ONE); - var pow = aux.divide(q); - var gTemp; - do { - gTemp = randomfn(bitlength); - } while (gTemp.compareTo(aux) != -1 && gTemp.compareTo(BigInteger.ONE) != 1); - return gTemp.modPow(pow, p); - } + function generateG(p, q, bitlength, randomfn) { + var aux = p.subtract(BigInteger.ONE); + var pow = aux.divide(q); + var gTemp; + do { + gTemp = randomfn(bitlength); + } while (gTemp.compareTo(aux) != -1 && gTemp.compareTo(BigInteger.ONE) != 1); + return gTemp.modPow(pow, p); + } - function generateK(q, bitlength, randomfn) { - var tempK; - do { - tempK = randomfn(bitlength, false); - } while (tempK.compareTo(q) != -1 && tempK.compareTo(BigInteger.ZERO) != 1); - return tempK; - } + function generateK(q, bitlength, randomfn) { + var tempK; + do { + tempK = randomfn(bitlength, false); + } while (tempK.compareTo(q) != -1 && tempK.compareTo(BigInteger.ZERO) != 1); + return tempK; + } - function generateR(q,p) { - k = generateK(q); - var r = g.modPow(k, p).mod(q); - return r; - } + function generateR(q,p) { + k = generateK(q); + var r = g.modPow(k, p).mod(q); + return r; + } - function generateS(hashfn,k,r,m,q,x) { - var hash = hashfn(m); - s = (k.modInverse(q).multiply(hash.add(x.multiply(r)))).mod(q); - return s; - } */ + function generateS(hashfn,k,r,m,q,x) { + var hash = hashfn(m); + s = (k.modInverse(q).multiply(hash.add(x.multiply(r)))).mod(q); + return s; + } */ this.sign = sign; this.verify = verify; // this.generate = generateKey; diff --git a/src/crypto/public_key/index.js b/src/crypto/public_key/index.js index beafaf9f..fa4dd2d1 100644 --- a/src/crypto/public_key/index.js +++ b/src/crypto/public_key/index.js @@ -11,4 +11,4 @@ module.exports = { elgamal: require('./elgamal.js'), /** @see module:crypto/public_key/dsa */ dsa: require('./dsa.js') -} +}; diff --git a/src/crypto/public_key/jsbn.js b/src/crypto/public_key/jsbn.js index 845fd44a..84e9fe80 100644 --- a/src/crypto/public_key/jsbn.js +++ b/src/crypto/public_key/jsbn.js @@ -51,9 +51,9 @@ var j_lm = ((canary & 0xffffff) == 0xefcafe); // (public) Constructor function BigInteger(a, b, c) { - if (a != null) + if (a !== null) if ("number" == typeof a) this.fromNumber(a, b, c); - else if (b == null && "string" != typeof a) this.fromString(a, 256); + else if (b === null && "string" != typeof a) this.fromString(a, 256); else this.fromString(a, b); } @@ -138,7 +138,7 @@ BigInteger.prototype.F2 = 2 * dbits - BI_FP; // Digit conversions var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; -var BI_RC = new Array(); +var BI_RC = []; var rr, vv; rr = "0".charCodeAt(0); for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; @@ -153,7 +153,7 @@ function int2char(n) { function intAt(s, i) { var c = BI_RC[s.charCodeAt(i)]; - return (c == null) ? -1 : c; + return (c === null) ? -1 : c; } // (protected) copy this to r @@ -208,7 +208,7 @@ function bnpFromString(s, b) { continue; } mi = false; - if (sh == 0) + if (sh === 0) this[this.t++] = x; else if (sh + k > this.DB) { this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh; @@ -218,7 +218,7 @@ function bnpFromString(s, b) { sh += k; if (sh >= this.DB) sh -= this.DB; } - if (k == 8 && (s[0] & 0x80) != 0) { + if (k == 8 && (s[0] & 0x80) !== 0) { this.s = -1; if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh; } @@ -290,11 +290,11 @@ function bnAbs() { function bnCompareTo(a) { var r = this.s - a.s; - if (r != 0) return r; + if (r !== 0) return r; var i = this.t; r = i - a.t; - if (r != 0) return r; - while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r; + if (r !== 0) return r; + while (--i >= 0) if ((r = this[i] - a[i]) !== 0) return r; return 0; } @@ -303,23 +303,23 @@ function bnCompareTo(a) { function nbits(x) { var r = 1, t; - if ((t = x >>> 16) != 0) { + if ((t = x >>> 16) !== 0) { x = t; r += 16; } - if ((t = x >> 8) != 0) { + if ((t = x >> 8) !== 0) { x = t; r += 8; } - if ((t = x >> 4) != 0) { + if ((t = x >> 4) !== 0) { x = t; r += 4; } - if ((t = x >> 2) != 0) { + if ((t = x >> 2) !== 0) { x = t; r += 2; } - if ((t = x >> 1) != 0) { + if ((t = x >> 1) !== 0) { x = t; r += 1; } @@ -469,11 +469,11 @@ function bnpDivRemTo(m, q, r) { if (pm.t <= 0) return; var pt = this.abs(); if (pt.t < pm.t) { - if (q != null) q.fromInt(0); - if (r != null) this.copyTo(r); + if (q !== null) q.fromInt(0); + if (r !== null) this.copyTo(r); return; } - if (r == null) r = nbi(); + if (r === null) r = nbi(); var y = nbi(), ts = this.s, ms = m.s; @@ -487,14 +487,14 @@ function bnpDivRemTo(m, q, r) { } var ys = y.t; var y0 = y[ys - 1]; - if (y0 == 0) return; + if (y0 === 0) return; var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0); var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2; var i = r.t, j = i - ys, - t = (q == null) ? nbi() : q; + t = (q === null) ? nbi() : q; y.dlShiftTo(j, t); if (r.compareTo(t) >= 0) { r[r.t++] = 1; @@ -512,7 +512,7 @@ function bnpDivRemTo(m, q, r) { while (r[i] < --qd) r.subTo(t, r); } } - if (q != null) { + if (q !== null) { r.drShiftTo(ys, q); if (ts != ms) BigInteger.ZERO.subTo(q, q); } @@ -580,7 +580,7 @@ Classic.prototype.sqrTo = cSqrTo; function bnpInvDigit() { if (this.t < 1) return 0; var x = this[0]; - if ((x & 1) == 0) return 0; + if ((x & 1) === 0) return 0; var y = x & 3; // y == 1/x mod 2^2 y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 @@ -668,7 +668,7 @@ Montgomery.prototype.sqrTo = montSqrTo; // (protected) true iff this is even function bnpIsEven() { - return ((this.t > 0) ? (this[0] & 1) : this.s) == 0; + return ((this.t > 0) ? (this[0] & 1) : this.s) === 0; } // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) @@ -802,9 +802,9 @@ function bnClone() { function bnIntValue() { if (this.s < 0) { if (this.t == 1) return this[0] - this.DV; - else if (this.t == 0) return -1; + else if (this.t === 0) return -1; } else if (this.t == 1) return this[0]; - else if (this.t == 0) return 0; + else if (this.t === 0) return 0; // assumes 16 < DB < 32 return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]; } @@ -812,13 +812,13 @@ function bnIntValue() { // (public) return value as byte function bnByteValue() { - return (this.t == 0) ? this.s : (this[0] << 24) >> 24; + return (this.t === 0) ? this.s : (this[0] << 24) >> 24; } // (public) return value as short (assumes DB>=16) function bnShortValue() { - return (this.t == 0) ? this.s : (this[0] << 16) >> 16; + return (this.t === 0) ? this.s : (this[0] << 16) >> 16; } // (protected) return x s.t. r^x < DV @@ -838,8 +838,8 @@ function bnSigNum() { // (protected) convert to radix string function bnpToRadix(b) { - if (b == null) b = 10; - if (this.signum() == 0 || b < 2 || b > 36) return "0"; + if (b === null) b = 10; + if (this.signum() === 0 || b < 2 || b > 36) return "0"; var cs = this.chunkSize(b); var a = Math.pow(b, cs); var d = nbv(a), @@ -858,7 +858,7 @@ function bnpToRadix(b) { function bnpFromRadix(s, b) { this.fromInt(0); - if (b == null) b = 10; + if (b === null) b = 10; var cs = this.chunkSize(b); var d = Math.pow(b, cs), mi = false, @@ -867,7 +867,7 @@ function bnpFromRadix(s, b) { for (var i = 0; i < s.length; ++i) { var x = intAt(s, i); if (x < 0) { - if (s.charAt(i) == "-" && this.signum() == 0) mi = true; + if (s.charAt(i) == "-" && this.signum() === 0) mi = true; continue; } w = b * w + x; @@ -903,7 +903,7 @@ function bnpFromNumber(a, b, c) { } } else { // new BigInteger(int,RNG) - var x = new Array(), + var x = [], t = a & 7; x.length = (a >> 3) + 1; b.nextBytes(x); @@ -917,7 +917,7 @@ function bnpFromNumber(a, b, c) { function bnToByteArray() { var i = this.t, - r = new Array(); + r = []; r[0] = this.s; var p = this.DB - (i * this.DB) % 8, d, k = 0; @@ -944,7 +944,7 @@ function bnToByteArray() { } function bnEquals(a) { - return (this.compareTo(a) == 0); + return (this.compareTo(a) === 0); } function bnMin(a) { @@ -1052,25 +1052,25 @@ function bnShiftRight(n) { // return index of lowest 1-bit in x, x < 2^31 function lbit(x) { - if (x == 0) return -1; + if (x === 0) return -1; var r = 0; - if ((x & 0xffff) == 0) { + if ((x & 0xffff) === 0) { x >>= 16; r += 16; } - if ((x & 0xff) == 0) { + if ((x & 0xff) === 0) { x >>= 8; r += 8; } - if ((x & 0xf) == 0) { + if ((x & 0xf) === 0) { x >>= 4; r += 4; } - if ((x & 3) == 0) { + if ((x & 3) === 0) { x >>= 2; r += 2; } - if ((x & 1) == 0)++r; + if ((x & 1) === 0)++r; return r; } @@ -1078,7 +1078,7 @@ function lbit(x) { function bnGetLowestSetBit() { for (var i = 0; i < this.t; ++i) - if (this[i] != 0) return i * this.DB + lbit(this[i]); + if (this[i] !== 0) return i * this.DB + lbit(this[i]); if (this.s < 0) return this.t * this.DB; return -1; } @@ -1087,7 +1087,7 @@ function bnGetLowestSetBit() { function cbit(x) { var r = 0; - while (x != 0) { + while (x !== 0) { x &= x - 1; ++r; } @@ -1107,8 +1107,8 @@ function bnBitCount() { function bnTestBit(n) { var j = Math.floor(n / this.DB); - if (j >= this.t) return (this.s != 0); - return ((this[j] & (1 << (n % this.DB))) != 0); + if (j >= this.t) return (this.s !== 0); + return ((this[j] & (1 << (n % this.DB))) !== 0); } // (protected) this op (1<= 0 function bnpDAddOffset(n, w) { - if (n == 0) return; + if (n === 0) return; while (this.t <= w) this[this.t++] = 0; this[w] += n; while (this[w] >= this.DV) { @@ -1386,7 +1386,7 @@ function bnModPow(e, m) { z = new Montgomery(m); // precomputation - var g = new Array(), + var g = [], n = 3, k1 = k - 1, km = (1 << k) - 1; @@ -1414,7 +1414,7 @@ function bnModPow(e, m) { } n = k; - while ((w & 1) == 0) { + while ((w & 1) === 0) { w >>= 1; --n; } @@ -1440,7 +1440,7 @@ function bnModPow(e, m) { z.mulTo(r2, g[w], r); } - while (j >= 0 && (e[j] & (1 << i)) == 0) { + while (j >= 0 && (e[j] & (1 << i)) === 0) { z.sqrTo(r, r2); t = r; r = r2; @@ -1494,7 +1494,7 @@ function bnpModInt(n) { var d = this.DV % n, r = (this.s < 0) ? n - 1 : 0; if (this.t > 0) - if (d == 0) r = this[0] % n; + if (d === 0) r = this[0] % n; else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n; return r; } @@ -1503,14 +1503,14 @@ function bnpModInt(n) { function bnModInverse(m) { var ac = m.isEven(); - if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; + if ((this.isEven() && ac) || m.signum() === 0) return BigInteger.ZERO; var u = m.clone(), v = this.clone(); var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); - while (u.signum() != 0) { + while (u.signum() !== 0) { while (u.isEven()) { u.rShiftTo(1, u); if (ac) { @@ -1543,7 +1543,7 @@ function bnModInverse(m) { d.subTo(b, d); } } - if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; + if (v.compareTo(BigInteger.ONE) !== 0) return BigInteger.ZERO; if (d.compareTo(m) >= 0) return d.subtract(m); if (d.signum() < 0) d.addTo(m, d); else return d; @@ -1578,7 +1578,7 @@ function bnIsProbablePrime(t) { j = i + 1; while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]; m = x.modInt(m); - while (i < j) if (m % lowprimes[i++] == 0) return false; + while (i < j) if (m % lowprimes[i++] === 0) return false; } return x.millerRabin(t); } @@ -1588,23 +1588,23 @@ function bnIsProbablePrime(t) { function nbits(x) { var n = 1, t; - if ((t = x >>> 16) != 0) { + if ((t = x >>> 16) !== 0) { x = t; n += 16; } - if ((t = x >> 8) != 0) { + if ((t = x >> 8) !== 0) { x = t; n += 8; } - if ((t = x >> 4) != 0) { + if ((t = x >> 4) !== 0) { x = t; n += 4; } - if ((t = x >> 2) != 0) { + if ((t = x >> 2) !== 0) { x = t; n += 2; } - if ((t = x >> 1) != 0) { + if ((t = x >> 1) !== 0) { x = t; n += 1; } @@ -1641,13 +1641,13 @@ function bnpMillerRabin(t) { bases.push(j); a.fromInt(j); var y = a.modPow(r, this); - if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while (j++ < k && y.compareTo(n1) != 0) { + if (y.compareTo(BigInteger.ONE) !== 0 && y.compareTo(n1) !== 0) { + j = 1; + while (j++ < k && y.compareTo(n1) !== 0) { y = y.modPowInt(2, this); - if (y.compareTo(BigInteger.ONE) == 0) return false; + if (y.compareTo(BigInteger.ONE) === 0) return false; } - if (y.compareTo(n1) != 0) return false; + if (y.compareTo(n1) !== 0) return false; } } return true; diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 3338238e..f6d48f3f 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -58,7 +58,7 @@ function RSA() { util.print_debug("rsa.js decrypt\nxpn:" + util.hexstrdump(xp.toMPI()) + "\nxqn:" + util.hexstrdump(xq.toMPI())); var t = xq.subtract(xp); - if (t[0] == 0) { + if (t[0] === 0) { t = xp.subtract(xq); t = t.multiply(u).mod(q); t = q.subtract(t); @@ -113,12 +113,12 @@ function RSA() { for (;;) { for (;;) { key.p = new BigInteger(B - qs, 1, rng); - if (key.p.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) == 0 && key.p.isProbablePrime(10)) + if (key.p.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.p.isProbablePrime(10)) break; } for (;;) { key.q = new BigInteger(qs, 1, rng); - if (key.q.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) == 0 && key.q.isProbablePrime(10)) + if (key.q.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.q.isProbablePrime(10)) break; } if (key.p.compareTo(key.q) <= 0) { @@ -129,7 +129,7 @@ function RSA() { var p1 = key.p.subtract(BigInteger.ONE); var q1 = key.q.subtract(BigInteger.ONE); var phi = p1.multiply(q1); - if (phi.gcd(key.ee).compareTo(BigInteger.ONE) == 0) { + if (phi.gcd(key.ee).compareTo(BigInteger.ONE) === 0) { key.n = key.p.multiply(key.q); key.d = key.ee.modInverse(phi); key.dmp1 = key.d.mod(p1); diff --git a/src/crypto/signature.js b/src/crypto/signature.js index 5d51c374..930d7baa 100644 --- a/src/crypto/signature.js +++ b/src/crypto/signature.js @@ -20,6 +20,7 @@ module.exports = { */ verify: function(algo, hash_algo, msg_MPIs, publickey_MPIs, data) { var calc_hash = hashModule.digest(hash_algo, data); + var dopublic; switch (algo) { case 1: @@ -32,7 +33,7 @@ module.exports = { var n = publickey_MPIs[0].toBigInteger(); var e = publickey_MPIs[1].toBigInteger(); var x = msg_MPIs[0].toBigInteger(); - var dopublic = rsa.verify(x, e, n); + dopublic = rsa.verify(x, e, n); var hash = pkcs1.emsa.decode(hash_algo, dopublic.toMPI().substring(2)); if (hash == -1) { throw new Error('PKCS1 padding in message or key incorrect. Aborting...'); @@ -52,12 +53,11 @@ module.exports = { var g = publickey_MPIs[2].toBigInteger(); var y = publickey_MPIs[3].toBigInteger(); var m = data; - var dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y); - return dopublic.compareTo(s1) == 0; + dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y); + return dopublic.compareTo(s1) === 0; default: throw new Error('Invalid signature algorithm.'); } - }, /** @@ -73,6 +73,8 @@ module.exports = { */ sign: function(hash_algo, algo, keyIntegers, data) { + var m; + switch (algo) { case 1: // RSA (Encrypt or Sign) [HAC] @@ -83,7 +85,7 @@ module.exports = { var rsa = new publicKey.rsa(); var d = keyIntegers[2].toBigInteger(); var n = keyIntegers[0].toBigInteger(); - var m = pkcs1.emsa.encode(hash_algo, + m = pkcs1.emsa.encode(hash_algo, data, keyIntegers[0].byteLength()); return rsa.sign(m, d, n).toMPI(); @@ -97,7 +99,7 @@ module.exports = { var g = keyIntegers[2].toBigInteger(); var y = keyIntegers[3].toBigInteger(); var x = keyIntegers[4].toBigInteger(); - var m = data; + m = data; var result = dsa.sign(hash_algo, m, g, p, q, x); return result[0].toString() + result[1].toString(); @@ -108,4 +110,4 @@ module.exports = { throw new Error('Invalid signature algorithm.'); } } -} +}; diff --git a/src/encoding/armor.js b/src/encoding/armor.js index 11efddae..a2136f9e 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -213,7 +213,7 @@ function splitHeaders(text) { var matchResult = reEmptyLine.exec(text); - if (matchResult != null) { + if (matchResult !== null) { headers = text.slice(0, matchResult.index); body = text.slice(matchResult.index + matchResult[0].length); } @@ -235,7 +235,7 @@ function splitChecksum(text) { var matchResult = reChecksumStart.exec(text); - if (matchResult != null) { + if (matchResult !== null) { body = text.slice(0, matchResult.index); checksum = text.slice(matchResult.index + 1); } @@ -268,14 +268,14 @@ function dearmor(text) { // so we know the index of the data we are interested in. var indexBase = 1; - var result, checksum; + var result, checksum, msg; if (text.search(reSplit) != splittext[0].length) { indexBase = 0; } if (type != 2) { - var msg = splitHeaders(splittext[indexBase]); + msg = splitHeaders(splittext[indexBase]); var msg_sum = splitChecksum(msg.body); result = { @@ -286,7 +286,7 @@ function dearmor(text) { checksum = msg_sum.checksum; } else { // Reverse dash-escaping for msg and remove trailing whitespace at end of line - var msg = splitHeaders(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n")); + msg = splitHeaders(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n")); var sig = splitHeaders(splittext[indexBase + 1].replace(/^- /mg, '')); var sig_sum = splitChecksum(sig.body); @@ -300,10 +300,10 @@ function dearmor(text) { } if (!verifyCheckSum(result.data, checksum)) { - throw new Error("Ascii armor integrity check on message failed: '" - + checksum - + "' should be '" - + getCheckSum(result) + "'"); + throw new Error("Ascii armor integrity check on message failed: '" + + checksum + + "' should be '" + + getCheckSum(result) + "'"); } else { return result; } diff --git a/src/encoding/base64.js b/src/encoding/base64.js index e88b9d14..59bd512d 100644 --- a/src/encoding/base64.js +++ b/src/encoding/base64.js @@ -32,7 +32,7 @@ function s2r(t) { for (n = 0; n < tl; n++) { c = t.charCodeAt(n); - if (s == 0) { + if (s === 0) { r += b64s.charAt((c >> 2) & 63); a = (c & 3) << 4; } else if (s == 1) { @@ -41,12 +41,12 @@ function s2r(t) { } else if (s == 2) { r += b64s.charAt(a | ((c >> 6) & 3)); l += 1; - if ((l % 60) == 0) + if ((l % 60) === 0) r += "\n"; r += b64s.charAt(c & 63); } l += 1; - if ((l % 60) == 0) + if ((l % 60) === 0) r += "\n"; s += 1; @@ -56,13 +56,13 @@ function s2r(t) { if (s > 0) { r += b64s.charAt(a); l += 1; - if ((l % 60) == 0) + if ((l % 60) === 0) r += "\n"; r += '='; l += 1; } if (s == 1) { - if ((l % 60) == 0) + if ((l % 60) === 0) r += "\n"; r += '='; } @@ -98,4 +98,4 @@ function r2s(t) { module.exports = { encode: s2r, decode: r2s -} +}; diff --git a/src/enums.js b/src/enums.js index ccb995dd..97ab8f99 100644 --- a/src/enums.js +++ b/src/enums.js @@ -314,4 +314,4 @@ module.exports = { throw new Error('Invalid enum value.'); } -} +}; diff --git a/src/key.js b/src/key.js index 11b4c9a2..ddea303e 100644 --- a/src/key.js +++ b/src/key.js @@ -128,11 +128,12 @@ Key.prototype.toPacketlist = function() { packetlist.push(this.primaryKey); packetlist.push(this.revocationSignature); packetlist.concat(this.directSignatures); - for (var i = 0; i < this.users.length; i++) { + var i; + for (i = 0; i < this.users.length; i++) { packetlist.concat(this.users[i].toPacketlist()); } if (this.subKeys) { - for (var i = 0; i < this.subKeys.length; i++) { + for (i = 0; i < this.subKeys.length; i++) { packetlist.concat(this.subKeys[i].toPacketlist()); } } @@ -257,16 +258,17 @@ Key.prototype.isPrivate = function() { Key.prototype.toPublic = function() { var packetlist = new packet.list(); var keyPackets = this.toPacketlist(); + var bytes; for (var i = 0; i < keyPackets.length; i++) { switch (keyPackets[i].tag) { case enums.packet.secret_key: - var bytes = keyPackets[i].writePublicKey(); + bytes = keyPackets[i].writePublicKey(); var pubKeyPacket = new packet.public_key(); pubKeyPacket.read(bytes); packetlist.push(pubKeyPacket); break; case enums.packet.secret_subkey: - var bytes = keyPackets[i].writePublicKey(); + bytes = keyPackets[i].writePublicKey(); var pubSubkeyPacket = new packet.public_subkey(); pubSubkeyPacket.read(bytes); packetlist.push(pubSubkeyPacket); @@ -328,7 +330,7 @@ function isValidEncryptionKeyPacket(keyPacket, signature) { ((signature.keyFlags & enums.keyFlags.encrypt_communication) !== 0 || (signature.keyFlags & enums.keyFlags.encrypt_storage) !== 0 || !signature.keyFlags); -}; +} function isValidSigningKeyPacket(keyPacket, signature) { return (keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.dsa) || @@ -336,7 +338,7 @@ function isValidSigningKeyPacket(keyPacket, signature) { keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_encrypt_sign)) && ((signature.keyFlags & enums.keyFlags.sign_data) !== 0 || !signature.keyFlags); -}; +} /** * Returns the first valid encryption key packet for this key @@ -469,7 +471,7 @@ Key.prototype.getPrimaryUser = function() { } } return user ? {user: user, selfCertificate: userSelfCert} : null; -} +}; // TODO Key.prototype.revoke = function() { @@ -485,7 +487,7 @@ function User(userPacket) { return new User(userPacket); } this.userId = userPacket.tag == enums.packet.userid ? userPacket : null; - this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null + this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null; this.selfCertifications = null; this.otherCertifications = null; this.revocationCertifications = null; @@ -683,8 +685,8 @@ function readArmored(armoredText) { var packetlist = new packet.list(); packetlist.read(input.data); var keyIndex = packetlist.indexOfTag(enums.packet.public_key, enums.packet.secret_key); - if (keyIndex.length == 0) { - throw new Error('No key packet found in armored text') + if (keyIndex.length === 0) { + throw new Error('No key packet found in armored text'); } for (var i = 0; i < keyIndex.length; i++) { var oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]); diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js index 48e329a7..4fc1fd8b 100644 --- a/src/keyring/localstore.js +++ b/src/keyring/localstore.js @@ -39,7 +39,7 @@ module.exports = function () { } } return keys; - } + }; /** * Saves the current state of the keyring to HTML5 local storage. @@ -52,5 +52,5 @@ module.exports = function () { armoredKeys.push(keys[i].armor()); } window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys)); - } + }; }; diff --git a/src/message.js b/src/message.js index cf4b5f38..f2c9dfae 100644 --- a/src/message.js +++ b/src/message.js @@ -184,10 +184,10 @@ Message.prototype.sign = function(privateKeys) { if (!literalDataPacket) throw new Error('No literal data packet to sign.'); var literalFormat = enums.write(enums.literal, literalDataPacket.format); - var signatureType = literalFormat == enums.literal.binary - ? enums.signature.binary : enums.signature.text; - - for (var i = 0; i < privateKeys.length; i++) { + var signatureType = literalFormat == enums.literal.binary ? + enums.signature.binary : enums.signature.text; + var i; + for (i = 0; i < privateKeys.length; i++) { var onePassSig = new packet.one_pass_signature(); onePassSig.type = signatureType; //TODO get preferred hashg algo from key signature @@ -203,7 +203,7 @@ Message.prototype.sign = function(privateKeys) { packetlist.push(literalDataPacket); - for (var i = privateKeys.length - 1; i >= 0; i--) { + for (i = privateKeys.length - 1; i >= 0; i--) { var signaturePacket = new packet.signature(); signaturePacket.signatureType = signatureType; signaturePacket.hashAlgorithm = config.prefer_hash_algorithm; diff --git a/src/openpgp.js b/src/openpgp.js index 9463d407..a3308eac 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -158,7 +158,7 @@ function generateKeyPair(keyType, numBits, userId, passphrase) { exports.encryptMessage = encryptMessage; exports.signAndEncryptMessage = signAndEncryptMessage; exports.decryptMessage = decryptMessage; -exports.decryptAndVerifyMessage = decryptAndVerifyMessage +exports.decryptAndVerifyMessage = decryptAndVerifyMessage; exports.signClearMessage = signClearMessage; exports.verifyClearSignedMessage = verifyClearSignedMessage; exports.generateKeyPair = generateKeyPair; diff --git a/src/packet/all_packets.js b/src/packet/all_packets.js index 8d7207c8..c85c7851 100644 --- a/src/packet/all_packets.js +++ b/src/packet/all_packets.js @@ -39,11 +39,11 @@ module.exports = { signature: require('./signature.js'), /** @see module:packet/trust */ trust: require('./trust.js') -} +}; for (var i in enums.packet) { var packetClass = module.exports[i]; - if (packetClass != undefined) + if (packetClass !== undefined) packetClass.prototype.tag = enums.packet[i]; } diff --git a/src/packet/compressed.js b/src/packet/compressed.js index 61ab6e10..f11732c8 100644 --- a/src/packet/compressed.js +++ b/src/packet/compressed.js @@ -65,7 +65,7 @@ module.exports = function () { this.compressed = bytes.substr(1); this.decompress(); - } + }; @@ -74,11 +74,11 @@ module.exports = function () { * @return {String} binary compressed packet */ this.write = function() { - if (this.compressed == null) + if (this.compressed === null) this.compress(); return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed; - } + }; /** @@ -86,7 +86,7 @@ module.exports = function () { * read by read_packet */ this.decompress = function() { - var decompressed; + var decompressed, compdata, radix; switch (this.algorithm) { case 'uncompressed': @@ -94,9 +94,9 @@ module.exports = function () { break; case 'zip': - var compData = this.compressed; + compData = this.compressed; - var radix = base64.encode(compData).replace(/\n/g, ""); + radix = base64.encode(compData).replace(/\n/g, ""); // no header in this case, directly call deflate var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix)); @@ -113,8 +113,8 @@ module.exports = function () { if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951 // remove 4 bytes ADLER32 checksum from the end - var compData = this.compressed.substring(0, this.compressed.length - 4); - var radix = base64.encode(compData).replace(/\n/g, ""); + compData = this.compressed.substring(0, this.compressed.length - 4); + radix = base64.encode(compData).replace(/\n/g, ""); //TODO check ADLER32 checksum decompressed = JXG.decompress(radix); break; @@ -128,15 +128,13 @@ module.exports = function () { case 'bzip2': // TODO: need to implement this throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.'); - break; default: throw new Error("Compression algorithm unknown :" + this.alogrithm); - break; } this.packets.read(decompressed); - } + }; /** * Compress the packet data (member decompressedData) @@ -152,23 +150,19 @@ module.exports = function () { case 'zip': // - ZIP [RFC1951] throw new Error("Compression algorithm ZIP [RFC1951] is not implemented."); - break; case 'zlib': // - ZLIB [RFC1950] // TODO: need to implement this throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented."); - break; case 'bzip2': // - BZip2 [BZ2] // TODO: need to implement this throw new Error("Compression algorithm BZip2 [BZ2] is not implemented."); - break; default: throw new Error("Compression algorithm unknown :" + this.type); - break; } - } + }; }; diff --git a/src/packet/literal.js b/src/packet/literal.js index a9455eae..21d24678 100644 --- a/src/packet/literal.js +++ b/src/packet/literal.js @@ -47,7 +47,7 @@ module.exports = function () { text = text.replace(/\r/g, '').replace(/\n/g, '\r\n'); // encode UTF8 this.data = this.format == 'utf8' ? util.encode_utf8(text) : text; - } + }; /** * Returns literal data packets as native JavaScript string @@ -59,7 +59,7 @@ module.exports = function () { var text = util.decode_utf8(this.data); // normalize EOL to \n return text.replace(/\r\n/g, '\n'); - } + }; /** * Set the packet data to value represented by the provided string of bytes. @@ -69,7 +69,7 @@ module.exports = function () { this.setBytes = function(bytes, format) { this.format = format; this.data = bytes; - } + }; /** @@ -78,7 +78,7 @@ module.exports = function () { */ this.getBytes = function() { return this.data; - } + }; /** @@ -105,7 +105,7 @@ module.exports = function () { var data = bytes.substring(6 + filename_len); this.setBytes(data, format); - } + }; /** * Creates a string representation of the packet @@ -125,5 +125,5 @@ module.exports = function () { result += util.writeDate(this.date); result += data; return result; - } -} + }; +}; diff --git a/src/packet/marker.js b/src/packet/marker.js index d9f2f35e..70eff073 100644 --- a/src/packet/marker.js +++ b/src/packet/marker.js @@ -50,5 +50,5 @@ module.exports = function () { return true; // marker packet does not contain "PGP" return false; - } -} + }; +}; diff --git a/src/packet/one_pass_signature.js b/src/packet/one_pass_signature.js index 12b056d5..52233559 100644 --- a/src/packet/one_pass_signature.js +++ b/src/packet/one_pass_signature.js @@ -74,7 +74,7 @@ module.exports = function () { // signature to be applied to the same message data. this.flags = bytes.charCodeAt(mypos++); return this; - } + }; /** * creates a string representation of a one-pass signature packet @@ -91,5 +91,5 @@ module.exports = function () { result += String.fromCharCode(this.flags); return result; - } + }; }; diff --git a/src/packet/packet.js b/src/packet/packet.js index 7486038c..317ff0d2 100644 --- a/src/packet/packet.js +++ b/src/packet/packet.js @@ -123,8 +123,8 @@ module.exports = { */ read: function(input, position, len) { // some sanity checks - if (input == null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) & - 0x80) == 0) { + if (input === null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) & + 0x80) === 0) { throw new Error("Error during parsing. This message / key is probably not containing a valid OpenPGP format."); } var mypos = position; @@ -133,7 +133,7 @@ module.exports = { var packet_length; format = 0; // 0 = old format; 1 = new format - if ((input.charCodeAt(mypos) & 0x40) != 0) { + if ((input.charCodeAt(mypos) & 0x40) !== 0) { format = 1; } @@ -207,27 +207,28 @@ module.exports = { // EEEK, we're reading the full data here... var mypos2 = mypos + packet_length; bodydata = input.substring(mypos, mypos + packet_length); + var tmplen; while (true) { if (input.charCodeAt(mypos2) < 192) { - var tmplen = input.charCodeAt(mypos2++); + tmplen = input.charCodeAt(mypos2++); packet_length += tmplen; bodydata += input.substring(mypos2, mypos2 + tmplen); mypos2 += tmplen; break; } else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) { - var tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192; + 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.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) { - var tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F); + tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F); packet_length += tmplen; bodydata += input.substring(mypos2, mypos2 + tmplen); mypos2 += tmplen; } else { mypos2++; - var tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input[mypos2++] + 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; @@ -250,7 +251,7 @@ module.exports = { real_packet_length = packet_length; } - if (bodydata == null) { + if (bodydata === null) { bodydata = input.substring(mypos, mypos + real_packet_length); } @@ -260,4 +261,4 @@ module.exports = { offset: mypos + real_packet_length }; } -} +}; diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index 9de92aa4..3052aa65 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -39,7 +39,7 @@ module.exports = packetlist = function () { packet.read(parsed.packet); } - } + }; /** * Creates a binary representation of openpgp objects contained within the @@ -56,7 +56,7 @@ module.exports = packetlist = function () { } return bytes; - } + }; /** * Adds a packet to the list. This is the only supported method of doing so; @@ -69,7 +69,7 @@ module.exports = packetlist = function () { this[this.length] = packet; this.length++; - } + }; /** * Creates a new packetList with all packets that pass the test implemented by the provided function. @@ -85,7 +85,7 @@ module.exports = packetlist = function () { } return filtered; - } + }; /** * Creates a new packetList with all packets from the given types @@ -96,13 +96,13 @@ module.exports = packetlist = function () { var that = this; for (var i = 0; i < this.length; i++) { - if (args.some(function(packetType) {return that[i].tag == packetType})) { + if (args.some(function(packetType) {return that[i].tag == packetType;})) { filtered.push(this[i]); } } return filtered; - } + }; /** * Executes the provided callback once for each element @@ -111,7 +111,7 @@ module.exports = packetlist = function () { for (var i = 0; i < this.length; i++) { callback(this[i]); } - } + }; /** * Traverses packet tree and returns first matching packet @@ -132,7 +132,7 @@ module.exports = packetlist = function () { } } return null; - } + }; /** * Returns array of found indices by tag @@ -142,26 +142,26 @@ module.exports = packetlist = function () { var tagIndex = []; var that = this; for (var i = 0; i < this.length; i++) { - if (args.some(function(packetType) {return that[i].tag == packetType})) { + if (args.some(function(packetType) {return that[i].tag == packetType;})) { tagIndex.push(i); } } return tagIndex; - } + }; /** * Returns slice of packetlist */ this.slice = function(begin, end) { if (!end) { - end = this.length + end = this.length; } var part = new packetlist(); for (var i = begin; i < end; i++) { part.push(this[i]); } return part; - } + }; /** * Concatenates packetlist or array of packets @@ -172,6 +172,5 @@ module.exports = packetlist = function () { this.push(packetlist[i]); } } - } - -} + }; +}; diff --git a/src/packet/public_key.js b/src/packet/public_key.js index 7f6f9c95..879df2b7 100644 --- a/src/packet/public_key.js +++ b/src/packet/public_key.js @@ -91,7 +91,7 @@ module.exports = function () { this.mpi[i] = new type_mpi(); - p += this.mpi[i].read(bmpi.substr(p)) + p += this.mpi[i].read(bmpi.substr(p)); if (p > bmpi.length) { throw new Error('Error reading MPI @:' + p); @@ -181,7 +181,7 @@ module.exports = function () { for (var i = 0; i < mpicount; i++) { toHash += this.mpi[i].toBytes(); } - return crypto.hash.md5(toHash) + return crypto.hash.md5(toHash); } }; }; diff --git a/src/packet/public_key_encrypted_session_key.js b/src/packet/public_key_encrypted_session_key.js index 9d14a8f3..db60b761 100644 --- a/src/packet/public_key_encrypted_session_key.js +++ b/src/packet/public_key_encrypted_session_key.js @@ -124,7 +124,7 @@ module.exports = function () { enums.write(enums.publicKey, this.publicKeyAlgorithm)); for (var i = 0; i < this.encrypted.length; i++) { - result += this.encrypted[i].write() + result += this.encrypted[i].write(); } return result; @@ -169,7 +169,7 @@ module.exports = function () { result, key.mpi[0].byteLength()); - var key = decoded.substring(1, decoded.length - 2); + key = decoded.substring(1, decoded.length - 2); if (checksum != util.calc_checksum(key)) { throw new Error('Checksum mismatch'); diff --git a/src/packet/public_subkey.js b/src/packet/public_subkey.js index 0b94870f..166c0d5b 100644 --- a/src/packet/public_subkey.js +++ b/src/packet/public_subkey.js @@ -28,4 +28,4 @@ var publicKey = require('./public_key.js'); */ module.exports = function () { publicKey.call(this); -} +}; diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index 03dcd12e..ed6477ed 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -261,6 +261,6 @@ module.exports = function () { this.isDecrypted = true; }; -} +}; module.exports.prototype = new publicKey(); diff --git a/src/packet/secret_subkey.js b/src/packet/secret_subkey.js index 97a69fee..b0e26eed 100644 --- a/src/packet/secret_subkey.js +++ b/src/packet/secret_subkey.js @@ -28,4 +28,4 @@ var secretKey = require('./secret_key.js'); */ module.exports = function () { secretKey.call(this); -} +}; diff --git a/src/packet/signature.js b/src/packet/signature.js index fa2d3f8a..ef97d101 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -171,7 +171,6 @@ module.exports = packetSignature = function () { break; default: throw new Error('Version ' + version + ' of the signature is unsupported.'); - break; } // Two-octet field holding left 16 bits of signed hash value. @@ -363,6 +362,7 @@ module.exports = packetSignature = function () { // The leftwost bit denotes a "critical" packet, but we ignore it. var type = bytes.charCodeAt(mypos++) & 0x7F; + var seconds; // subpacket type switch (type) { @@ -372,9 +372,9 @@ module.exports = packetSignature = function () { break; case 3: // Signature Expiration Time in seconds - var seconds = util.readNumber(bytes.substr(mypos)); + seconds = util.readNumber(bytes.substr(mypos)); - this.signatureNeverExpires = seconds == 0; + this.signatureNeverExpires = seconds === 0; this.signatureExpirationTime = seconds; break; @@ -397,10 +397,10 @@ module.exports = packetSignature = function () { break; case 9: // Key Expiration Time in seconds - var seconds = util.readNumber(bytes.substr(mypos)); + seconds = util.readNumber(bytes.substr(mypos)); this.keyExpirationTime = seconds; - this.keyNeverExpires = seconds == 0; + this.keyNeverExpires = seconds === 0; break; case 11: @@ -435,9 +435,9 @@ module.exports = packetSignature = function () { // We extract key/value tuple from the byte stream. mypos += 4; var m = util.readNumber(bytes.substr(mypos, 2)); - mypos += 2 + mypos += 2; var n = util.readNumber(bytes.substr(mypos, 2)); - mypos += 2 + mypos += 2; var name = bytes.substr(mypos, m), value = bytes.substr(mypos + m, n); @@ -464,7 +464,7 @@ module.exports = packetSignature = function () { break; case 25: // Primary User ID - this.isPrimaryUserID = bytes[mypos++] != 0; + this.isPrimaryUserID = bytes[mypos++] !== 0; break; case 26: // Policy URI @@ -504,7 +504,6 @@ module.exports = packetSignature = function () { break; default: throw new Error("Unknown signature subpacket type " + type + " @:" + mypos); - break; } }; @@ -556,7 +555,7 @@ module.exports = packetSignature = function () { }); case t.key: - if (data.key == undefined) + if (data.key === undefined) throw new Error('Key packet is required for this sigtature.'); return data.key.writeOld(); @@ -568,11 +567,10 @@ module.exports = packetSignature = function () { return ''; case t.third_party: throw new Error('Not implemented'); - break; default: - throw new Error('Unknown signature type.') + throw new Error('Unknown signature type.'); } - } + }; this.calculateTrailer = function() { @@ -583,8 +581,8 @@ module.exports = packetSignature = function () { trailer += String.fromCharCode(4); // Version trailer += String.fromCharCode(0xFF); trailer += util.writeNumber(this.signatureData.length, 4); - return trailer - } + return trailer; + }; /** @@ -625,7 +623,7 @@ module.exports = packetSignature = function () { bytes + this.signatureData + trailer); return this.verified; - } + }; /** * Verifies signature expiration date @@ -636,5 +634,6 @@ module.exports = packetSignature = function () { return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000); } return false; - } -} + }; +}; + diff --git a/src/packet/sym_encrypted_integrity_protected.js b/src/packet/sym_encrypted_integrity_protected.js index 5a2998bb..bcb71cb7 100644 --- a/src/packet/sym_encrypted_integrity_protected.js +++ b/src/packet/sym_encrypted_integrity_protected.js @@ -64,16 +64,16 @@ module.exports = function () { this.write = function() { - return String.fromCharCode(1) // Version - + this.encrypted; + // 1 = Version + return String.fromCharCode(1) + this.encrypted; }; this.encrypt = function(sessionKeyAlgorithm, key) { - var bytes = this.packets.write() + var bytes = this.packets.write(); var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm); var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length - - 1) + 1); var tohash = bytes; diff --git a/src/packet/sym_encrypted_session_key.js b/src/packet/sym_encrypted_session_key.js index 0fb88ff3..4ef64296 100644 --- a/src/packet/sym_encrypted_session_key.js +++ b/src/packet/sym_encrypted_session_key.js @@ -75,13 +75,13 @@ module.exports = function () { if (done < bytes.length) { this.encrypted = bytes.substr(done); - this.sessionKeyEncryptionAlgorithm = algo + this.sessionKeyEncryptionAlgorithm = algo; } else this.sessionKeyAlgorithm = algo; }; this.write = function() { - var algo = this.encrypted == null ? + var algo = this.encrypted === null ? this.sessionKeyAlgorithm : this.sessionKeyEncryptionAlgorithm; @@ -89,7 +89,7 @@ module.exports = function () { String.fromCharCode(enums.write(enums.symmetric, algo)) + this.s2k.write(); - if (this.encrypted != null) + if (this.encrypted !== null) bytes += this.encrypted; return bytes; }; @@ -101,7 +101,7 @@ module.exports = function () { * @return {String} The unencrypted session key */ this.decrypt = function(passphrase) { - var algo = this.sessionKeyEncryptionAlgorithm != null ? + var algo = this.sessionKeyEncryptionAlgorithm !== null ? this.sessionKeyEncryptionAlgorithm : this.sessionKeyAlgorithm; @@ -109,7 +109,7 @@ module.exports = function () { var length = crypto.cipher[algo].keySize; var key = this.s2k.produce_key(passphrase, length); - if (this.encrypted == null) { + if (this.encrypted === null) { this.sessionKey = key; } else { diff --git a/src/packet/userid.js b/src/packet/userid.js index 74df385e..4e60338b 100644 --- a/src/packet/userid.js +++ b/src/packet/userid.js @@ -55,4 +55,4 @@ module.exports = function () { this.write = function () { return util.encode_utf8(this.userid); }; -} +}; diff --git a/src/type/keyid.js b/src/type/keyid.js index 4d36956f..ff8267b2 100644 --- a/src/type/keyid.js +++ b/src/type/keyid.js @@ -63,4 +63,4 @@ module.exports = function () { module.exports.mapToHex = function(keyId) { return keyId.toHex(); -} +}; diff --git a/src/type/mpi.js b/src/type/mpi.js index 03834823..55827462 100644 --- a/src/type/mpi.js +++ b/src/type/mpi.js @@ -57,11 +57,11 @@ module.exports = function mpi() { // The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. // // The length field of an MPI describes the length starting from its - // most significant non-zero bit. Thus, the MPI [00 02 01] is not + // most significant non-zero bit. Thus, the MPI [00 02 01] is not // formed correctly. It should be [00 01 01]. // TODO: Verification of this size method! This size calculation as - // specified above is not applicable in JavaScript + // specified above is not applicable in JavaScript var bytelen = Math.ceil(bits / 8); var raw = bytes.substr(2, bytelen); @@ -97,4 +97,4 @@ module.exports = function mpi() { this.fromBigInteger = function(bn) { this.data = bn.clone(); }; -} +}; diff --git a/src/type/s2k.js b/src/type/s2k.js index f29f5849..bfce53ea 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -99,7 +99,6 @@ module.exports = function s2k() { default: throw new Error("Unknown s2k type."); - break; } return i; diff --git a/src/util/util.js b/src/util/util.js index 83450a96..a1b2d73c 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -70,7 +70,7 @@ module.exports = { while (h.length < 2) h = "0" + h; r.push(" " + h); i++; - if (i % 32 == 0) + if (i % 32 === 0) r.push("\n "); } return r.join(''); @@ -82,7 +82,7 @@ module.exports = { * @return {String} String containing the hexadecimal values */ hexstrdump: function (str) { - if (str == null) + if (str === null) return ""; var r = []; var e = str.length; @@ -250,7 +250,7 @@ module.exports = { getLeftNBits: function (string, bitcount) { var rest = bitcount % 8; - if (rest == 0) + if (rest === 0) return string.substring(0, bitcount / 8); var bytes = (bitcount - rest) / 8 + 1; var result = string.substring(0, bytes); @@ -266,7 +266,7 @@ module.exports = { */ shiftRight: function (value, bitcount) { var temp = util.str2bin(value); - if (bitcount % 8 != 0) { + if (bitcount % 8 !== 0) { for (var i = temp.length - 1; i >= 0; i--) { temp[i] >>= bitcount % 8; if (i > 0)