Skip to content

Commit

Permalink
Merge pull request #10 from omsmith/eslint
Browse files Browse the repository at this point in the history
Eslint
  • Loading branch information
omsmith committed Jan 18, 2016
2 parents 1b3fefc + af11071 commit f184fea
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 178 deletions.
1 change: 1 addition & 0 deletions .eslintignore
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "brightspace/node-config",
"env": {
"es6": false
}
}
99 changes: 0 additions & 99 deletions .jscs.json

This file was deleted.

2 changes: 0 additions & 2 deletions .jshintignore

This file was deleted.

11 changes: 0 additions & 11 deletions .jshintrc

This file was deleted.

5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
.npmignore

.editorconfig
.jscs.json
.jshintrc
.jshintignore
.eslintignore
.eslintrc

spec
coverage
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ signature. Returns a `Buffer`

### Code Style

This repository is configured with [EditorConfig][EditorConfig], [jscs][jscs]
and [JSHint][JSHint] rules.
This repository is configured with [EditorConfig][EditorConfig] and
[ESLint][ESLint] rules.

[EditorConfig]: http://editorconfig.org/
[jscs]: http://jscs.info/
[JSHint]: http://jshint.com/
[ESLint]: http://eslint.org
6 changes: 3 additions & 3 deletions benchmarks/der-to-jose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ var sigs = [
['MIGHAkFgiYpVsYxx6XiQp2OXscRW/PrbEcoime/FftP+B7x4QVa+M3KZzXlfP66zKqjo7O3nwK2s8GbTftW8H4HwojzimwJCAYQNsozTpCo5nwIkBgelcfIQ0y/U/60TbNH1+rlKpFDCFs6Q1ro7R1tjtXoAUb9aPIOVyXGiSQX/+fcmmWs1rkJU', 'ES512']
];

var sigBuffers = sigs.map(function (sig) {
var sigBuffers = sigs.map(function(sig) {
return [new Buffer(sig[0], 'base64'), sig[1]];
});

module.exports.compare = {
fromBase64: function () {
fromBase64: function() {
for (var i = 0, n = sigs.length; i < n; ++i) {
derToJose.apply(null, sigs[i]);
}
},
fromBuffer: function () {
fromBuffer: function() {
for (var i = 0, n = sigBuffers.length; i < n; ++i) {
derToJose.apply(null, sigBuffers[i]);
}
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/jose-to-der.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ var sigs = [
['AFKapY_5gq60n8NZ_C2iOQFov7sXgcMyDzCrnGsbvE7OlSBKbgj95aZ7GtdSdbw6joK2jjWJio8IgKNB9o11GdMTADfLUsv9oAJvmIApsmsPBAIe1vH8oeHYiDMBEz9OQcwS5eL-r1iO2v7oxzl9zZb1rA5kzBqS93ARCPKbjgcr602r', 'ES512']
];

var sigBuffers = sigs.map(function (sig) {
var sigBuffers = sigs.map(function(sig) {
return [new Buffer(sig[0], 'base64'), sig[1]];
});

module.exports.compare = {
fromBase64: function () {
fromBase64: function() {
for (var i = 0, n = sigs.length; i < n; ++i) {
joseToDer.apply(null, sigs[i]);
}
},
fromBuffer: function () {
fromBuffer: function() {
for (var i = 0, n = sigBuffers.length; i < n; ++i) {
joseToDer.apply(null, sigBuffers[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/happy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var sslalgs = {
'ES512': 'RSA-SHA512'
};

['ES256', 'ES384', 'ES512'].forEach(function (alg) {
['ES256', 'ES384', 'ES512'].forEach(function(alg) {
for (var i = 0; i < 10; ++i) {
var pem = keygen(alg);

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Translate ECDSA signatures between ASN.1/DER and JOSE-style concatenation",
"main": "src/ecdsa-sig-formatter.js",
"scripts": {
"check-style": "eslint .",
"pretest": "npm run check-style",
"test": "istanbul cover --root src _mocha -- spec",
"report-cov": "cat ./coverage/lcov.info | coveralls"
},
Expand Down Expand Up @@ -34,6 +36,8 @@
"chai": "^3.0.0",
"coveralls": "^2.11.2",
"elliptic": "^6.0.1",
"eslint": "^1.10.3",
"eslint-config-brightspace": "^0.1.0",
"istanbul": "^0.3.15",
"jwk-to-pem": "^1.2.2",
"mocha": "^2.2.5"
Expand Down
47 changes: 23 additions & 24 deletions spec/der-to-jose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,88 @@ var describe = mocha.describe,

var format = require('..');

var MAX_LENGTH_OCTET = 0x80,
CLASS_UNIVERSAL = 0,
var CLASS_UNIVERSAL = 0,
PRIMITIVE_BIT = 0x20,
TAG_SEQ = (0x10 | PRIMITIVE_BIT) | (CLASS_UNIVERSAL << 6),
TAG_INT = 0x02 | (CLASS_UNIVERSAL << 6);

describe('#derToJose', function () {
describe('should throw for', function () {
it('no signature', function () {
function fn () {
describe('#derToJose', function() {
describe('should throw for', function() {
it('no signature', function() {
function fn() {
return format.derToJose();
}

expect(fn).to.throw(TypeError);
});

it('non buffer or base64 signature', function () {
function fn () {
it('non buffer or base64 signature', function() {
function fn() {
return format.derToJose(123);
}

expect(fn).to.throw(TypeError);
});

it('unknown algorithm', function () {
function fn () {
it('unknown algorithm', function() {
function fn() {
return format.derToJose('Zm9vLmJhci5iYXo=', 'foozleberries');
}

expect(fn).to.throw(/"foozleberries"/);
});

it('no seq', function () {
it('no seq', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ + 1; // not seq

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /expected "seq"/);
});

it('seq length exceeding input', function () {
it('seq length exceeding input', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 10;

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /length/);
});

it('r is not marked as int', function () {
it('r is not marked as int', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 8;
input[2] = TAG_INT + 1; // not int

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /expected "int".+"r"/);
});

it('r length exceeds available input', function () {
it('r length exceeds available input', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 8;
input[2] = TAG_INT;
input[3] = 5;

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /"r".+length/);
});

it('s is not marked as int', function () {
it('s is not marked as int', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 8;
Expand All @@ -100,14 +99,14 @@ describe('#derToJose', function () {
input[5] = 0;
input[6] = TAG_INT + 1; // not int

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /expected "int".+"s"/);
});

it('s length exceeds available input', function () {
it('s length exceeds available input', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 8;
Expand All @@ -118,14 +117,14 @@ describe('#derToJose', function () {
input[6] = TAG_INT;
input[7] = 3;

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

expect(fn).to.throw(Error, /"s".+length/);
});

it('s length does not consume available input', function () {
it('s length does not consume available input', function() {
var input = new Buffer(10);
input[0] = TAG_SEQ;
input[1] = 8;
Expand All @@ -136,7 +135,7 @@ describe('#derToJose', function () {
input[6] = TAG_INT;
input[7] = 1;

function fn () {
function fn() {
format.derToJose(input, 'ES256');
}

Expand Down
Loading

0 comments on commit f184fea

Please sign in to comment.