diginext-utils 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/file/detectPrivateKey.js +4 -9
- package/dist/file/detectPrivateKey.js.map +1 -1
- package/dist/file/detectPrivateKeyByFilePath.d.ts +2 -0
- package/dist/file/detectPrivateKeyByFilePath.js +24 -0
- package/dist/file/detectPrivateKeyByFilePath.js.map +1 -0
- package/dist/file/getAllFiles.d.ts +1 -1
- package/dist/file/getAllFiles.js +14 -4
- package/dist/file/getAllFiles.js.map +1 -1
- package/esm/file/detectPrivateKey.js +4 -9
- package/esm/file/detectPrivateKey.js.map +1 -1
- package/esm/file/detectPrivateKeyByFilePath.d.ts +2 -0
- package/esm/file/detectPrivateKeyByFilePath.js +17 -0
- package/esm/file/detectPrivateKeyByFilePath.js.map +1 -0
- package/esm/file/getAllFiles.d.ts +1 -1
- package/esm/file/getAllFiles.js +14 -4
- package/esm/file/getAllFiles.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.detectPrivateKey = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
7
|
const getAllFiles_1 = __importDefault(require("./getAllFiles"));
|
|
8
|
+
const detectPrivateKeyByFilePath_1 = __importDefault(require("./detectPrivateKeyByFilePath"));
|
|
9
9
|
function detectPrivateKey(dirPath) {
|
|
10
10
|
//
|
|
11
11
|
const list = (0, getAllFiles_1.default)(dirPath);
|
|
@@ -13,16 +13,11 @@ function detectPrivateKey(dirPath) {
|
|
|
13
13
|
const _list = [];
|
|
14
14
|
for (let i = 0; i < list.length; i++) {
|
|
15
15
|
const _path = list[i];
|
|
16
|
-
|
|
17
|
-
const fileContents = fs_1.default.readFileSync(_path);
|
|
18
|
-
// Check if the file contents contain a private key
|
|
19
|
-
if (fileContents.includes("-----BEGIN ")) {
|
|
20
|
-
// console.log("Private key detected");
|
|
21
|
-
_list.push(_path);
|
|
22
|
-
result = false;
|
|
16
|
+
if ((0, detectPrivateKeyByFilePath_1.default)(_path)) {
|
|
23
17
|
}
|
|
24
18
|
else {
|
|
25
|
-
|
|
19
|
+
_list.push(_path);
|
|
20
|
+
result = false;
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
23
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectPrivateKey.js","sourceRoot":"","sources":["../../src/file/detectPrivateKey.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"detectPrivateKey.js","sourceRoot":"","sources":["../../src/file/detectPrivateKey.ts"],"names":[],"mappings":";;;;;;AACA,gEAAwC;AACxC,8FAAsE;AAEtE,SAAwB,gBAAgB,CAAC,OAAe;IACvD,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC;IAElC,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAI,IAAA,oCAA0B,EAAC,KAAK,CAAC,EAAE;SACtC;aAAM;YACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,MAAM,GAAG,KAAK,CAAC;SACf;KACD;IAED,OAAO;QACN,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,KAAK;KACX,CAAC;AACH,CAAC;AAtBD,mCAsBC;AAEQ,4CAAgB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.detectPrivateKeyByFilePath = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
function detectPrivateKeyByFilePath(_path) {
|
|
9
|
+
//
|
|
10
|
+
if (!fs_1.default.existsSync(_path))
|
|
11
|
+
return false;
|
|
12
|
+
const fileContents = fs_1.default.readFileSync(_path);
|
|
13
|
+
switch (true) {
|
|
14
|
+
case fileContents.includes("-----BEGIN "):
|
|
15
|
+
case fileContents.includes("SECRET=") && !fileContents.includes("SECRET=\n") && !fileContents.includes("SECRET=*"):
|
|
16
|
+
return false;
|
|
17
|
+
default:
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
exports.default = detectPrivateKeyByFilePath;
|
|
23
|
+
exports.detectPrivateKeyByFilePath = detectPrivateKeyByFilePath;
|
|
24
|
+
//# sourceMappingURL=detectPrivateKeyByFilePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAEpB,SAAwB,0BAA0B,CAAC,KAAa;IAC/D,EAAE;IACF,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,YAAY,GAAG,YAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAE5C,QAAQ,IAAI,EAAE;QACb,KAAK,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC1C,KAAK,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC;YACjH,OAAO,KAAK,CAAC;QACd;YACC,MAAM;KACP;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAfD,6CAeC;AAEQ,gEAA0B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getAllFiles(dirPath: string): Array<string>;
|
|
1
|
+
export default function getAllFiles(dirPath: string, skipDotStart?: true): Array<string>;
|
package/dist/file/getAllFiles.js
CHANGED
|
@@ -5,14 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
function getAllFiles(dirPath) {
|
|
8
|
+
function getAllFiles(dirPath, skipDotStart) {
|
|
9
9
|
//
|
|
10
10
|
const list = [];
|
|
11
11
|
const files = fs_1.default.readdirSync(dirPath);
|
|
12
12
|
files.forEach(function (file) {
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (!/^(node_modules|_next|\.next|\.git)/.test(file)) {
|
|
14
|
+
if (skipDotStart) {
|
|
15
|
+
if (!/^\..*/.test(file)) {
|
|
16
|
+
const newPath = path_1.default.join(dirPath, "/", file).replace(/\\/g, "/");
|
|
17
|
+
if (fs_1.default.statSync(newPath).isDirectory()) {
|
|
18
|
+
list.push(...getAllFiles(newPath));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
list.push(newPath);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
16
26
|
const newPath = path_1.default.join(dirPath, "/", file).replace(/\\/g, "/");
|
|
17
27
|
if (fs_1.default.statSync(newPath).isDirectory()) {
|
|
18
28
|
list.push(...getAllFiles(newPath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllFiles.js","sourceRoot":"","sources":["../../src/file/getAllFiles.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,gDAAw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;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACb,CAAC;AA5BD,8BA4BC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import getAllFiles from "./getAllFiles";
|
|
2
|
+
import detectPrivateKeyByFilePath from "./detectPrivateKeyByFilePath";
|
|
3
3
|
export default function detectPrivateKey(dirPath) {
|
|
4
4
|
//
|
|
5
5
|
const list = getAllFiles(dirPath);
|
|
@@ -7,16 +7,11 @@ export default function detectPrivateKey(dirPath) {
|
|
|
7
7
|
const _list = [];
|
|
8
8
|
for (let i = 0; i < list.length; i++) {
|
|
9
9
|
const _path = list[i];
|
|
10
|
-
|
|
11
|
-
const fileContents = fs.readFileSync(_path);
|
|
12
|
-
// Check if the file contents contain a private key
|
|
13
|
-
if (fileContents.includes("-----BEGIN ")) {
|
|
14
|
-
// console.log("Private key detected");
|
|
15
|
-
_list.push(_path);
|
|
16
|
-
result = false;
|
|
10
|
+
if (detectPrivateKeyByFilePath(_path)) {
|
|
17
11
|
}
|
|
18
12
|
else {
|
|
19
|
-
|
|
13
|
+
_list.push(_path);
|
|
14
|
+
result = false;
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
17
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectPrivateKey.js","sourceRoot":"","sources":["../../src/file/detectPrivateKey.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"detectPrivateKey.js","sourceRoot":"","sources":["../../src/file/detectPrivateKey.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAe;IACvD,EAAE;IACF,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAElC,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAI,0BAA0B,CAAC,KAAK,CAAC,EAAE;SACtC;aAAM;YACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,MAAM,GAAG,KAAK,CAAC;SACf;KACD;IAED,OAAO;QACN,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,KAAK;KACX,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
export default function detectPrivateKeyByFilePath(_path) {
|
|
3
|
+
//
|
|
4
|
+
if (!fs.existsSync(_path))
|
|
5
|
+
return false;
|
|
6
|
+
const fileContents = fs.readFileSync(_path);
|
|
7
|
+
switch (true) {
|
|
8
|
+
case fileContents.includes("-----BEGIN "):
|
|
9
|
+
case fileContents.includes("SECRET=") && !fileContents.includes("SECRET=\n") && !fileContents.includes("SECRET=*"):
|
|
10
|
+
return false;
|
|
11
|
+
default:
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
export { detectPrivateKeyByFilePath };
|
|
17
|
+
//# sourceMappingURL=detectPrivateKeyByFilePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,KAAa;IAC/D,EAAE;IACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAE5C,QAAQ,IAAI,EAAE;QACb,KAAK,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC1C,KAAK,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC;YACjH,OAAO,KAAK,CAAC;QACd;YACC,MAAM;KACP;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getAllFiles(dirPath: string): Array<string>;
|
|
1
|
+
export default function getAllFiles(dirPath: string, skipDotStart?: true): Array<string>;
|
package/esm/file/getAllFiles.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
export default function getAllFiles(dirPath) {
|
|
3
|
+
export default function getAllFiles(dirPath, skipDotStart) {
|
|
4
4
|
//
|
|
5
5
|
const list = [];
|
|
6
6
|
const files = fs.readdirSync(dirPath);
|
|
7
7
|
files.forEach(function (file) {
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (!/^(node_modules|_next|\.next|\.git)/.test(file)) {
|
|
9
|
+
if (skipDotStart) {
|
|
10
|
+
if (!/^\..*/.test(file)) {
|
|
11
|
+
const newPath = path.join(dirPath, "/", file).replace(/\\/g, "/");
|
|
12
|
+
if (fs.statSync(newPath).isDirectory()) {
|
|
13
|
+
list.push(...getAllFiles(newPath));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
list.push(newPath);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
11
21
|
const newPath = path.join(dirPath, "/", file).replace(/\\/g, "/");
|
|
12
22
|
if (fs.statSync(newPath).isDirectory()) {
|
|
13
23
|
list.push(...getAllFiles(newPath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllFiles.js","sourceRoot":"","sources":["../../src/file/getAllFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAe;
|
|
1
|
+
{"version":3,"file":"getAllFiles.js","sourceRoot":"","sources":["../../src/file/getAllFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAe,EAAE,YAAmB;IACvE,EAAE;IACF,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEtC,KAAK,CAAC,OAAO,CAAC,UAAU,IAAI;QAC3B,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrD,IAAI,YAAY,EAAE;gBACjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBACxB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;oBAClE,IAAI,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;wBACvC,IAAI,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;qBACnC;yBAAM;wBACN,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;qBACnB;iBACD;aACD;iBAAM;gBACN,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,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