diff --git a/.jshintrc b/.jshintrc index 086caa58..aa08bea0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,7 +7,6 @@ "curly": true, "eqeqeq": true, "immed": true, - "newcap": true, "regexp": true, "evil": true, "eqnull": true, @@ -32,6 +31,7 @@ "afterEach": true, "escape": true, "unescape": true, - "asmCrypto": true + "asmCrypto": true, + "postMessage": true } } \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index ae182ae8..1d26c270 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,6 +2,50 @@ module.exports = function(grunt) { + var lintFiles = [ + 'src/config/*.js', + 'src/crypto/cipher/aes.js', + 'src/crypto/cipher/blowfish.js', + 'src/crypto/cipher/cast5.js', + 'src/crypto/cipher/des.js', + 'src/crypto/cipher/index.js', + 'src/crypto/hash/md5.js', + 'src/crypto/public_key/dsa.js', + 'src/crypto/public_key/elgamal.js', + 'src/crypto/public_key/index.js', + 'src/crypto/public_key/rsa.js', + 'src/crypto/cfb.js', + 'src/crypto/crypto.js', + 'src/crypto/index.js', + 'src/crypto/pkcs1.js', + 'src/crypto/random.js', + 'src/crypto/signature.js', + 'src/encoding/*.js', + 'src/hkp/*.js', + 'src/keyring/*.js', + 'src/packet/all_packets.js', + 'src/packet/compressed.js', + 'src/packet/index.js', + 'src/packet/literal.js', + 'src/packet/marker.js', + 'src/packet/one_pass_signature.js', + 'src/packet/packet.js', + 'src/packet/public_key.js', + 'src/packet/public_key_encrypted_session_key.js', + 'src/packet/public_subkey.js', + 'src/packet/secret_key.js', + 'src/packet/secret_subkey.js', + 'src/packet/sym_encrypted_integrity_protected.js', + 'src/packet/sym_encrypted_session_key.js', + 'src/packet/symmetrically_encrypted.js', + 'src/packet/trust.js', + 'src/packet/user_attribute.js', + 'src/packet/userid.js', + 'src/type/*.js', + 'src/worker/async_proxy.js', + 'src/*.js', + ]; // add more over time ... goal should be 100% coverage + var version = grunt.option('release'); var fs = require('fs'); var browser_capabilities; @@ -105,14 +149,14 @@ module.exports = function(grunt) { } }, jshint: { - src: ['src/*.js'], // add more over time ... goal should be 100% coverage + src: lintFiles, build: ['Gruntfile.js', '*.json'], options: { jshintrc: '.jshintrc' } }, jscs: { - src: ['src/*.js'], // add more over time ... goal should be 100% coverage + src: lintFiles, build: ['Gruntfile.js'], options: { config: ".jscsrc", diff --git a/src/config/index.js b/src/config/index.js index 4e9f84a5..668b3958 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -2,4 +2,7 @@ * @see module:config/config * @module config */ + +'use strict'; + module.exports = require('./config.js'); diff --git a/src/config/localStorage.js b/src/config/localStorage.js index 4eafa45a..16253a73 100644 --- a/src/config/localStorage.js +++ b/src/config/localStorage.js @@ -3,13 +3,14 @@ * @module config/localStorage */ +'use strict'; + module.exports = LocalStorage; /** * @constructor */ -function LocalStorage() { -} +function LocalStorage() {} /** * Reads the config out of the HTML5 local storage @@ -22,8 +23,9 @@ LocalStorage.prototype.read = function () { if (cf === null) { this.config = this.default_config; this.write(); - } else + } else { this.config = cf; + } }; /** diff --git a/src/crypto/cfb.js b/src/crypto/cfb.js index 74ad1ace..5d278a47 100644 --- a/src/crypto/cfb.js +++ b/src/crypto/cfb.js @@ -1,6 +1,6 @@ // Modified by ProtonTech AG -// Modified by Recurity Labs GmbH +// Modified by Recurity Labs GmbH // modified version of http://www.hanewin.net/encrypt/PGdecode.js: @@ -8,10 +8,10 @@ * Copyright 2005-2006 Herbert Hanewinkel, www.haneWIN.de * version 2.0, check www.haneWIN.de for the latest version - * This software is provided as-is, without express or implied warranty. + * This software is provided as-is, without express or implied warranty. * Permission to use, copy, modify, distribute or sell this software, with or * without fee, for any purpose and by any individual or organization, is hereby - * granted, provided that the above copyright notice and this paragraph appear + * granted, provided that the above copyright notice and this paragraph appear * in all copies. Distribution as a part of an application or binary must * include the above copyright notice in the documentation and/or other * materials provided with the application or distribution. @@ -29,18 +29,18 @@ var cipher = require('./cipher'); module.exports = { /** - * This function encrypts a given with the specified prefixrandom + * This function encrypts a given with the specified prefixrandom * using the specified blockcipher to encrypt a message * @param {Uint8Array} prefixrandom random bytes of block_size length * to be used in prefixing the data * @param {String} cipherfn the algorithm cipher class to encrypt * data in one block_size encryption, {@link module:crypto/cipher}. - * @param {Uint8Array} plaintext data to be encrypted + * @param {Uint8Array} plaintext data to be encrypted * @param {Uint8Array} key key to be used to encrypt the plaintext. * This will be passed to the cipherfn * @param {Boolean} resync a boolean value specifying if a resync of the - * IV should be used or not. The encrypteddatapacket uses the - * "old" style with a resync. Encryption within an + * IV should be used or not. The encrypteddatapacket uses the + * "old" style with a resync. Encryption within an * encryptedintegrityprotecteddata packet is not resyncing the IV. * @return {Uint8Array} encrypted data */ @@ -172,8 +172,8 @@ module.exports = { * This will be passed to the cipherfn * @param {Uint8Array} ciphertext to be decrypted * @param {Boolean} resync a boolean value specifying if a resync of the - * IV should be used or not. The encrypteddatapacket uses the - * "old" style with a resync. Decryption within an + * IV should be used or not. The encrypteddatapacket uses the + * "old" style with a resync. Decryption within an * encryptedintegrityprotecteddata packet is not resyncing the IV. * @return {Uint8Array} the plaintext data */ @@ -202,8 +202,8 @@ module.exports = { ablock = cipherfn.encrypt(ablock); // test check octets - if (iblock[block_size - 2] != (ablock[0] ^ ciphertext[block_size]) || - iblock[block_size - 1] != (ablock[1] ^ ciphertext[block_size + 1])) { + if (iblock[block_size - 2] !== (ablock[0] ^ ciphertext[block_size]) || + iblock[block_size - 1] !== (ablock[1] ^ ciphertext[block_size + 1])) { throw new Error('CFB decrypt: invalid key'); } @@ -261,7 +261,7 @@ module.exports = { var blockc = new Uint8Array(block_size); var pos = 0; var cyphertext = new Uint8Array(plaintext.length); - var j = 0; + var i, j = 0; if (iv === null) { for (i = 0; i < block_size; i++) { @@ -276,7 +276,7 @@ module.exports = { while (plaintext.length > block_size * pos) { var encblock = cipherfn.encrypt(blockc); blocki = plaintext.subarray((pos * block_size), (pos * block_size) + block_size); - for (var i = 0; i < blocki.length; i++) { + for (i = 0; i < blocki.length; i++) { blockc[i] = blocki[i] ^ encblock[i]; cyphertext[j++] = blockc[i]; } @@ -293,7 +293,7 @@ module.exports = { var pos = 0; var plaintext = new Uint8Array(ciphertext.length); var offset = 0; - var j = 0; + var i, j = 0; if (iv === null) { blockp = new Uint8Array(block_size); @@ -307,7 +307,7 @@ module.exports = { while (ciphertext.length > (block_size * pos)) { var decblock = cipherfn.encrypt(blockp); blockp = ciphertext.subarray((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[j++] = blockp[i] ^ decblock[i]; } pos++; diff --git a/src/crypto/cipher/aes.js b/src/crypto/cipher/aes.js index 5a8e074d..1b776bbf 100644 --- a/src/crypto/cipher/aes.js +++ b/src/crypto/cipher/aes.js @@ -2,10 +2,10 @@ * Copyright 2005 Herbert Hanewinkel, www.haneWIN.de * version 1.1, check www.haneWIN.de for the latest version - * This software is provided as-is, without express or implied warranty. + * This software is provided as-is, without express or implied warranty. * Permission to use, copy, modify, distribute or sell this software, with or * without fee, for any purpose and by any individual or organization, is hereby - * granted, provided that the above copyright notice and this paragraph appear + * granted, provided that the above copyright notice and this paragraph appear * in all copies. Distribution as a part of an application or binary must * include the above copyright notice in the documentation and/or other * materials provided with the application or distribution. @@ -339,7 +339,9 @@ function packBytes(octets) { var len = octets.length; var b = new Array(len / 4); - if (!octets || len % 4) return; + if (!octets || len % 4) { + return; + } for (i = 0, j = 0; j < len; j += 4) { b[i++] = octets[j] | (octets[j + 1] << 8) | (octets[j + 2] << 16) | (octets[j + 3] << 24); @@ -377,13 +379,13 @@ function keyExpansion(key) { var tk = new Array(maxkc); var rconpointer = 0; - if (keylen == 16) { + if (keylen === 16) { rounds = 10; kc = 4; - } else if (keylen == 24) { + } else if (keylen === 24) { rounds = 12; kc = 6; - } else if (keylen == 32) { + } else if (keylen === 32) { rounds = 14; kc = 8; } else { @@ -408,7 +410,7 @@ function keyExpansion(key) { for (; (j < kc) && (t < 4); j++, t++) { keySched[r][t] = tk[j]; } - if (t == 4) { + if (t === 4) { r++; t = 0; } @@ -420,7 +422,7 @@ function keyExpansion(key) { tk[0] ^= S[B1(temp)] | (S[B2(temp)] << 8) | (S[B3(temp)] << 16) | (S[B0(temp)] << 24); tk[0] ^= Rcon[rconpointer++]; - if (kc != 8) { + if (kc !== 8) { for (j = 1; j < kc; j++) { tk[j] ^= tk[j - 1]; } @@ -441,7 +443,7 @@ function keyExpansion(key) { for (; (j < kc) && (t < 4); j++, t++) { keySched[r][t] = tk[j]; } - if (t == 4) { + if (t === 4) { r++; t = 0; } diff --git a/src/crypto/cipher/blowfish.js b/src/crypto/cipher/blowfish.js index 33ae604c..dc7e5cdc 100644 --- a/src/crypto/cipher/blowfish.js +++ b/src/crypto/cipher/blowfish.js @@ -1,5 +1,5 @@ -/* Modified by Recurity Labs GmbH - * +/* Modified by Recurity Labs GmbH + * * Originally written by nklein software (nklein.com) */ @@ -7,7 +7,9 @@ * @module crypto/cipher/blowfish */ -/* +'use strict'; + +/* * Javascript implementation based on Bruce Schneier's reference implementation. * * @@ -393,12 +395,6 @@ Blowfish.prototype.init = function(key) { // added by Recurity Labs -function BFencrypt(block, key) { - var bf = new Blowfish(); - bf.init(key); - return bf.encrypt_block(block); -} - function BF(key) { this.bf = new Blowfish(); this.bf.init(key); diff --git a/src/crypto/cipher/cast5.js b/src/crypto/cipher/cast5.js index 00c25cd3..5d656b57 100644 --- a/src/crypto/cipher/cast5.js +++ b/src/crypto/cipher/cast5.js @@ -16,9 +16,9 @@ /** @module crypto/cipher/cast5 */ +'use strict'; - -function openpgp_symenc_cast5() { +function OpenpgpSymencCast5() { this.BlockSize = 8; this.KeySize = 16; @@ -28,7 +28,7 @@ function openpgp_symenc_cast5() { this.reset(); - if (key.length == this.KeySize) { + if (key.length === this.KeySize) { this.keySchedule(key); } else { throw new Error('CAST-128: keys must be 16 bytes'); @@ -44,7 +44,7 @@ function openpgp_symenc_cast5() { }; this.getBlockSize = function() { - return BlockSize; + return this.BlockSize; }; this.encrypt = function(src) { @@ -592,8 +592,8 @@ function openpgp_symenc_cast5() { } -function cast5(key) { - this.cast5 = new openpgp_symenc_cast5(); +function Cast5(key) { + this.cast5 = new OpenpgpSymencCast5(); this.cast5.setKey(key); this.encrypt = function(block) { @@ -601,6 +601,6 @@ function cast5(key) { }; } -module.exports = cast5; -module.exports.blockSize = cast5.prototype.blockSize = 8; -module.exports.keySize = cast5.prototype.keySize = 16; +module.exports = Cast5; +module.exports.blockSize = Cast5.prototype.blockSize = 8; +module.exports.keySize = Cast5.prototype.keySize = 16; diff --git a/src/crypto/cipher/des.js b/src/crypto/cipher/des.js index 08f5fcd3..4850a486 100644 --- a/src/crypto/cipher/des.js +++ b/src/crypto/cipher/des.js @@ -81,14 +81,14 @@ 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; + i, j, temp, right1, right2, left, right, looping; var cbcleft, cbcleft2, cbcright, cbcright2; var endloop, loopinc; var len = message.length; //set up the loops for single and triple des - var iterations = keys.length == 32 ? 3 : 9; //single or triple des - if (iterations == 3) { + var iterations = keys.length === 32 ? 3 : 9; //single or triple des + if (iterations === 3) { looping = encrypt ? new Array(0, 32, 2) : new Array(30, -2, -2); } else { looping = encrypt ? new Array(0, 32, 2, 62, 30, -2, 64, 96, 2) : new Array(94, 62, -2, 32, 64, 2, 30, -2, -2); @@ -105,7 +105,7 @@ function des(keys, message, encrypt, mode, iv, padding) { var result = new Uint8Array(len); var k = 0; - if (mode == 1) { //CBC mode + if (mode === 1) { //CBC mode cbcleft = (iv[m++] << 24) | (iv[m++] << 16) | (iv[m++] << 8) | iv[m++]; cbcright = (iv[m++] << 24) | (iv[m++] << 16) | (iv[m++] << 8) | iv[m++]; m = 0; @@ -117,7 +117,7 @@ function des(keys, message, encrypt, mode, iv, padding) { right = (message[m++] << 24) | (message[m++] << 16) | (message[m++] << 8) | message[m++]; //for Cipher Block Chaining mode, xor the message with the previous result - if (mode == 1) { + if (mode === 1) { if (encrypt) { left ^= cbcleft; right ^= cbcright; @@ -154,7 +154,7 @@ function des(keys, message, encrypt, mode, iv, padding) { endloop = looping[j + 1]; loopinc = looping[j + 2]; //now go through and perform the encryption or decryption - for (i = looping[j]; i != endloop; i += loopinc) { //for efficiency + for (i = looping[j]; i !== endloop; i += loopinc) { //for efficiency right1 = right ^ keys[i]; right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1]; //the result is attained by passing these bytes through the S selection functions @@ -191,7 +191,7 @@ function des(keys, message, encrypt, mode, iv, padding) { left ^= (temp << 4); //for Cipher Block Chaining mode, xor the message with the previous result - if (mode == 1) { + if (mode === 1) { if (encrypt) { cbcleft = left; cbcright = right; @@ -335,13 +335,13 @@ function des_addPadding(message, padding) { var padLength = 8 - (message.length % 8); var pad; - if (padding == 2 && (padLength < 8)) { //pad the message with spaces + if (padding === 2 && (padLength < 8)) { //pad the message with spaces pad = " ".charCodeAt(0); - } else if (padding == 1) { //PKCS7 padding + } else if (padding === 1) { //PKCS7 padding pad = padLength; } else if (!padding && (padLength < 8)) { //pad the message out with null bytes pad = 0; - } else if (padLength == 8) { + } else if (padLength === 8) { return message; } else { @@ -362,9 +362,9 @@ function des_addPadding(message, padding) { function des_removePadding(message, padding) { var padLength = null; var pad; - if (padding == 2) { // space padded + if (padding === 2) { // space padded pad = " ".charCodeAt(0); - } else if (padding == 1) { // PKCS7 + } else if (padding === 1) { // PKCS7 padLength = message[message.length - 1]; } else if (!padding) { // null padding pad = 0; @@ -384,9 +384,6 @@ function des_removePadding(message, padding) { return message.subarray(0, message.length - padLength); } - -var util = require('../../util.js'); - // added by Recurity Labs function Des(key) { diff --git a/src/crypto/cipher/index.js b/src/crypto/cipher/index.js index 06efdc8b..51495141 100644 --- a/src/crypto/cipher/index.js +++ b/src/crypto/cipher/index.js @@ -6,6 +6,8 @@ * @module crypto/cipher */ +'use strict'; + var desModule = require('./des.js'); module.exports = { diff --git a/src/crypto/cipher/twofish.js b/src/crypto/cipher/twofish.js index 3e59756a..8d4bd9c0 100644 --- a/src/crypto/cipher/twofish.js +++ b/src/crypto/cipher/twofish.js @@ -1,5 +1,5 @@ -/* Modified by Recurity Labs GmbH - * +/* Modified by Recurity Labs GmbH + * * Cipher.js * A block-cipher algorithm implementation on JavaScript * See Cipher.readme.txt for further information. @@ -10,10 +10,10 @@ * ACKNOWLEDGMENT * * The main subroutines are written by Michiel van Everdingen. - * + * * Michiel van Everdingen * http://home.versatel.nl/MAvanEverdingen/index.html - * + * * All rights for these routines are reserved to Michiel van Everdingen. * */ @@ -22,7 +22,7 @@ * @module crypto/cipher/twofish */ - +'use strict'; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Math @@ -42,10 +42,6 @@ function setW(a, i, w) { a.splice(i, 4, w & 0xFF, (w >>> 8) & 0xFF, (w >>> 16) & 0xFF, (w >>> 24) & 0xFF); } -function setWInv(a, i, w) { - a.splice(i, 4, (w >>> 24) & 0xFF, (w >>> 16) & 0xFF, (w >>> 8) & 0xFF, w & 0xFF); -} - function getB(x, n) { return (x >>> (n * 8)) & 0xFF; } @@ -176,8 +172,9 @@ function createTwofish() { keyBytes = keyBytes.slice(0, 32); i = keyBytes.length; - while (i != 16 && i != 24 && i != 32) + while (i !== 16 && i !== 24 && i !== 32) { keyBytes[i++] = 0; + } for (i = 0; i < keyBytes.length; i += 4) { inKey[i >> 2] = getW(keyBytes, i); @@ -334,15 +331,6 @@ function createTwofish() { // added by Recurity Labs -function TFencrypt(block, key) { - var block_copy = toArray(block); - var tf = createTwofish(); - tf.open(toArray(key), 0); - var result = tf.encrypt(block_copy, 0); - tf.close(); - return result; -} - function TF(key) { this.tf = createTwofish(); this.tf.open(toArray(key), 0); diff --git a/src/crypto/crypto.js b/src/crypto/crypto.js index 68479a48..1d00f825 100644 --- a/src/crypto/crypto.js +++ b/src/crypto/crypto.js @@ -25,6 +25,8 @@ * @module crypto/crypto */ +'use strict'; + var random = require('./random.js'), cipher = require('./cipher'), publicKey = require('./public_key'), diff --git a/src/crypto/hash/md5.js b/src/crypto/hash/md5.js index 30466d77..c90e412e 100644 --- a/src/crypto/hash/md5.js +++ b/src/crypto/hash/md5.js @@ -17,6 +17,8 @@ * @module crypto/hash/md5 */ +'use strict'; + var util = require('../../util.js'); /** @@ -140,12 +142,15 @@ function md51(s) { } s = s.substring(i - 64); var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (i = 0; i < s.length; i++) + for (i = 0; i < s.length; i++) { tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); + } tail[i >> 2] |= 0x80 << ((i % 4) << 3); if (i > 55) { md5cycle(state, tail); - for (i = 0; i < 16; i++) tail[i] = 0; + for (i = 0; i < 16; i++) { + tail[i] = 0; + } } tail[14] = n * 8; md5cycle(state, tail); @@ -182,14 +187,16 @@ var hex_chr = '0123456789abcdef'.split(''); function rhex(n) { var s = '', j = 0; - for (; j < 4; j++) + for (; j < 4; j++) { s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; + } return s; } function hex(x) { - for (var i = 0; i < x.length; i++) + for (var i = 0; i < x.length; i++) { x[i] = rhex(x[i]); + } return x.join(''); } @@ -206,11 +213,3 @@ generated by an if clause. */ function add32(a, b) { return (a + b) & 0xFFFFFFFF; } - -if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') { - function add32(x, y) { - var lsw = (x & 0xFFFF) + (y & 0xFFFF), - msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); - } -} diff --git a/src/crypto/pkcs1.js b/src/crypto/pkcs1.js index e7adf1f5..b50e74bd 100644 --- a/src/crypto/pkcs1.js +++ b/src/crypto/pkcs1.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -25,6 +25,8 @@ * @module crypto/pkcs1 */ +'use strict'; + /** * ASN1 object identifiers for hashes (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.2}) */ @@ -47,8 +49,7 @@ hash_headers[11] = [0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x00, 0x04, 0x1C ]; -var crypto = require('./crypto.js'), - random = require('./random.js'), +var random = require('./random.js'), util = require('../util.js'), BigInteger = require('./public_key/jsbn.js'), hash = require('./hash'); diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index d9138c33..56d8c670 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -25,6 +25,8 @@ * @module crypto/public_key/dsa */ +'use strict'; + var BigInteger = require('./jsbn.js'), random = require('../random.js'), hashModule = require('../hash'), @@ -45,14 +47,14 @@ function DSA() { // FIPS-186-4, section 4.6: // The values of r and s shall be checked to determine if r = 0 or s = 0. // If either r = 0 or s = 0, a new value of k shall be generated, and the - // signature shall be recalculated. It is extremely unlikely that r = 0 + // signature shall be recalculated. It is extremely unlikely that r = 0 // or s = 0 if signatures are generated properly. var k, s1, s2; while (true) { k = random.getRandomBigIntegerInRange(BigInteger.ONE, q.subtract(BigInteger.ONE)); s1 = (g.modPow(k, p)).mod(q); s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q); - if (s1 != 0 && s2 != 0) { + if (s1 !== 0 && s2 !== 0) { break; } } @@ -73,28 +75,30 @@ function DSA() { switch (Math.round(q.bitLength() / 8)) { case 20: // 1024 bit - if (usersetting != 2 && + if (usersetting !== 2 && usersetting > 11 && - usersetting != 10 && - usersetting < 8) + usersetting !== 10 && + usersetting < 8) { return 2; // prefer sha1 + } return usersetting; case 28: // 2048 bit if (usersetting > 11 && - usersetting < 8) + usersetting < 8) { return 11; + } return usersetting; case 32: // 4096 bit // prefer sha224 if (usersetting > 10 && - usersetting < 8) + usersetting < 8) { return 8; // prefer sha256 + } return usersetting; default: util.print_debug("DSA select hash algorithm: returning null for an unknown length of q"); return null; - } } this.select_hash_algorithm = select_hash_algorithm; @@ -110,7 +114,7 @@ function DSA() { return null; } var w = s2.modInverse(q); - if (BigInteger.ZERO.compareTo(w) == 0) { + if (BigInteger.ZERO.compareTo(w) === 0) { util.print_debug("invalid DSA Signature"); return null; } @@ -119,68 +123,8 @@ function DSA() { return g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q); } - /* - * 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 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 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 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; } module.exports = DSA; diff --git a/src/crypto/public_key/elgamal.js b/src/crypto/public_key/elgamal.js index aaf97120..dd1aa009 100644 --- a/src/crypto/public_key/elgamal.js +++ b/src/crypto/public_key/elgamal.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -24,6 +24,8 @@ * @module crypto/public_key/elgamal */ +'use strict'; + var BigInteger = require('./jsbn.js'), random = require('../random.js'), util = require('../../util.js'); diff --git a/src/crypto/public_key/index.js b/src/crypto/public_key/index.js index fa4dd2d1..a0969e90 100644 --- a/src/crypto/public_key/index.js +++ b/src/crypto/public_key/index.js @@ -4,6 +4,9 @@ * @requires crypto/public_key/rsa * @module crypto/public_key */ + +'use strict'; + module.exports = { /** @see module:crypto/public_key/rsa */ rsa: require('./rsa.js'), diff --git a/src/crypto/signature.js b/src/crypto/signature.js index 0620330e..86e0782d 100644 --- a/src/crypto/signature.js +++ b/src/crypto/signature.js @@ -5,28 +5,30 @@ * @requires crypto/public_key * @module crypto/signature */ +'use strict'; + var util = require('../util'), publicKey = require('./public_key'), - pkcs1 = require('./pkcs1.js'), - hashModule = require('./hash'); + pkcs1 = require('./pkcs1.js'); module.exports = { /** - * + * * @param {module:enums.publicKey} algo public Key algorithm * @param {module:enums.hash} hash_algo Hash algorithm * @param {Array} msg_MPIs Signature multiprecision integers - * @param {Array} publickey_MPIs Public key multiprecision integers + * @param {Array} publickey_MPIs Public key multiprecision integers * @param {Uint8Array} data Data on where the signature was computed on. * @return {Boolean} true if signature (sig_data was equal to data over hash) */ verify: function(algo, hash_algo, msg_MPIs, publickey_MPIs, data) { + var m; data = util.Uint8Array2str(data); switch (algo) { case 1: - // RSA (Encrypt or Sign) [HAC] + // RSA (Encrypt or Sign) [HAC] case 2: // RSA Encrypt-Only [HAC] case 3: @@ -35,7 +37,7 @@ module.exports = { var n = publickey_MPIs[0].toBigInteger(); var k = publickey_MPIs[0].byteLength(); var e = publickey_MPIs[1].toBigInteger(); - var m = msg_MPIs[0].toBigInteger(); + m = msg_MPIs[0].toBigInteger(); var EM = rsa.verify(m, e, n); var EM2 = pkcs1.emsa.encode(hash_algo, data, k); return EM.compareTo(EM2) === 0; @@ -51,7 +53,7 @@ module.exports = { var q = publickey_MPIs[1].toBigInteger(); var g = publickey_MPIs[2].toBigInteger(); var y = publickey_MPIs[3].toBigInteger(); - var m = data; + m = data; var dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y); return dopublic.compareTo(s1) === 0; default: @@ -63,9 +65,9 @@ module.exports = { * Create a signature on data using the specified algorithm * @param {module:enums.hash} hash_algo hash Algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4}) * @param {module:enums.publicKey} algo Asymmetric cipher algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1}) - * @param {Array} publicMPIs Public key multiprecision integers - * of the private key - * @param {Array} secretMPIs Private key multiprecision + * @param {Array} publicMPIs Public key multiprecision integers + * of the private key + * @param {Array} secretMPIs Private key multiprecision * integers which is used to sign the data * @param {Uint8Array} data Data to be signed * @return {Array} @@ -78,7 +80,7 @@ module.exports = { switch (algo) { case 1: - // RSA (Encrypt or Sign) [HAC] + // RSA (Encrypt or Sign) [HAC] case 2: // RSA Encrypt-Only [HAC] case 3: @@ -97,7 +99,6 @@ module.exports = { var p = keyIntegers[0].toBigInteger(); var q = keyIntegers[1].toBigInteger(); var g = keyIntegers[2].toBigInteger(); - var y = keyIntegers[3].toBigInteger(); var x = keyIntegers[4].toBigInteger(); m = data; var result = dsa.sign(hash_algo, m, g, p, q, x); diff --git a/src/encoding/armor.js b/src/encoding/armor.js index 846eccb2..78241b2b 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -22,6 +22,8 @@ * @module encoding/armor */ +'use strict'; + var base64 = require('./base64.js'), enums = require('../enums.js'), config = require('../config'); @@ -129,7 +131,7 @@ function getCheckSum(data) { function verifyCheckSum(data, checksum) { var c = getCheckSum(data); var d = checksum; - return c[0] == d[0] && c[1] == d[1] && c[2] == d[2] && c[3] == d[3]; + return c[0] === d[0] && c[1] === d[1] && c[2] === d[2] && c[3] === d[3]; } /** * Internal function to calculate a CRC-24 checksum over a given string (data) @@ -291,11 +293,11 @@ function dearmor(text) { var result, checksum, msg; - if (text.search(reSplit) != splittext[0].length) { + if (text.search(reSplit) !== splittext[0].length) { indexBase = 0; } - if (type != 2) { + if (type !== 2) { msg = splitHeaders(splittext[indexBase]); var msg_sum = splitChecksum(msg.body); diff --git a/src/encoding/base64.js b/src/encoding/base64.js index c47957bf..ea9b25f0 100644 --- a/src/encoding/base64.js +++ b/src/encoding/base64.js @@ -2,10 +2,10 @@ * Copyright 2005 Herbert Hanewinkel, www.haneWIN.de * version 1.0, check www.haneWIN.de for the latest version * - * This software is provided as-is, without express or implied warranty. + * This software is provided as-is, without express or implied warranty. * Permission to use, copy, modify, distribute or sell this software, with or * without fee, for any purpose and by any individual or organization, is hereby - * granted, provided that the above copyright notice and this paragraph appear + * granted, provided that the above copyright notice and this paragraph appear * in all copies. Distribution as a part of an application or binary must * include the above copyright notice in the documentation and/or other materials * provided with the application or distribution. @@ -15,6 +15,8 @@ * @module encoding/base64 */ +'use strict'; + var b64s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; /** @@ -36,35 +38,40 @@ function s2r(t, o) { if (s === 0) { r.push(b64s.charAt((c >> 2) & 63)); a = (c & 3) << 4; - } else if (s == 1) { + } else if (s === 1) { r.push(b64s.charAt((a | (c >> 4) & 15))); a = (c & 15) << 2; - } else if (s == 2) { + } else if (s === 2) { r.push(b64s.charAt(a | ((c >> 6) & 3))); l += 1; - if ((l % 60) === 0) + if ((l % 60) === 0) { r.push("\n"); + } r.push(b64s.charAt(c & 63)); } l += 1; - if ((l % 60) === 0) + if ((l % 60) === 0) { r.push("\n"); + } s += 1; - if (s == 3) + if (s === 3) { s = 0; + } } if (s > 0) { r.push(b64s.charAt(a)); l += 1; - if ((l % 60) === 0) + if ((l % 60) === 0) { r.push("\n"); + } r.push('='); l += 1; } - if (s == 1) { - if ((l % 60) === 0) + if (s === 1) { + if ((l % 60) === 0) { r.push("\n"); + } r.push('='); } if (o) @@ -91,8 +98,9 @@ function r2s(t) { for (n = 0; n < tl; n++) { c = b64s.indexOf(t.charAt(n)); if (c >= 0) { - if (s) + if (s) { r.push(a | (c >> (6 - s)) & 255); + } s = (s + 2) & 7; a = (c << s) & 255; } diff --git a/src/hkp/index.js b/src/hkp/index.js index c3098000..cb1b2ca5 100644 --- a/src/hkp/index.js +++ b/src/hkp/index.js @@ -1,3 +1,5 @@ +'use strict'; + /** * @see module:hkp/hkp * @module hkp diff --git a/src/keyring/index.js b/src/keyring/index.js index b1ef2352..20c52f87 100644 --- a/src/keyring/index.js +++ b/src/keyring/index.js @@ -1,3 +1,5 @@ +'use strict'; + /** * @see module:keyring/keyring * @module keyring diff --git a/src/keyring/keyring.js b/src/keyring/keyring.js index 82f58cf9..9968ce4d 100644 --- a/src/keyring/keyring.js +++ b/src/keyring/keyring.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -23,13 +23,13 @@ * @module keyring/keyring */ -var enums = require('../enums.js'), - keyModule = require('../key.js'), - util = require('../util.js'); +'use strict'; + +var keyModule = require('../key.js'); module.exports = Keyring; - /** +/** * Initialization routine for the keyring. This method reads the * keyring from HTML5 local storage and initializes this instance. * @constructor diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js index 9fcc98e1..44a01f0f 100644 --- a/src/keyring/localstore.js +++ b/src/keyring/localstore.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -21,6 +21,9 @@ * @module keyring/localstore * @param {String} prefix prefix for itemnames in localstore */ + +'use strict'; + module.exports = LocalStore; var config = require('../config'), @@ -31,7 +34,7 @@ function LocalStore(prefix) { prefix = prefix || 'openpgp-'; this.publicKeysItem = prefix + this.publicKeysItem; this.privateKeysItem = prefix + this.privateKeysItem; - if (typeof window != 'undefined' && window.localStorage) { + if (typeof window !== 'undefined' && window.localStorage) { this.storage = window.localStorage; } else { this.storage = new (require('node-localstorage').LocalStorage)(config.node_store); diff --git a/src/packet/all_packets.js b/src/packet/all_packets.js index 37921a00..9df86d1e 100644 --- a/src/packet/all_packets.js +++ b/src/packet/all_packets.js @@ -1,3 +1,5 @@ +'use strict'; + /** * @requires enums * @module packet @@ -57,10 +59,10 @@ module.exports = { var tagName = enums.read(enums.packet, packetClone.tag); var packet = this.newPacketFromTag(tagName); for (var attr in packetClone) { - if (packetClone.hasOwnProperty(attr)) { - packet[attr] = packetClone[attr]; - } + if (packetClone.hasOwnProperty(attr)) { + packet[attr] = packetClone[attr]; } + } if (packet.postCloneTypeFix) { packet.postCloneTypeFix(); } diff --git a/src/packet/compressed.js b/src/packet/compressed.js index 5156d1d9..f9bc86d5 100644 --- a/src/packet/compressed.js +++ b/src/packet/compressed.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -29,6 +29,8 @@ * @module packet/compressed */ +'use strict'; + module.exports = Compressed; var enums = require('../enums.js'), @@ -85,8 +87,9 @@ Compressed.prototype.read = function (bytes) { * @return {String} binary compressed packet */ Compressed.prototype.write = function () { - if (this.compressed === null) + if (this.compressed === null) { this.compress(); + } return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed); }; @@ -97,7 +100,7 @@ Compressed.prototype.write = function () { * read by read_packet */ Compressed.prototype.decompress = function () { - var decompressed; + var decompressed, inflate; switch (this.algorithm) { case 'uncompressed': @@ -105,12 +108,12 @@ Compressed.prototype.decompress = function () { break; case 'zip': - var inflate = new RawInflate.Zlib.RawInflate(this.compressed); + inflate = new RawInflate.Zlib.RawInflate(this.compressed); decompressed = inflate.decompress(); break; case 'zlib': - var inflate = new Zlib.Zlib.Inflate(this.compressed); + inflate = new Zlib.Zlib.Inflate(this.compressed); decompressed = inflate.decompress(); break; diff --git a/src/packet/index.js b/src/packet/index.js index be4e31f2..cd9e6578 100644 --- a/src/packet/index.js +++ b/src/packet/index.js @@ -1,4 +1,4 @@ -var enums = require('../enums.js'); +'use strict'; module.exports = { /** @@ -10,5 +10,6 @@ module.exports = { var packets = require('./all_packets.js'); -for (var i in packets) +for (var i in packets) { module.exports[i] = packets[i]; +} diff --git a/src/packet/literal.js b/src/packet/literal.js index 98f9f109..75f3ba71 100644 --- a/src/packet/literal.js +++ b/src/packet/literal.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -25,6 +25,8 @@ * @module packet/literal */ +'use strict'; + module.exports = Literal; var util = require('../util.js'), @@ -50,7 +52,7 @@ Literal.prototype.setText = function (text) { // normalize EOL to \r\n text = text.replace(/\r/g, '').replace(/\n/g, '\r\n'); // encode UTF8 - this.data = this.format == 'utf8' ? util.str2Uint8Array(util.encode_utf8(text)) : util.str2Uint8Array(text); + this.data = this.format === 'utf8' ? util.str2Uint8Array(util.encode_utf8(text)) : util.str2Uint8Array(text); }; /** @@ -96,7 +98,7 @@ Literal.prototype.setFilename = function (filename) { /** * Get the filename of the literal packet data - * @returns {String} filename + * @returns {String} filename */ Literal.prototype.getFilename = function() { return this.filename; diff --git a/src/packet/marker.js b/src/packet/marker.js index a6d32b36..089c1939 100644 --- a/src/packet/marker.js +++ b/src/packet/marker.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -29,6 +29,8 @@ * @module packet/marker */ +'use strict'; + module.exports = Marker; var enums = require('../enums.js'); @@ -52,10 +54,11 @@ function Marker() { * @return {module:packet/marker} Object representation */ Marker.prototype.read = function (bytes) { - if (bytes[0] == 0x50 && // P - bytes[1] == 0x47 && // G - bytes[2] == 0x50) // P + if (bytes[0] === 0x50 && // P + bytes[1] === 0x47 && // G + bytes[2] === 0x50) { // P 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 8b650e74..0d0a3fdd 100644 --- a/src/packet/one_pass_signature.js +++ b/src/packet/one_pass_signature.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -29,6 +29,8 @@ * @module packet/one_pass_signature */ +'use strict'; + module.exports = OnePassSignature; var util = require('../util.js'), @@ -87,11 +89,11 @@ OnePassSignature.prototype.read = function (bytes) { */ OnePassSignature.prototype.write = function () { - var start = new Uint8Array([3, enums.write(enums.signature, this.type), + var start = new Uint8Array([3, enums.write(enums.signature, this.type), enums.write(enums.hash, this.hashAlgorithm), enums.write(enums.publicKey, this.publicKeyAlgorithm)]); - var end = new Uint8Array([this.flags]); + var end = new Uint8Array([this.flags]); return util.concatUint8Array([start, this.signingKeyId.write(), end]); }; diff --git a/src/packet/packet.js b/src/packet/packet.js index e36d89f5..8629449c 100644 --- a/src/packet/packet.js +++ b/src/packet/packet.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -21,8 +21,9 @@ * @module packet/packet */ -var enums = require('../enums.js'), - util = require('../util.js'); +'use strict'; + +var util = require('../util.js'); module.exports = { readSimpleLength: function(bytes) { @@ -37,7 +38,7 @@ module.exports = { } else if (type < 255) { len = ((bytes[0] - 192) << 8) + (bytes[1]) + 192; offset = 2; - } else if (type == 255) { + } else if (type === 255) { len = util.readNumber(bytes.subarray(1, 1 + 4)); offset = 5; } @@ -51,7 +52,7 @@ module.exports = { /** * Encodes a given integer of length to the openpgp length specifier to a * string - * + * * @param {Integer} length The length to encode * @return {Uint8Array} String with openpgp length representation */ @@ -73,7 +74,7 @@ module.exports = { /** * Writes a packet header version 4 with the given tag_type and length to a * string - * + * * @param {Integer} tag_type Tag type * @param {Integer} length Length of the payload * @return {String} String of the header @@ -86,7 +87,7 @@ module.exports = { /** * Writes a packet header Version 3 with the given tag_type and length to a * string - * + * * @param {Integer} tag_type Tag type * @param {Integer} length Length of the payload * @return {String} String of the header @@ -104,7 +105,7 @@ module.exports = { /** * Generic static Packet Parser function - * + * * @param {String} input Input stream as string * @param {integer} position Position to start parsing * @param {integer} len Length of the input from position on @@ -167,11 +168,11 @@ module.exports = { // 3 - The packet is of indeterminate length. The header is 1 // octet long, and the implementation must determine how long // the packet is. If the packet is in a file, this means that - // the packet extends until the end of the file. In general, - // an implementation SHOULD NOT use indeterminate-length - // packets except where the end of the data will be clear - // from the context, and even then it is better to use a - // definite length, or a new format header. The new format + // the packet extends until the end of the file. In general, + // an implementation SHOULD NOT use indeterminate-length + // packets except where the end of the data will be clear + // from the context, and even then it is better to use a + // definite length, or a new format header. The new format // headers described below have a mechanism for precisely // encoding data of indeterminate length. packet_length = len; @@ -235,7 +236,7 @@ module.exports = { // if there was'nt a partial body length: use the specified // packet_length - if (real_packet_length == -1) { + if (real_packet_length === -1) { real_packet_length = packet_length; } diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index a15daddb..0e515936 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -9,6 +9,8 @@ * @module packet/packetlist */ +'use strict'; + module.exports = Packetlist; var util = require('../util'), @@ -67,7 +69,9 @@ Packetlist.prototype.write = function () { * writing to packetlist[i] directly will result in an error. */ Packetlist.prototype.push = function (packet) { - if (!packet) return; + if (!packet) { + return; + } packet.packets = packet.packets || new Packetlist(); @@ -100,7 +104,7 @@ Packetlist.prototype.filterByTag = 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]); } } @@ -131,7 +135,9 @@ Packetlist.prototype.findPacket = function (type) { for (var i = 0; i < this.length; i++) { if (this[i].packets.length) { found = this[i].packets.findPacket(type); - if (found) return found; + if (found) { + return found; + } } } } diff --git a/src/packet/public_key.js b/src/packet/public_key.js index c31b49a1..e57c1d63 100644 --- a/src/packet/public_key.js +++ b/src/packet/public_key.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -30,6 +30,8 @@ * @module packet/public_key */ +'use strict'; + module.exports = PublicKey; var util = require('../util.js'), @@ -78,12 +80,12 @@ PublicKey.prototype.read = function (bytes) { // A one-octet version number (3 or 4). this.version = bytes[pos++]; - if (this.version == 3 || this.version == 4) { + if (this.version === 3 || this.version === 4) { // - A four-octet number denoting the time that the key was created. this.created = util.readDate(bytes.subarray(pos, pos + 4)); pos += 4; - if (this.version == 3) { + if (this.version === 3) { // - A two-octet number denoting the time in days that this key is // valid. If this number is zero, then it does not expire. this.expirationTimeV3 = util.readNumber(bytes.subarray(pos, pos + 2)); @@ -133,7 +135,7 @@ PublicKey.prototype.write = function () { // Version arr.push(new Uint8Array([this.version])); arr.push(util.writeDate(this.created)); - if (this.version == 3) { + if (this.version === 3) { arr.push(util.writeNumber(this.expirationTimeV3, 2)); } arr.push(new Uint8Array([enums.write(enums.publicKey, this.algorithm)])); @@ -171,9 +173,9 @@ PublicKey.prototype.getKeyId = function () { return this.keyid; } this.keyid = new type_keyid(); - if (this.version == 4) { + if (this.version === 4) { this.keyid.read(util.str2Uint8Array(util.hex2bin(this.getFingerprint()).substr(12, 8))); - } else if (this.version == 3) { + } else if (this.version === 3) { var arr = this.mpi[0].write(); this.keyid.read(arr.subarray(arr.length - 8, arr.length)); } @@ -189,10 +191,10 @@ PublicKey.prototype.getFingerprint = function () { return this.fingerprint; } var toHash = ''; - if (this.version == 4) { + if (this.version === 4) { toHash = this.writeOld(); this.fingerprint = util.Uint8Array2str(crypto.hash.sha1(toHash)); - } else if (this.version == 3) { + } else if (this.version === 3) { var mpicount = crypto.getPublicMpiCount(this.algorithm); for (var i = 0; i < mpicount; i++) { toHash += this.mpi[i].toBytes(); diff --git a/src/packet/public_key_encrypted_session_key.js b/src/packet/public_key_encrypted_session_key.js index 66b462d8..f3e174c0 100644 --- a/src/packet/public_key_encrypted_session_key.js +++ b/src/packet/public_key_encrypted_session_key.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -37,6 +37,8 @@ * @module packet/public_key_encrypted_session_key */ +'use strict'; + module.exports = PublicKeyEncryptedSessionKey; var type_keyid = require('../type/keyid.js'), @@ -157,7 +159,7 @@ PublicKeyEncryptedSessionKey.prototype.decrypt = function (key) { key = util.str2Uint8Array(decoded.substring(1, decoded.length - 2)); - if (checksum != util.calc_checksum(key)) { + if (checksum !== util.calc_checksum(key)) { throw new Error('Checksum mismatch'); } else { this.sessionKey = key; diff --git a/src/packet/public_subkey.js b/src/packet/public_subkey.js index f7e52b88..a7456c84 100644 --- a/src/packet/public_subkey.js +++ b/src/packet/public_subkey.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -21,6 +21,8 @@ * @module packet/public_subkey */ +'use strict'; + module.exports = PublicSubkey; var publicKey = require('./public_key.js'), diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index 1331d6e4..a800d927 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -31,6 +31,8 @@ * @module packet/secret_key */ +'use strict'; + module.exports = SecretKey; var publicKey = require('./public_key.js'), @@ -57,19 +59,21 @@ SecretKey.prototype = new publicKey(); SecretKey.prototype.constructor = SecretKey; function get_hash_len(hash) { - if (hash == 'sha1') + if (hash === 'sha1') { return 20; - else + } else { return 2; + } } function get_hash_fn(hash) { - if (hash == 'sha1') + if (hash === 'sha1') { return crypto.hash.sha1; - else + } else { return function(c) { return util.writeNumber(util.calc_checksum(c), 2); - }; + }; + } } // Helper function @@ -83,8 +87,9 @@ function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) { var hash = util.Uint8Array2str(hashfn(cleartext)); - if (hash != hashtext) + if (hash !== hashtext) { return new Error("Hash mismatch."); + } var mpis = crypto.getPrivateMpiCount(algorithm); @@ -141,8 +146,9 @@ SecretKey.prototype.read = function (bytes) { // key data. These algorithm-specific fields are as described // below. var parsedMPI = parse_cleartext_mpi('mod', bytes.subarray(1, bytes.length), this.algorithm); - if (parsedMPI instanceof Error) + if (parsedMPI instanceof Error) { throw parsedMPI; + } this.mpi = this.mpi.concat(parsedMPI); this.isDecrypted = true; } @@ -169,7 +175,7 @@ SecretKey.prototype.write = function () { /** Encrypt the payload. By default, we use aes256 and iterated, salted string - * to key specifier. If the key is in a decrypted state (isDecrypted == true) + * to key specifier. If the key is in a decrypted state (isDecrypted === true) * and the passphrase is empty or undefined, the key will be set as not encrypted. * This can be used to remove passphrase protection after calling decrypt(). * @param {String} passphrase @@ -213,8 +219,9 @@ function produceEncryptionKey(s2k, passphrase, algorithm) { * decrypted; false if not */ SecretKey.prototype.decrypt = function (passphrase) { - if (this.isDecrypted) + if (this.isDecrypted) { return true; + } var i = 0, symmetric, @@ -224,7 +231,7 @@ SecretKey.prototype.decrypt = function (passphrase) { // - [Optional] If string-to-key usage octet was 255 or 254, a one- // octet symmetric encryption algorithm. - if (s2k_usage == 255 || s2k_usage == 254) { + if (s2k_usage === 255 || s2k_usage === 254) { symmetric = this.encrypted[i++]; symmetric = enums.read(enums.symmetric, symmetric); @@ -254,7 +261,7 @@ SecretKey.prototype.decrypt = function (passphrase) { cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv); - var hash = s2k_usage == 254 ? + var hash = s2k_usage === 254 ? 'sha1' : 'mod'; diff --git a/src/packet/secret_subkey.js b/src/packet/secret_subkey.js index 384b7620..e07db468 100644 --- a/src/packet/secret_subkey.js +++ b/src/packet/secret_subkey.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -21,6 +21,8 @@ * @module packet/secret_subkey */ +'use strict'; + module.exports = SecretSubkey; var secretKey = require('./secret_key.js'), diff --git a/src/packet/signature.js b/src/packet/signature.js index 76c98dd8..2def8b7c 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -103,10 +103,11 @@ Signature.prototype.read = function (bytes) { switch (this.version) { case 3: // One-octet length of following hashed material. MUST be 5. - if (bytes[i++] != 5) + if (bytes[i++] !== 5) { util.print_debug("packet/signature.js\n" + 'invalid One-octet length of following hashed material.' + 'MUST be 5. @:' + (i - 1)); + } var sigpos = i; // One-octet signature type. @@ -142,7 +143,6 @@ Signature.prototype.read = function (bytes) { var i = 2; // subpacket data set (zero or more subpackets) - var subpacked_read = 0; while (i < 2 + subpacket_length) { var len = packet.readSimpleLength(bytes.subarray(i, bytes.length)); @@ -252,7 +252,7 @@ Signature.prototype.write_all_sub_packets = function () { arr.push(write_sub_packet(sub.exportable_certification, new Uint8Array([this.exportable ? 1 : 0]))); } if (this.trustLevel !== null) { - bytes = new Uint8Array([this.trustLevel,this.trustAmount]);; + bytes = new Uint8Array([this.trustLevel,this.trustAmount]); arr.push(write_sub_packet(sub.trust_signature, bytes)); } if (this.regularExpression !== null) { @@ -340,7 +340,7 @@ Signature.prototype.write_all_sub_packets = function () { var result = util.concatUint8Array(arr); var length = util.writeNumber(result.length, 2); - + return util.concatUint8Array([length, result]); }; @@ -392,7 +392,7 @@ Signature.prototype.read_sub_packet = function (bytes) { break; case 4: // Exportable Certification - this.exportable = bytes[mypos++] == 1; + this.exportable = bytes[mypos++] === 1; break; case 5: // Trust Signature @@ -405,7 +405,7 @@ Signature.prototype.read_sub_packet = function (bytes) { break; case 7: // Revocable - this.revocable = bytes[mypos++] == 1; + this.revocable = bytes[mypos++] === 1; break; case 9: // Key Expiration Time in seconds @@ -437,7 +437,7 @@ Signature.prototype.read_sub_packet = function (bytes) { case 20: // Notation Data // We don't know how to handle anything but a text flagged data. - if (bytes[mypos] == 0x80) { + if (bytes[mypos] === 0x80) { // We extract key/value tuple from the byte stream. mypos += 4; @@ -452,8 +452,8 @@ Signature.prototype.read_sub_packet = function (bytes) { this.notation = this.notation || {}; this.notation[name] = value; } else { - util.print_debug("Unsupported notation flag "+bytes[mypos]); - } + util.print_debug("Unsupported notation flag "+bytes[mypos]); + } break; case 21: // Preferred Hash Algorithms @@ -512,7 +512,7 @@ Signature.prototype.read_sub_packet = function (bytes) { this.embeddedSignature.read(bytes.subarray(mypos, bytes.length)); break; default: - util.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); + util.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); } }; @@ -541,17 +541,19 @@ Signature.prototype.toSign = function (type, data) { } else if (data.userattribute !== undefined) { tag = 0xD1; packet = data.userattribute; - } else throw new Error('Either a userid or userattribute packet needs to be ' + + } else { + throw new Error('Either a userid or userattribute packet needs to be ' + 'supplied for certification.'); + } var bytes = packet.write(); - if (this.version == 4) { + if (this.version === 4) { return util.concatUint8Array([this.toSign(t.key, data), new Uint8Array([tag]), util.writeNumber(bytes.length, 4), bytes]); - } else if (this.version == 3) { + } else if (this.version === 3) { return util.concatUint8Array([this.toSign(t.key, data), bytes]); } @@ -565,8 +567,9 @@ Signature.prototype.toSign = function (type, data) { })]); case t.key: - if (data.key === undefined) + if (data.key === undefined) { throw new Error('Key packet is required for this signature.'); + } return data.key.writeOld(); case t.key_revocation: @@ -584,7 +587,9 @@ Signature.prototype.toSign = function (type, data) { Signature.prototype.calculateTrailer = function () { // calculating the trailer // V3 signatures don't have a trailer - if (this.version == 3) return new Uint8Array(0); + if (this.version === 3) { + return new Uint8Array(0); + } var first = new Uint8Array([4, 0xFF]); //Version, ? return util.concatUint8Array([first, util.writeNumber(this.signatureData.length, 4)]); }; @@ -609,13 +614,15 @@ Signature.prototype.verify = function (key, data) { var mpicount = 0; // Algorithm-Specific Fields for RSA signatures: // - multiprecision number (MPI) of RSA signature value m**d mod n. - if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4) + if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4) { mpicount = 1; + } // Algorithm-Specific Fields for DSA signatures: // - MPI of DSA value r. // - MPI of DSA value s. - else if (publicKeyAlgorithm == 17) + else if (publicKeyAlgorithm === 17) { mpicount = 2; + } var mpi = [], i = 0; diff --git a/src/packet/sym_encrypted_session_key.js b/src/packet/sym_encrypted_session_key.js index 96a2ec32..8b33a3f2 100644 --- a/src/packet/sym_encrypted_session_key.js +++ b/src/packet/sym_encrypted_session_key.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -36,6 +36,8 @@ * @module packet/sym_encrypted_session_key */ +'use strict'; + var util = require('../util.js'), type_s2k = require('../type/s2k.js'), enums = require('../enums.js'), @@ -83,8 +85,9 @@ SymEncryptedSessionKey.prototype.read = function(bytes) { if (done < bytes.length) { this.encrypted = bytes.subarray(done, bytes.length); this.sessionKeyEncryptionAlgorithm = algo; - } else + } else { this.sessionKeyAlgorithm = algo; + } }; SymEncryptedSessionKey.prototype.write = function() { @@ -94,8 +97,9 @@ SymEncryptedSessionKey.prototype.write = function() { var bytes = util.concatUint8Array([new Uint8Array([this.version, enums.write(enums.symmetric, algo)]), this.s2k.write()]); - if (this.encrypted !== null) + if (this.encrypted !== null) { bytes = util.concatUint8Array([bytes, this.encrypted]); + } return bytes; }; @@ -117,7 +121,6 @@ SymEncryptedSessionKey.prototype.decrypt = function(passphrase) { this.sessionKey = key; } else { - var decrypted = crypto.cfb.normalDecrypt( algo, key, this.encrypted, null); diff --git a/src/packet/symmetrically_encrypted.js b/src/packet/symmetrically_encrypted.js index 8f8337d0..e43829cf 100644 --- a/src/packet/symmetrically_encrypted.js +++ b/src/packet/symmetrically_encrypted.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -28,6 +28,8 @@ * @module packet/symmetrically_encrypted */ +'use strict'; + module.exports = SymmetricallyEncrypted; var crypto = require('../crypto'), @@ -40,7 +42,7 @@ var crypto = require('../crypto'), function SymmetricallyEncrypted() { this.tag = enums.packet.symmetricallyEncrypted; this.encrypted = null; - /** Decrypted packets contained within. + /** Decrypted packets contained within. * @type {module:packet/packetlist} */ this.packets = null; this.ignore_mdc_error = config.ignore_mdc_error; @@ -70,7 +72,7 @@ SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) { (sessionKeyAlgorithm === 'aes128' || sessionKeyAlgorithm === 'aes192' || sessionKeyAlgorithm === 'aes256')) { - throw new Error('Decryption failed due to missing MDC in combination with modern cipher.') + throw new Error('Decryption failed due to missing MDC in combination with modern cipher.'); } this.packets.read(decrypted); }; diff --git a/src/packet/trust.js b/src/packet/trust.js index 0b85c076..30ca330c 100644 --- a/src/packet/trust.js +++ b/src/packet/trust.js @@ -3,6 +3,8 @@ * @module packet/trust */ +'use strict'; + module.exports = Trust; var enums = require('../enums.js'); @@ -19,6 +21,4 @@ function Trust() { * Currently empty as we ignore trust packets * @param {String} byptes payload of a tag 12 packet */ -Trust.prototype.read = function (bytes) { - -}; +Trust.prototype.read = function () {}; diff --git a/src/packet/user_attribute.js b/src/packet/user_attribute.js index bc599f48..c1c516bd 100644 --- a/src/packet/user_attribute.js +++ b/src/packet/user_attribute.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -36,6 +36,8 @@ * @module packet/user_attribute */ +'use strict'; + var util = require('../util.js'), packet = require('./packet.js'), enums = require('../enums.js'); diff --git a/src/packet/userid.js b/src/packet/userid.js index 84a05292..ba0d4cf6 100644 --- a/src/packet/userid.js +++ b/src/packet/userid.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -28,6 +28,8 @@ * @module packet/userid */ +'use strict'; + module.exports = Userid; var util = require('../util.js'), @@ -40,7 +42,7 @@ function Userid() { this.tag = enums.packet.userid; /** A string containing the user id. Usually in the form * John Doe - * @type {String} + * @type {String} */ this.userid = ''; } diff --git a/src/type/keyid.js b/src/type/keyid.js index 69e6a78d..fb5e06fc 100644 --- a/src/type/keyid.js +++ b/src/type/keyid.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -26,6 +26,8 @@ * @module type/keyid */ +'use strict'; + module.exports = Keyid; var util = require('../util.js'); @@ -34,7 +36,6 @@ var util = require('../util.js'); * @constructor */ function Keyid() { - this.bytes = ''; } @@ -55,7 +56,7 @@ Keyid.prototype.toHex = function() { }; Keyid.prototype.equals = function(keyid) { - return this.bytes == keyid.bytes; + return this.bytes === keyid.bytes; }; Keyid.prototype.isNull = function() { diff --git a/src/type/mpi.js b/src/type/mpi.js index 89e92d9d..0fc8bf5c 100644 --- a/src/type/mpi.js +++ b/src/type/mpi.js @@ -1,23 +1,23 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Hint: We hold our MPIs as an array of octets in big endian format preceeding a two // octet scalar: MPI: [a,b,c,d,e,f] -// - MPI size: (a << 8) | b +// - MPI size: (a << 8) | b // - MPI = c | d << 8 | e << ((MPI.length -2)*8) | f ((MPI.length -2)*8) /** @@ -34,6 +34,8 @@ * @module type/mpi */ +'use strict'; + module.exports = MPI; var BigInteger = require('../crypto/public_key/jsbn.js'), diff --git a/src/type/s2k.js b/src/type/s2k.js index e17c304d..82e73a1f 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -1,16 +1,16 @@ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3.0 of the License, or (at your option) any later version. -// +// // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -29,6 +29,8 @@ * @module type/s2k */ +'use strict'; + module.exports = S2K; var enums = require('../enums.js'), @@ -85,10 +87,10 @@ S2K.prototype.read = function (bytes) { break; case 'gnu': - if (util.Uint8Array2str(bytes.subarray(i, 3)) == "GNU") { + if (util.Uint8Array2str(bytes.subarray(i, 3)) === "GNU") { i += 3; // GNU var gnuExtType = 1000 + bytes[i++]; - if (gnuExtType == 1001) { + if (gnuExtType === 1001) { this.type = gnuExtType; // GnuPG extension mode 1001 -- don't write secret key at all } else { @@ -160,13 +162,15 @@ S2K.prototype.produce_key = function (passphrase, numBytes) { count = s2k.get_count(), data = util.concatUint8Array([s2k.salt,passphrase]); - while (isp.length * data.length < count) + while (isp.length * data.length < count) { isp.push(data); + } isp = util.concatUint8Array(isp); - if (isp.length > count) + if (isp.length > count) { isp = isp.subarray(0, count); + } return crypto.hash.digest(algorithm, util.concatUint8Array([prefix,isp])); diff --git a/src/worker/async_proxy.js b/src/worker/async_proxy.js index bf7b7103..b87061f0 100644 --- a/src/worker/async_proxy.js +++ b/src/worker/async_proxy.js @@ -116,7 +116,9 @@ AsyncProxy.prototype.seedRandom = function(size) { * @return {Uint8Array} */ AsyncProxy.prototype.getRandomBuffer = function(size) { - if (!size) return null; + if (!size) { + return null; + } var buf = new Uint8Array(size); crypto.random.getRandomValues(buf); return buf; @@ -134,7 +136,7 @@ AsyncProxy.prototype.terminate = function() { * @param {(Array|module:key~Key)} keys array of keys or single key, used to encrypt the message * @param {Uint8Array} data message as Uint8Array * @param {(Array|String)} passwords passwords for the message - * @param {Object} params parameter object with optional properties binary {Boolean}, + * @param {Object} params parameter object with optional properties binary {Boolean}, * filename {String}, and packets {Boolean} */ AsyncProxy.prototype.encryptMessage = function(keys, data, passwords, params) { @@ -397,8 +399,8 @@ AsyncProxy.prototype.decryptKey = function(privateKey, password) { }); self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data), - data = new key.Key(packetlist); + var packetlist = packet.List.fromStructuredClone(data); + data = new key.Key(packetlist); resolve(data); }, reject:reject }); }); @@ -425,8 +427,8 @@ AsyncProxy.prototype.decryptKeyPacket = function(privateKey, keyIds, password) { }); self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data), - data = new key.Key(packetlist); + var packetlist = packet.List.fromStructuredClone(data); + data = new key.Key(packetlist); resolve(data); }, reject:reject }); });