Skip to content

Commit

Permalink
[eslint] switch to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 18, 2023
1 parent a67d0eb commit 83fe463
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 313 deletions.
44 changes: 44 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"root": true,

"extends": "@ljharb",

"rules": {
"func-style": "warn",
"indent": ["error", 2],
"sort-keys": "off",
},

"overrides": [
{
"files": "browser/index.js",
"rules": {
"func-name-matching": "off",
"max-statements-per-line": "off",
"no-underscore-dangle": "warn",
},
},
{
"files": "browser/verify.js",
"rules": {
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "off",
"no-param-reassign": "warn",
"no-plusplus": "warn",
"no-use-before-define": "warn",
}
},
{
"files": "browser/sign.js",
"rules": {
"max-params": "off",
// "max-statements": "off",
"max-statements-per-line": "off",
"no-param-reassign": "warn",
"no-plusplus": "warn",
"no-use-before-define": "warn",
}
},
],
}
4 changes: 3 additions & 1 deletion algos.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require('./browser/algorithms.json')
'use strict';

module.exports = require('./browser/algorithms.json');
126 changes: 63 additions & 63 deletions browser/index.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
var Buffer = require('safe-buffer').Buffer
var createHash = require('create-hash')
var stream = require('readable-stream')
var inherits = require('inherits')
var sign = require('./sign')
var verify = require('./verify')

var algorithms = require('./algorithms.json')
'use strict';

var Buffer = require('safe-buffer').Buffer;
var createHash = require('create-hash');
var stream = require('readable-stream');
var inherits = require('inherits');
var sign = require('./sign');
var verify = require('./verify');

var algorithms = require('./algorithms.json');
Object.keys(algorithms).forEach(function (key) {
algorithms[key].id = Buffer.from(algorithms[key].id, 'hex')
algorithms[key.toLowerCase()] = algorithms[key]
})
algorithms[key].id = Buffer.from(algorithms[key].id, 'hex');
algorithms[key.toLowerCase()] = algorithms[key];
});

function Sign (algorithm) {
stream.Writable.call(this)
function Sign(algorithm) {
stream.Writable.call(this);

var data = algorithms[algorithm]
if (!data) throw new Error('Unknown message digest')
var data = algorithms[algorithm];
if (!data) { throw new Error('Unknown message digest'); }

this._hashType = data.hash
this._hash = createHash(data.hash)
this._tag = data.id
this._signType = data.sign
this._hashType = data.hash;
this._hash = createHash(data.hash);
this._tag = data.id;
this._signType = data.sign;
}
inherits(Sign, stream.Writable)
inherits(Sign, stream.Writable);

Sign.prototype._write = function _write (data, _, done) {
this._hash.update(data)
done()
}
Sign.prototype._write = function _write(data, _, done) {
this._hash.update(data);
done();
};

Sign.prototype.update = function update (data, enc) {
if (typeof data === 'string') data = Buffer.from(data, enc)
Sign.prototype.update = function update(data, enc) {
this._hash.update(typeof data === 'string' ? Buffer.from(data, enc) : data);

this._hash.update(data)
return this
}
return this;
};

Sign.prototype.sign = function signMethod (key, enc) {
this.end()
var hash = this._hash.digest()
var sig = sign(hash, key, this._hashType, this._signType, this._tag)
Sign.prototype.sign = function signMethod(key, enc) {
this.end();
var hash = this._hash.digest();
var sig = sign(hash, key, this._hashType, this._signType, this._tag);

return enc ? sig.toString(enc) : sig
}
return enc ? sig.toString(enc) : sig;
};

function Verify (algorithm) {
stream.Writable.call(this)
function Verify(algorithm) {
stream.Writable.call(this);

var data = algorithms[algorithm]
if (!data) throw new Error('Unknown message digest')
var data = algorithms[algorithm];
if (!data) { throw new Error('Unknown message digest'); }

this._hash = createHash(data.hash)
this._tag = data.id
this._signType = data.sign
this._hash = createHash(data.hash);
this._tag = data.id;
this._signType = data.sign;
}
inherits(Verify, stream.Writable)
inherits(Verify, stream.Writable);

Verify.prototype._write = function _write (data, _, done) {
this._hash.update(data)
done()
}
Verify.prototype._write = function _write(data, _, done) {
this._hash.update(data);
done();
};

Verify.prototype.update = function update (data, enc) {
if (typeof data === 'string') data = Buffer.from(data, enc)
Verify.prototype.update = function update(data, enc) {
this._hash.update(typeof data === 'string' ? Buffer.from(data, enc) : data);

this._hash.update(data)
return this
}
return this;
};

Verify.prototype.verify = function verifyMethod (key, sig, enc) {
if (typeof sig === 'string') sig = Buffer.from(sig, enc)
Verify.prototype.verify = function verifyMethod(key, sig, enc) {
var sigBuffer = typeof sig === 'string' ? Buffer.from(sig, enc) : sig;

this.end()
var hash = this._hash.digest()
return verify(sig, hash, key, this._signType, this._tag)
}
this.end();
var hash = this._hash.digest();
return verify(sigBuffer, hash, key, this._signType, this._tag);
};

function createSign (algorithm) {
return new Sign(algorithm)
function createSign(algorithm) {
return new Sign(algorithm);
}

function createVerify (algorithm) {
return new Verify(algorithm)
function createVerify(algorithm) {
return new Verify(algorithm);
}

module.exports = {
Sign: createSign,
Verify: createVerify,
createSign: createSign,
createVerify: createVerify
}
};
Loading

0 comments on commit 83fe463

Please sign in to comment.