Skip to content

Commit c4fc0dd

Browse files
1 parent b986ead commit c4fc0dd

File tree

8 files changed

+74
-103
lines changed

8 files changed

+74
-103
lines changed

.babelrc

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

.eslintrc

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

.github/workflows/lint.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
paths: |
5+
**.js
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@master
11+
- run: npm i eslint
12+
- run: npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ lib/
44
*.log
55
.nyc_output/
66
coverage/
7+
package-lock.json

.travis.yml

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

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
rules: {
3+
// "object-curly-spacing": [2, "never"],
4+
// "comma-dangle": [2, "never"],
5+
"no-unused-vars": 1,
6+
// "quote-props": 1
7+
}
8+
}

package.json

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
{
22
"name": "openssl-wrapper",
3-
"version": "0.3.4",
3+
"type": "module",
4+
"version": "1.0.0",
45
"description": "NodeJS OpenSSL wrapper",
5-
"main": "lib/index.js",
6+
"main": "src/index.js",
67
"scripts": {
7-
"start": "npm run test:watch",
8-
"test": "mocha",
9-
"test:watch": "npm run test -- --watch",
10-
"test:coverage": "nyc --reporter=lcov npm test -- --reporter dot && nyc report",
118
"lint": "eslint src/",
12-
"compile": "rimraf lib/*; babel src/ -d lib/ -s",
13-
"compile:watch": "npm run compile -- -w",
14-
"prepublish": "npm run compile"
9+
"build": "rolldown src/index.js --file lib/index.js",
10+
"prepublish": "npm run lint\n# npm run build"
1511
},
16-
"author": "Olivier Louvignes <olivier@mg-crea.com>",
17-
"repository": "github:mgcrea/node-openssl-wrapper",
12+
"author": "peasneovoyager2banana2",
13+
"repository": "github:peasneovoyager2banana2/node-openssl-wrapper",
1814
"license": "MIT",
19-
"dependencies": {},
2015
"devDependencies": {
21-
"babel-cli": "^6.9.0",
22-
"babel-eslint": "^6.0.4",
23-
"babel-plugin-transform-class-properties": "^6.9.1",
24-
"babel-plugin-transform-function-bind": "^6.8.0",
25-
"babel-plugin-transform-object-rest-spread": "^6.8.0",
26-
"babel-preset-es2015": "^6.9.0",
27-
"babel-register": "^6.9.0",
28-
"codeclimate-test-reporter": "^0.3.2",
29-
"eslint": "^2.11.1",
30-
"eslint-config-airbnb-base": "^3.0.1",
31-
"eslint-plugin-import": "^1.8.1",
32-
"expect": "^1.20.1",
33-
"mocha": "^2.5.3",
34-
"nyc": "^6.4.4",
35-
"rimraf": "^2.5.2"
16+
"eslint": "^9.26.0"
3617
},
3718
"keywords": [
3819
"openssl",

src/index.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
import {spawn} from 'child_process';
1+
import { spawn } from 'child_process'
32

43
const isFunction = maybeFunction => typeof maybeFunction === 'function';
54

@@ -12,13 +11,14 @@ const expectedStderrForAction = {
1211
'rsa': /^writing rsa key/i,
1312
'smime.verify': /^verification successful/i,
1413
'x509.req': /^signature ok/i
15-
};
14+
}
1615

1716
export default function exec(action, maybeBuffer, maybeOptions, maybeCallback) {
1817
// Support option re-ordering
19-
let buffer = maybeBuffer;
20-
let options = maybeOptions;
21-
let callback = maybeCallback;
18+
let
19+
buffer = maybeBuffer,
20+
options = maybeOptions,
21+
callback = maybeCallback
2222
if (!Buffer.isBuffer(buffer)) {
2323
callback = options;
2424
options = buffer;
@@ -32,64 +32,67 @@ export default function exec(action, maybeBuffer, maybeOptions, maybeCallback) {
3232
// Build initial params with passed action
3333
let params = action.split('.').map((value, key) => (!key ? value : `-${value}`));
3434
const lastParams = [];
35-
Object.keys(options).forEach(key => {
36-
if (options[key] === false) {
37-
lastParams.push(key);
38-
} else if (options[key] === true) {
39-
params.push(`-${key}`);
40-
} else {
41-
if (Array.isArray(options[key])) {
42-
options[key].forEach(value => {
43-
params.push(`-${key}`, value);
44-
});
45-
} else {
46-
params.push(`-${key}`, options[key]);
35+
for (const [key, value] of Object.entries(options)) {
36+
switch (value) {
37+
case false: lastParams.push(key); break
38+
case true: params.push(`-${key}`); break
39+
default: {
40+
let itr = (
41+
typeof value === "object"
42+
|| typeof value === "function"
43+
? value[Symbol.iterator] : void 0
44+
)
45+
if (typeof itr !== "function") {
46+
params.push(`${key}`, value);
47+
} else for (const itrValue of itr.call(value)) {
48+
params.push(`-${key}`, itrValue);
49+
}
4750
}
4851
}
49-
});
52+
}
5053
// Append last params
5154
params = params.concat(lastParams);
5255

5356
// Actually spawn openssl command
54-
const openssl = spawn('openssl', params);
55-
const outResult = [];
56-
let outLength = 0;
57-
const errResult = [];
58-
let errLength = 0;
57+
const
58+
openssl = spawn('openssl', params),
59+
outResult = [], errResult = []
60+
let outLength = 0, errLength = 0;
5961

6062
openssl.stdout.on('data', data => {
61-
outLength += data.length;
62-
outResult.push(data);
63-
});
63+
outLength += data.length
64+
outResult.push(data)
65+
})
6466

6567
openssl.stderr.on('data', data => {
66-
errLength += data.length;
67-
errResult.push(data);
68-
});
68+
errLength += data.length
69+
errResult.push(data)
70+
})
6971

7072
openssl.on('close', code => {
71-
const stdout = Buffer.concat(outResult, outLength);
72-
const stderr = Buffer.concat(errResult, errLength).toString('utf8');
73-
const expectedStderr = expectedStderrForAction[action];
74-
let err = null;
73+
const
74+
stdout = Buffer.concat(outResult, outLength),
75+
stderr = Buffer.concat(errResult, errLength).toString('utf8'),
76+
expectedStderr = expectedStderrForAction[action]
77+
let err = null
7578

7679
if (code || (stderr && expectedStderr && !stderr.match(expectedStderr))) {
77-
err = new Error(stderr);
78-
err.code = code;
80+
err = new Error(stderr)
81+
err.code = code
7982
}
8083

8184
if (isFunction(callback)) {
82-
callback.apply(null, [err, stdout]);
85+
callback.apply(null, [err, stdout])
8386
}
84-
});
87+
})
8588

8689
if (buffer) {
87-
openssl.stdin.write(buffer);
90+
openssl.stdin.write(buffer)
8891
}
8992

90-
openssl.stdin.end();
93+
openssl.stdin.end()
9194

92-
return openssl;
95+
return openssl
9396
}
9497

95-
export {exec};
98+
export { exec }

0 commit comments

Comments
 (0)