Skip to content

Commit ae02fd6

Browse files
committed
[Tests] standard -> eslint, make test dir, etc
1 parent 42528f2 commit ae02fd6

File tree

5 files changed

+238
-193
lines changed

5 files changed

+238
-193
lines changed

.eslintrc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
{
2-
"extends": ["standard"]
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"func-style": "off",
8+
},
9+
10+
"overrides": [
11+
{
12+
"files": [
13+
"./index.js",
14+
"./test/index.js",
15+
],
16+
"rules": {
17+
"no-underscore-dangle": "warn",
18+
},
19+
},
20+
],
321
}

index.js

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,103 @@
1-
var Buffer = require('safe-buffer').Buffer
2-
var Transform = require('stream').Transform
3-
var StringDecoder = require('string_decoder').StringDecoder
4-
var inherits = require('inherits')
5-
6-
function CipherBase (hashMode) {
7-
Transform.call(this)
8-
this.hashMode = typeof hashMode === 'string'
9-
if (this.hashMode) {
10-
this[hashMode] = this._finalOrDigest
11-
} else {
12-
this.final = this._finalOrDigest
13-
}
14-
if (this._final) {
15-
this.__final = this._final
16-
this._final = null
17-
}
18-
this._decoder = null
19-
this._encoding = null
1+
'use strict';
2+
3+
var Buffer = require('safe-buffer').Buffer;
4+
var Transform = require('stream').Transform;
5+
var StringDecoder = require('string_decoder').StringDecoder;
6+
var inherits = require('inherits');
7+
8+
function CipherBase(hashMode) {
9+
Transform.call(this);
10+
this.hashMode = typeof hashMode === 'string';
11+
if (this.hashMode) {
12+
this[hashMode] = this._finalOrDigest;
13+
} else {
14+
this['final'] = this._finalOrDigest;
15+
}
16+
if (this._final) {
17+
this.__final = this._final;
18+
this._final = null;
19+
}
20+
this._decoder = null;
21+
this._encoding = null;
2022
}
21-
inherits(CipherBase, Transform)
23+
inherits(CipherBase, Transform);
2224

2325
CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
24-
if (typeof data === 'string') {
25-
data = Buffer.from(data, inputEnc)
26-
}
26+
var bufferData = typeof data === 'string' ? Buffer.from(data, inputEnc) : data;
2727

28-
var outData = this._update(data)
29-
if (this.hashMode) return this
28+
var outData = this._update(bufferData);
29+
if (this.hashMode) {
30+
return this;
31+
}
3032

31-
if (outputEnc) {
32-
outData = this._toString(outData, outputEnc)
33-
}
33+
if (outputEnc) {
34+
outData = this._toString(outData, outputEnc);
35+
}
3436

35-
return outData
36-
}
37+
return outData;
38+
};
3739

38-
CipherBase.prototype.setAutoPadding = function () {}
40+
CipherBase.prototype.setAutoPadding = function () {};
3941
CipherBase.prototype.getAuthTag = function () {
40-
throw new Error('trying to get auth tag in unsupported state')
41-
}
42+
throw new Error('trying to get auth tag in unsupported state');
43+
};
4244

4345
CipherBase.prototype.setAuthTag = function () {
44-
throw new Error('trying to set auth tag in unsupported state')
45-
}
46+
throw new Error('trying to set auth tag in unsupported state');
47+
};
4648

4749
CipherBase.prototype.setAAD = function () {
48-
throw new Error('trying to set aad in unsupported state')
49-
}
50+
throw new Error('trying to set aad in unsupported state');
51+
};
5052

5153
CipherBase.prototype._transform = function (data, _, next) {
52-
var err
53-
try {
54-
if (this.hashMode) {
55-
this._update(data)
56-
} else {
57-
this.push(this._update(data))
58-
}
59-
} catch (e) {
60-
err = e
61-
} finally {
62-
next(err)
63-
}
64-
}
54+
var err;
55+
try {
56+
if (this.hashMode) {
57+
this._update(data);
58+
} else {
59+
this.push(this._update(data));
60+
}
61+
} catch (e) {
62+
err = e;
63+
} finally {
64+
next(err);
65+
}
66+
};
6567
CipherBase.prototype._flush = function (done) {
66-
var err
67-
try {
68-
this.push(this.__final())
69-
} catch (e) {
70-
err = e
71-
}
72-
73-
done(err)
74-
}
68+
var err;
69+
try {
70+
this.push(this.__final());
71+
} catch (e) {
72+
err = e;
73+
}
74+
75+
done(err);
76+
};
7577
CipherBase.prototype._finalOrDigest = function (outputEnc) {
76-
var outData = this.__final() || Buffer.alloc(0)
77-
if (outputEnc) {
78-
outData = this._toString(outData, outputEnc, true)
79-
}
80-
return outData
81-
}
78+
var outData = this.__final() || Buffer.alloc(0);
79+
if (outputEnc) {
80+
outData = this._toString(outData, outputEnc, true);
81+
}
82+
return outData;
83+
};
8284

8385
CipherBase.prototype._toString = function (value, enc, fin) {
84-
if (!this._decoder) {
85-
this._decoder = new StringDecoder(enc)
86-
this._encoding = enc
87-
}
86+
if (!this._decoder) {
87+
this._decoder = new StringDecoder(enc);
88+
this._encoding = enc;
89+
}
8890

89-
if (this._encoding !== enc) throw new Error('can\'t switch encodings')
91+
if (this._encoding !== enc) {
92+
throw new Error('can’t switch encodings');
93+
}
9094

91-
var out = this._decoder.write(value)
92-
if (fin) {
93-
out += this._decoder.end()
94-
}
95+
var out = this._decoder.write(value);
96+
if (fin) {
97+
out += this._decoder.end();
98+
}
9599

96-
return out
97-
}
100+
return out;
101+
};
98102

99-
module.exports = CipherBase
103+
module.exports = CipherBase;

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "abstract base class for crypto-streams",
55
"main": "index.js",
66
"scripts": {
7-
"test": "node test.js | tspec"
7+
"lint": "eslint --ext=js,.mjs .",
8+
"pretest": "npm run lint",
9+
"test": "npm run tests-only",
10+
"tests-only": "tape 'test/**/*.js'",
11+
"posttest": "npx npm@'>=10.2' audit --production"
812
},
913
"repository": {
1014
"type": "git",
@@ -25,8 +29,8 @@
2529
"safe-buffer": "^5.0.1"
2630
},
2731
"devDependencies": {
28-
"standard": "^10.0.2",
29-
"tap-spec": "^4.1.0",
30-
"tape": "^4.2.0"
32+
"@ljharb/eslint-config": "^21.1.1",
33+
"eslint": "=8.8.0",
34+
"tape": "^5.9.0"
3135
}
3236
}

test.js

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)