Skip to content

Commit

Permalink
Fix more linting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlehn committed Feb 23, 2019
1 parent 8acd150 commit 5478021
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 153 deletions.
28 changes: 12 additions & 16 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"node": true
env: {
browser: true,
commonjs: true,
node: true
},
"extends": ["eslint-config-digitalbazaar"],
"parserOptions": {
"ecmaVersion": 5
extends: ['eslint-config-digitalbazaar'],
parserOptions: {
ecmaVersion: 5
},
"rules": {
"quotes": [
"error",
"single"
],
rules: {
// overrides to support ES5, remove when updated to ES20xx
"no-unused-vars": "warn",
"no-var": "off",
"object-shorthand": "off",
"prefer-const": "off",
'no-unused-vars': 'warn',
'no-var': 'off',
'object-shorthand': 'off',
'prefer-const': 'off'
}
};
2 changes: 1 addition & 1 deletion examples/create-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ try {
console.log('Certificate verified.');
}
return true;
});
});
} catch(ex) {
console.log('Certificate verification failure: ' +
JSON.stringify(ex, null, 2));
Expand Down
2 changes: 1 addition & 1 deletion examples/sign-p7.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {
type: forge.pki.oids.messageDigest
// value will be auto-populated at signing time
}, {
type: forge.pki.oids.signingTime,
type: forge.pki.oids.signingTime
// value will be auto-populated at signing time
//value: new Date('2050-01-01T00:00:00Z')
}]
Expand Down
8 changes: 4 additions & 4 deletions flash/policyserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ let policyFile =
// Looks for a request string and returns the policy file.
exports.policyServer = function(port) {
let prefix = '[policy-server] ';
let server = net.createServer((socket) => {
let server = net.createServer(socket => {
let remoteAddress = socket.remoteAddress + ':' + socket.remotePort;
console.log(prefix + 'new client connection from %s', remoteAddress);

// deal with strings
socket.setEncoding('utf8');

socket.on('data', (d) => {
socket.on('data', d => {
if(d.indexOf('<policy-file-request/>') === 0) {
console.log(prefix + 'policy file request from: %s', remoteAddress);
socket.write(policyFile);
Expand All @@ -41,11 +41,11 @@ exports.policyServer = function(port) {
socket.once('close', () => {
console.log(prefix + 'connection from %s closed', remoteAddress);
});
socket.on('error', (err) => {
socket.on('error', err => {
console.error(
prefix + 'connection %s error: %s', remoteAddress, err.message);
});
}).on('error', (err) => {
}).on('error', err => {
throw err;
});
server.listen(port, () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"test-server-webid": "node tests/websockets/server-webid.js",
"coverage": "rm -rf coverage && nyc --reporter=lcov --reporter=text-summary npm test",
"coverage-report": "nyc report",
"lint": "eslint *.js lib/*.js tests/*.js tests/unit/*.js tests/legacy/*.js tests/issues/*.js tests/websockets/*.js"
"lint": "eslint *.js lib/*.js tests/*.js tests/**/*.js examples/*.js flash/*.js"
},
"nyc": {
"exclude": [
Expand Down
32 changes: 17 additions & 15 deletions tests/benchmarks/so-44303784.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const forge = require('../..');
const assert = require('assert');
const crypto = require('crypto');

const pwd = "aStringPassword";
const pwd = 'aStringPassword';
const iv = forge.random.getBytesSync(16);
const salt = forge.random.getBytesSync(16);
const key = forge.pkcs5.pbkdf2(pwd, salt, 100, 16);
Expand Down Expand Up @@ -86,7 +86,7 @@ function test_node(bytes) {
function data(megs) {
// slower single chunk
const start = new Date();
var x = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
var x = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
var plain = '';
const minlen = megs * 1024 * 1024;
while(plain.length < minlen) {
Expand Down Expand Up @@ -117,7 +117,7 @@ function data_chunk(megs, chunkSize) {
// faster with chunksize
const start = new Date();
// make some large plain text bigger than some size
var x = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
var x = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
var plain = '';
const minlen = megs * 1024 * 1024;
while(plain.length < minlen) {
Expand Down Expand Up @@ -185,8 +185,10 @@ function compareImpl() {
tns.forEach(res => assert(input.plain == res.plain));
const tn = tns.reduce((prev, cur) => prev.time < cur.time ? prev : cur);

csv += `${i}\t${tf.time}\t${i/tf.time}\t${tfc.time}\t${i/tfc.time}\t${tn.time}\t${i/tn.time}\t${tf.time/tn.time}\t${tfc.time/tn.time}\n`;
console.log(`m:${i} tf:${tf.time} tf/s:${i/tf.time} tfc:${tfc.time} tfc/s:${i/tfc.time} tn:${tn.time} tn/s:${i/tn.time} sf:${tf.time/tn.time} sfc:${tfc.time/tn.time}`);
/* eslint-disable max-len */
csv += `${i}\t${tf.time}\t${i / tf.time}\t${tfc.time}\t${i / tfc.time}\t${tn.time}\t${i / tn.time}\t${tf.time / tn.time}\t${tfc.time / tn.time}\n`;
console.log(`m:${i} tf:${tf.time} tf/s:${i / tf.time} tfc:${tfc.time} tfc/s:${i / tfc.time} tn:${tn.time} tn/s:${i / tn.time} sf:${tf.time / tn.time} sfc:${tfc.time / tn.time}`);
/* eslint-enable max-len */
}
console.log(csv);
}
Expand All @@ -196,21 +198,21 @@ function compareDecChunkSize() {
let csv = '';
const input = data_chunk(megs, 1024 * 64);
function _test(k) {
chunkSize = 1024 * k;
const chunkSize = 1024 * k;
const tfcs = [
test_forge_chunk(input.encrypted, chunkSize),
test_forge_chunk(input.encrypted, chunkSize),
test_forge_chunk(input.encrypted, chunkSize)
];
tfcs.forEach(res => assert(input.plain == res.plain));
const tfc = tfcs.reduce((prev, cur) => prev.time < cur.time ? prev : cur);
csv += `${k}\t${tfc.time}\t${megs/tfc.time}\n`;
console.log(`k:${k} tfc:${tfc.time} tfc/s:${megs/tfc.time}`);
csv += `${k}\t${tfc.time}\t${megs / tfc.time}\n`;
console.log(`k:${k} tfc:${tfc.time} tfc/s:${megs / tfc.time}`);
}
// sweep KB chunkSize
const sweep = [
1,2,4,8,16,32,64,96,128,160,192,256,
320,384,448,512,576,640,704,768,832,896,960,1024
1, 2, 4, 8, 16, 32, 64, 96, 128, 160, 192, 256,
320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024
];
sweep.forEach(k => _test(k));
console.log(csv);
Expand All @@ -220,20 +222,20 @@ function compareEncChunkSize() {
const megs = 10;
let csv = '';
function _test(k) {
chunkSize = 1024 * k;
const chunkSize = 1024 * k;
const dcs = [
data_chunk(megs, chunkSize),
data_chunk(megs, chunkSize),
data_chunk(megs, chunkSize)
];
const dc = dcs.reduce((prev, cur) => prev.time < cur.time ? prev : cur);
csv += `${k}\t${dc.time}\t${megs/dc.time}\n`;
console.log(`k:${k} dc:${dc.time} dc/s:${megs/dc.time}`);
csv += `${k}\t${dc.time}\t${megs / dc.time}\n`;
console.log(`k:${k} dc:${dc.time} dc/s:${megs / dc.time}`);
}
// sweep KB chunkSize
const sweep = [
1,2,4,8,16,32,64,96,128,160,192,256,
320,384,448,512,576,640,704,768,832,896,960,1024
1, 2, 4, 8, 16, 32, 64, 96, 128, 160, 192, 256,
320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024
];
sweep.forEach(k => _test(k));
console.log(csv);
Expand Down
128 changes: 64 additions & 64 deletions tests/unit/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,79 +40,79 @@ var UTIL = require('../../lib/util');
});

it('should encrypt a single block with a 192-bit key', function() {
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617];
var block = [0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff];

var output = [];
var w = AES._expandKey(key, false);
AES._updateBlock(w, block, output, false);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), 'dda97ca4864cdfe06eaf70a0ec0d7191');
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617];
var block = [0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff];

var output = [];
var w = AES._expandKey(key, false);
AES._updateBlock(w, block, output, false);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), 'dda97ca4864cdfe06eaf70a0ec0d7191');
});

it('should decrypt a single block with a 192-bit key', function() {
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617];
var block = [0xdda97ca4, 0x864cdfe0, 0x6eaf70a0, 0xec0d7191];

var output = [];
var w = AES._expandKey(key, true);
AES._updateBlock(w, block, output, true);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '00112233445566778899aabbccddeeff');
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617];
var block = [0xdda97ca4, 0x864cdfe0, 0x6eaf70a0, 0xec0d7191];

var output = [];
var w = AES._expandKey(key, true);
AES._updateBlock(w, block, output, true);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '00112233445566778899aabbccddeeff');
});

it('should encrypt a single block with a 256-bit key', function() {
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f];
var block = [0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff];

var output = [];
var w = AES._expandKey(key, false);
AES._updateBlock(w, block, output, false);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '8ea2b7ca516745bfeafc49904b496089');
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f];
var block = [0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff];

var output = [];
var w = AES._expandKey(key, false);
AES._updateBlock(w, block, output, false);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '8ea2b7ca516745bfeafc49904b496089');
});

it('should decrypt a single block with a 256-bit key', function() {
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f];
var block = [0x8ea2b7ca, 0x516745bf, 0xeafc4990, 0x4b496089];

var output = [];
var w = AES._expandKey(key, true);
AES._updateBlock(w, block, output, true);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '00112233445566778899aabbccddeeff');
var key = [
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f];
var block = [0x8ea2b7ca, 0x516745bf, 0xeafc4990, 0x4b496089];

var output = [];
var w = AES._expandKey(key, true);
AES._updateBlock(w, block, output, true);

var out = UTIL.createBuffer();
out.putInt32(output[0]);
out.putInt32(output[1]);
out.putInt32(output[2]);
out.putInt32(output[3]);

ASSERT.equal(out.toHex(), '00112233445566778899aabbccddeeff');
});

// AES-128-ECB
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ var UTIL = require('../../lib/util');
// validator check
if(!throws && options.v) {
var capture = {};
var errors = []
var errors = [];
var asn1ok = ASN1.validate(asn1, options.v, capture, errors);
ASSERT.deepEqual(errors, []);
if(options.captured) {
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/ed25519.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var ASSERT = require('assert');
var FORGE = require('../../lib/forge');
var ED25519 = require('../../lib/ed25519');
var RANDOM = require('../../lib/random');
var SHA256 = require('../../lib/sha256');
var UTIL = require('../../lib/util');

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/pkcs1.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,13 @@ var UTIL = require('../../lib/util');
message: 'SoZglTTuQ0psvKP36WLnbUVeMmTBn2Bfbl/2E3xlxW1/s0TNUryTN089FmyfDG+cUGutGTMJctI=',
seed: 'HKwZzpk971X5ggP2hSiWyVzMofMcrBnOmT3vVfmCA/Y=',
encrypted: 'AooWJVOiXRikAgxb8XW7nkDMKIcrCgZNTV0sY352+QatjTq4go6/DtieHvIgUgb/QYBYlOPOZkdiMWXtOFdapIMRFraGeq4mKhEVmSM8G5mpVgc62nVR0jX49AXeuw7kMGxnKTV4whJanPYYQRoOb0L4Mf+8uJ5QdqBE03Ohupsp'
/* FIXME: could not convert 4.2', to SHA-256, message too long
/* FIXME: could not convert 4.2', to SHA-256, message too long
}, {
title: 'RSAES-OAEP Encryption Example 4.2',
message: 'sK3E8/4R2lnOmSdz2QWZQ8AwRkl+6dn5oG3xFm20bZj1jSfsB0wC7ubL4kSci5/FCAxcP0QzCSUS7EaqeTdDyA==',
seed: '9UXViXWF49txqgy42nbFHQMq6WM=',
encrypted: 'AJe2mMYWVkWzA0hvv1oqRHnA7oWIm1QabwuFjWtll7E7hU60+DmvAzmagNeb2mV4yEH5DWRXFbKA03FDmS3RhsgLlJt3XK6XNw5OyXRDE2xtpITpcP/bEyOiCEeCHTsYOB3hO7SarqZlMMSkuCcfPq4XLNNm4H5mNvEBnSoortFe'
*/
*/
}, {
title: 'RSAES-OAEP Encryption Example 4.3',
message: 'v21C5wFwex0CBrDItFoccmQf8SiJIZqCveqWW155qWsNAWPtnVeOya2iDy+88eo8QInYNBm6gbDGDzYG2pk=',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/pkcs7.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ var UTIL = require('../../lib/util');
ASSERT.equal(p7.recipients[0].encryptedContent.content.length, 256);

ASSERT.equal(p7.encryptedContent.algorithm, PKI.oids['aes256-CBC']);
ASSERT.equal(p7.encryptedContent.parameter.data.length, 16); // IV
ASSERT.equal(p7.encryptedContent.parameter.data.length, 16); // IV
});

it('should import indefinite length message from PEM', function() {
Expand Down
Loading

0 comments on commit 5478021

Please sign in to comment.