snyk-cpp-plugin 2.12.4 → 2.15.0

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/common.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export declare const isWindowsOS: () => boolean;
1
2
  export declare const MAX_SUPPORTED_FILE_SIZE: number;
package/dist/common.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_SUPPORTED_FILE_SIZE = void 0;
3
+ exports.MAX_SUPPORTED_FILE_SIZE = exports.isWindowsOS = void 0;
4
+ const osName = require('os-name');
5
+ exports.isWindowsOS = () => osName()
6
+ .toLowerCase()
7
+ .indexOf('windows') === 0;
4
8
  exports.MAX_SUPPORTED_FILE_SIZE = 2 * 1024 * 1024 * 1024 - 1;
5
9
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../lib/common.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAW,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC"}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../lib/common.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAErB,QAAA,WAAW,GAAG,GAAY,EAAE,CACvC,MAAM,EAAE;KACL,WAAW,EAAE;KACb,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAEjB,QAAA,uBAAuB,GAAW,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC"}
@@ -14,6 +14,8 @@ function getColorBySeverity(severity) {
14
14
  return chalk.yellowBright;
15
15
  case 'high':
16
16
  return chalk.redBright;
17
+ case 'critical':
18
+ return chalk.magentaBright;
17
19
  default:
18
20
  return chalk.whiteBright;
19
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../lib/display/common.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,SAAgB,OAAO,CAAC,IAAY,EAAE,OAAO,GAAG,CAAC;IAC/C,OAAO,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAC1D,CAAC;AAFD,0BAEC;AAED,SAAgB,kBAAkB,CAAC,QAAgB;IACjD,QAAQ,QAAQ,EAAE;QAChB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC,UAAU,CAAC;QAC1B,KAAK,QAAQ;YACX,OAAO,KAAK,CAAC,YAAY,CAAC;QAE5B,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,SAAS,CAAC;QAEzB;YACE,OAAO,KAAK,CAAC,WAAW,CAAC;KAC5B;AACH,CAAC;AAbD,gDAaC;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAFD,gCAEC"}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../lib/display/common.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,SAAgB,OAAO,CAAC,IAAY,EAAE,OAAO,GAAG,CAAC;IAC/C,OAAO,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAC1D,CAAC;AAFD,0BAEC;AAED,SAAgB,kBAAkB,CAAC,QAAgB;IACjD,QAAQ,QAAQ,EAAE;QAChB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC,UAAU,CAAC;QAC1B,KAAK,QAAQ;YACX,OAAO,KAAK,CAAC,YAAY,CAAC;QAC5B,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,SAAS,CAAC;QACzB,KAAK,UAAU;YACb,OAAO,KAAK,CAAC,aAAa,CAAC;QAE7B;YACE,OAAO,KAAK,CAAC,WAAW,CAAC;KAC5B;AACH,CAAC;AAdD,gDAcC;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAFD,gCAEC"}
@@ -1,8 +1,7 @@
1
1
  import { DepGraph } from '@snyk/dep-graph';
2
- import { DepsFilePaths, Issue, IssuesData, Options, ScanResult, TestResult } from '../types';
2
+ import { DepsFilePaths, Issue, IssuesData, Options, ScanResult, TestResult, FileSignaturesDetails } from '../types';
3
3
  export declare function displaySignatures(scanResults: ScanResult[]): string[];
4
4
  export declare function selectDisplayStrategy(options: Options | undefined, depGraph: DepGraph, testResult: TestResult): string[][];
5
- export declare function displayDependencies(depGraph: DepGraph): string[];
6
- export declare function displayDependenciesWithFilePaths(depGraph: DepGraph, depsFilePaths?: DepsFilePaths): string[];
7
- export declare function displayIssues(depGraph: DepGraph, issues: Issue[], issuesData: IssuesData): string[];
5
+ export declare function displayDependencies(depGraph: DepGraph, fileSignaturesDetails?: FileSignaturesDetails, depsFilePaths?: DepsFilePaths): string[];
6
+ export declare function displayIssues(depGraph: DepGraph, issues: Issue[], issuesData: IssuesData, supportUnmanagedVulnDB?: boolean): string[];
8
7
  export declare function displayErrors(errors: string[]): string[];
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displayErrors = exports.displayIssues = exports.displayDependenciesWithFilePaths = exports.displayDependencies = exports.selectDisplayStrategy = exports.displaySignatures = void 0;
3
+ exports.displayErrors = exports.displayIssues = exports.displayDependencies = exports.selectDisplayStrategy = exports.displaySignatures = void 0;
4
4
  const chalk = require("chalk");
5
5
  const common_1 = require("./common");
6
+ const object_1 = require("../utils/object");
6
7
  function displaySignatures(scanResults) {
7
8
  const result = [chalk.whiteBright('Signatures')];
8
9
  for (const { facts = [] } of scanResults) {
@@ -20,62 +21,50 @@ function displaySignatures(scanResults) {
20
21
  return result;
21
22
  }
22
23
  exports.displaySignatures = displaySignatures;
23
- function findDependencyLines(depGraph, options, depsFilePaths) {
24
- const showDepsFilePaths = (options && options['print-dep-paths']) || false;
25
- const isAllowedToShowDependenciesWithFilePaths = showDepsFilePaths && depsFilePaths && Object.keys(depsFilePaths).length > 0;
26
- if (isAllowedToShowDependenciesWithFilePaths) {
27
- return displayDependenciesWithFilePaths(depGraph, depsFilePaths);
24
+ function findDependencyLines(depGraph, options, depsFilePaths, fileSignaturesDetails) {
25
+ const displayDepsWithPaths = (options && options['print-dep-paths']) || false;
26
+ const displayDeps = (options && options['print-deps']) || false;
27
+ if (displayDepsWithPaths) {
28
+ return displayDependencies(depGraph, fileSignaturesDetails, depsFilePaths);
28
29
  }
29
- const isAllowedToShowDependencies = (options && options['print-deps']) || false;
30
- const emptyDependencySection = '';
31
- return isAllowedToShowDependencies
32
- ? displayDependencies(depGraph)
33
- : [emptyDependencySection];
30
+ else if (displayDeps) {
31
+ return displayDependencies(depGraph, fileSignaturesDetails);
32
+ }
33
+ return [''];
34
34
  }
35
35
  function selectDisplayStrategy(options, depGraph, testResult) {
36
- const { depsFilePaths, issues, issuesData } = testResult;
37
- const dependencySection = findDependencyLines(depGraph, options, depsFilePaths);
38
- const issuesSection = displayIssues(depGraph, issues, issuesData);
36
+ const { depsFilePaths, issues, issuesData, fileSignaturesDetails, } = testResult;
37
+ const dependencySection = findDependencyLines(depGraph, options, depsFilePaths, fileSignaturesDetails);
38
+ const issuesSection = displayIssues(depGraph, issues, issuesData, options === null || options === void 0 ? void 0 : options.supportUnmanagedVulnDB);
39
39
  return [dependencySection, issuesSection];
40
40
  }
41
41
  exports.selectDisplayStrategy = selectDisplayStrategy;
42
- function displayDependencies(depGraph) {
43
- const result = [];
44
- const dependencies = depGraph === null || depGraph === void 0 ? void 0 : depGraph.getDepPkgs();
45
- const hasDependencies = (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) > 0;
46
- if (!hasDependencies) {
47
- return result;
48
- }
49
- result.push(chalk.whiteBright('\nDependencies:\n'));
50
- for (const { name, version } of dependencies || []) {
51
- result.push(common_1.leftPad(`${name}@${version}`, 2));
52
- }
53
- if (result.length) {
54
- result.push('');
55
- }
56
- return result;
57
- }
58
- exports.displayDependencies = displayDependencies;
59
- function displayDependenciesWithFilePaths(depGraph, depsFilePaths) {
42
+ function displayDependencies(depGraph, fileSignaturesDetails, depsFilePaths = {}) {
43
+ var _a;
60
44
  let result = [];
61
45
  const dependencies = depGraph === null || depGraph === void 0 ? void 0 : depGraph.getDepPkgs();
62
46
  const hasDependencies = (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) > 0;
63
47
  if (!hasDependencies) {
64
48
  return result;
65
49
  }
66
- result.push(chalk.whiteBright('\nDependencies:'));
50
+ result.push(chalk.whiteBright('\nDependencies:\n'));
67
51
  for (const { name, version } of dependencies) {
68
- const dependencyId = `${name}@${version}`;
52
+ const dependencyId = `${name}@${version}`.toLowerCase();
69
53
  result.push(`\n${common_1.leftPad(dependencyId, 2)}`);
70
- if (depsFilePaths && depsFilePaths[dependencyId]) {
54
+ if (fileSignaturesDetails && ((_a = fileSignaturesDetails[dependencyId]) === null || _a === void 0 ? void 0 : _a.confidence)) {
55
+ result.push(common_1.leftPad(`confidence: ${fileSignaturesDetails[dependencyId].confidence.toFixed(3)}`, 2));
56
+ }
57
+ if (!object_1.isEmpty(depsFilePaths)) {
71
58
  const displayDepsFilePathsOutput = displayDepsFilePaths(depsFilePaths, dependencyId);
72
59
  result = [...result, ...displayDepsFilePathsOutput];
73
60
  }
74
61
  }
75
- result.push('');
62
+ if (result.length) {
63
+ result.push('');
64
+ }
76
65
  return result;
77
66
  }
78
- exports.displayDependenciesWithFilePaths = displayDependenciesWithFilePaths;
67
+ exports.displayDependencies = displayDependencies;
79
68
  function displayDepsFilePaths(depsFilePaths, dependencyId) {
80
69
  const maxFilePathsToBeDisplayed = 3;
81
70
  const result = [];
@@ -84,14 +73,13 @@ function displayDepsFilePaths(depsFilePaths, dependencyId) {
84
73
  for (const filePathToDisplay of filePathsToDisplay) {
85
74
  result.push(common_1.leftPad(`- ${filePathToDisplay}`, 4));
86
75
  }
87
- const hasToHideAndSayDepsFilePathsCount = depsFilePaths[dependencyId].length > 3;
88
- if (hasToHideAndSayDepsFilePathsCount) {
76
+ if (depsFilePaths[dependencyId].length > 3) {
89
77
  result.push(common_1.leftPad(`... and ${depsFilePaths[dependencyId].length -
90
78
  maxFilePathsToBeDisplayed} more files`, 4));
91
79
  }
92
80
  return result;
93
81
  }
94
- function displayIssues(depGraph, issues, issuesData) {
82
+ function displayIssues(depGraph, issues, issuesData, supportUnmanagedVulnDB = false) {
95
83
  const result = [];
96
84
  const dependencies = depGraph === null || depGraph === void 0 ? void 0 : depGraph.getDepPkgs();
97
85
  const dependenciesCountMsg = (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) == 1
@@ -105,9 +93,11 @@ function displayIssues(depGraph, issues, issuesData) {
105
93
  const { title, severity } = issuesData[vulnId];
106
94
  const color = common_1.getColorBySeverity(severity);
107
95
  const severityAndTitle = color(`\n ✗ [${common_1.capitalize(severity)}] ${title}`);
108
- const nvdUrl = `https://nvd.nist.gov/vuln/detail/${vulnId}`;
96
+ const vulnDetailsUrl = supportUnmanagedVulnDB
97
+ ? `https://security.snyk.io/vuln/${vulnId}`
98
+ : `https://nvd.nist.gov/vuln/detail/${vulnId}`;
109
99
  const introducedThrough = common_1.leftPad(`Introduced through: ${name}@${version}`);
110
- const urlText = common_1.leftPad(`URL: ${nvdUrl}`);
100
+ const urlText = common_1.leftPad(`URL: ${vulnDetailsUrl}`);
111
101
  result.push(severityAndTitle);
112
102
  result.push(introducedThrough);
113
103
  result.push(urlText);
@@ -1 +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aAAa,CAAC,MAAgB;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;KACxC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACpB;IACD,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACjB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAZD,sCAYC"}
package/dist/find.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import * as fs from 'fs';
3
3
  export declare const stat: typeof fs.stat.__promisify__;
4
- export declare function find(dir: string): Promise<string[]>;
5
- export declare function extractFilePaths(absolutePaths: string[]): Promise<string[]>;
4
+ export declare function find(src: string): Promise<string[]>;
package/dist/find.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFilePaths = exports.find = exports.stat = void 0;
3
+ exports.find = exports.stat = void 0;
4
4
  const fs = require("fs");
5
5
  const path_1 = require("path");
6
6
  const util_1 = require("util");
@@ -8,40 +8,32 @@ const common_1 = require("./common");
8
8
  const debug_1 = require("./debug");
9
9
  const readdir = util_1.promisify(fs.readdir);
10
10
  exports.stat = util_1.promisify(fs.stat);
11
- async function find(dir) {
12
- const dirStat = await exports.stat(dir);
13
- if (!dirStat.isDirectory()) {
14
- throw new Error(`${dir} is not a directory`);
15
- }
16
- const paths = await readdir(dir);
17
- const absolutePaths = [];
18
- for (const relativePath of paths) {
19
- absolutePaths.push(path_1.join(dir, relativePath));
20
- }
21
- return await extractFilePaths(absolutePaths);
11
+ async function find(src) {
12
+ const result = [];
13
+ await traverse(src, (filePath, stats) => {
14
+ if (!stats.isFile() || stats.size > common_1.MAX_SUPPORTED_FILE_SIZE) {
15
+ return;
16
+ }
17
+ result.push(filePath);
18
+ });
19
+ return result;
22
20
  }
23
21
  exports.find = find;
24
- async function extractFilePaths(absolutePaths) {
25
- const result = [];
26
- for (const absolutePath of absolutePaths) {
27
- try {
28
- const fileStats = await exports.stat(absolutePath);
29
- if (fileStats.isDirectory()) {
30
- const subFiles = await find(absolutePath);
31
- result.push(...subFiles);
32
- }
33
- else if (fileStats.isFile()) {
34
- if (fileStats.size > common_1.MAX_SUPPORTED_FILE_SIZE) {
35
- continue;
36
- }
37
- result.push(absolutePath);
38
- }
22
+ async function traverse(src, handle) {
23
+ try {
24
+ const stats = await exports.stat(src);
25
+ if (!stats.isDirectory()) {
26
+ handle(src, stats);
27
+ return;
39
28
  }
40
- catch (error) {
41
- debug_1.debug(error.message || `Error reading file ${absolutePath}. ${error}`);
29
+ const entries = await readdir(src);
30
+ for (const entry of entries) {
31
+ const absolute = path_1.join(src, entry);
32
+ await traverse(absolute, handle);
42
33
  }
43
34
  }
44
- return result;
35
+ catch (error) {
36
+ debug_1.debug(error.message || `Error reading file ${src}. ${error}`);
37
+ }
45
38
  }
46
- exports.extractFilePaths = extractFilePaths;
47
39
  //# sourceMappingURL=find.js.map
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","sourceRoot":"","sources":["../lib/find.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,+BAA4B;AAC5B,+BAAiC;AACjC,qCAAmD;AACnD,mCAAgC;AAEhC,MAAM,OAAO,GAAG,gBAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACzB,QAAA,IAAI,GAAG,gBAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEhC,KAAK,UAAU,IAAI,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,MAAM,YAAI,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE;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M,OAAO,GAAG,gBAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACzB,QAAA,IAAI,GAAG,gBAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAMhC,KAAK,UAAU,IAAI,CAAC,GAAW;IACpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAgB,EAAE,KAAe,EAAE,EAAE;QACxD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,GAAG,gCAAuB,EAAE;YAC3D,OAAO;SACR;QAED,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAZD,oBAYC;AAED,KAAK,UAAU,QAAQ,CAAC,GAAW,EAAE,MAAmB;IACtD,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,YAAI,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACnB,OAAO;SACR;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;QAEnC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;YAC3B,MAAM,QAAQ,GAAG,WAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAElC,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;SAClC;KACF;IAAC,OAAO,KAAK,EAAE;QACd,aAAK,CAAC,KAAK,CAAC,OAAO,IAAI,sBAAsB,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC;KAC/D;AACH,CAAC"}
package/dist/hash.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { FileContent, FilePath, FullFileHash, SignatureResult } from './types';
2
+ export declare function getHashSignature(path: FilePath, content: FileContent): Promise<SignatureResult>;
3
+ export declare function computeSingleHash(content: FileContent): Promise<FullFileHash>;
4
+ export declare function computeUHash(content: FileContent): Promise<FullFileHash>;
package/dist/hash.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeUHash = exports.computeSingleHash = exports.getHashSignature = void 0;
4
+ const crypto = require("crypto");
5
+ const binary_1 = require("./utils/binary");
6
+ const format_1 = require("./utils/format");
7
+ var DigestFormat;
8
+ (function (DigestFormat) {
9
+ DigestFormat["BASE64"] = "base64";
10
+ DigestFormat["HEX"] = "hex";
11
+ })(DigestFormat || (DigestFormat = {}));
12
+ var HashAlgorithm;
13
+ (function (HashAlgorithm) {
14
+ HashAlgorithm["MD5"] = "md5";
15
+ HashAlgorithm["OTHER"] = "other";
16
+ })(HashAlgorithm || (HashAlgorithm = {}));
17
+ const usedHashAlgorithm = HashAlgorithm.MD5;
18
+ async function getHashSignature(path, content) {
19
+ const hashes = await Promise.all([
20
+ computeSingleHash(content),
21
+ computeUHash(content),
22
+ ]);
23
+ return {
24
+ path: path,
25
+ size: content.length,
26
+ hashes_ffm: hashes,
27
+ };
28
+ }
29
+ exports.getHashSignature = getHashSignature;
30
+ async function computeSingleHash(content) {
31
+ const hash = crypto.createHash(usedHashAlgorithm).update(content);
32
+ const base64Digest = hash.digest(DigestFormat.BASE64).replace(/=/g, '');
33
+ return {
34
+ data: base64Digest,
35
+ format: 1,
36
+ };
37
+ }
38
+ exports.computeSingleHash = computeSingleHash;
39
+ async function computeUHash(content) {
40
+ const file = binary_1.isBinary(content) ? content : format_1.removeWhitespaces(content);
41
+ const hash = crypto.createHash(usedHashAlgorithm).update(file);
42
+ const hexDigest = hash.digest(DigestFormat.HEX).slice(0, 24);
43
+ return {
44
+ data: hexDigest,
45
+ format: 3,
46
+ };
47
+ }
48
+ exports.computeUHash = computeUHash;
49
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sour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AI,GAAG,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7D,OAAO;QACL,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,CAAC;KACV,CAAC;AACJ,CAAC;AAZD,oCAYC"}
package/dist/scan.js CHANGED
@@ -21,7 +21,7 @@ async function scan(options) {
21
21
  const start = Date.now();
22
22
  const filePaths = await find_1.find(options.path);
23
23
  debug_1.debug('%d files found \n', filePaths.length);
24
- const allSignatures = await signatures_1.getSignaturesByAlgorithm(filePaths);
24
+ const allSignatures = await signatures_1.getSignatures(filePaths);
25
25
  const filteredSignatures = allSignatures.filter((s) => {
26
26
  return s !== null;
27
27
  });
package/dist/scan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"scan.js","sourceRoot":"","sources":["../lib/scan.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAI7B,mCAAgC;AAChC,iCAA8B;AAC9B,qDAA0C;AAC1C,6CAAwD;AACxD,+BAAkC;AAE3B,KAAK,UAAU,IAAI,CAAC,OAAgB;IACzC,IAAI;QACF,aAAK,CAAC,OAAO,GAAG,CAAC,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAA,CAAC;QAEjC,aAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACjB,MAAM,oCAAoC,CAAC;SAC5C;QAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAChC,MAAM,IAAI,OAAO,CAAC,IAAI,mBAAmB,CAAC;SAC3C;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,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M,IAAI,GACR,OAAO,CAAC,WAAW,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzE,aAAK,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAC1B,MAAM,WAAW,GAAiB;YAChC;gBACE,KAAK;gBACL,QAAQ,EAAE;oBACR,IAAI,EAAE,KAAK;iBACZ;gBACD,IAAI;gBACJ,MAAM;gBACN,SAAS;aACV;SACF,CAAC;QAEF,OAAO;YACL,WAAW;SACZ,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;KAC3D;AACH,CAAC;AAhFD,oBAgFC"}
@@ -1,2 +1,2 @@
1
- import { SignatureHashAlgorithm, SignatureResult } from './types';
2
- export declare function getSignaturesByAlgorithm(filePaths: string[], hashType?: SignatureHashAlgorithm): Promise<(SignatureResult | null)[]>;
1
+ import { FilePath, SignatureResult } from './types';
2
+ export declare function getSignatures(paths: FilePath[]): Promise<(SignatureResult | null)[]>;
@@ -1,32 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSignaturesByAlgorithm = void 0;
3
+ exports.getSignatures = void 0;
4
4
  const fs_1 = require("fs");
5
- const dubhash_1 = require("./dubhash");
6
- const uhash_1 = require("./uhash");
5
+ const hash_1 = require("./hash");
7
6
  const pMap = require("p-map");
8
7
  const { readFile } = fs_1.promises;
9
- async function getSignaturesByAlgorithm(filePaths, hashType = 'dubhash') {
10
- if (hashType !== 'dubhash' && hashType !== 'uhash') {
11
- throw new Error(`Unsupported hashType ${hashType}`);
12
- }
13
- let signatureMapperToBeUsed = getDubHashSignatureMapper;
14
- if (hashType === 'uhash') {
15
- signatureMapperToBeUsed = getUHashSignatureMapper;
16
- }
17
- return await pMap(filePaths, signatureMapperToBeUsed, { concurrency: 20 });
18
- }
19
- exports.getSignaturesByAlgorithm = getSignaturesByAlgorithm;
20
- async function getDubHashSignatureMapper(filePath) {
21
- const fileContents = await readFile(filePath);
22
- if (fileContents.length === 0)
23
- return null;
24
- return dubhash_1.getDubHashSignature(filePath, fileContents);
25
- }
26
- async function getUHashSignatureMapper(filePath) {
27
- const fileContents = await readFile(filePath);
28
- if (fileContents.length === 0)
29
- return null;
30
- return uhash_1.getUhashSignature(filePath, fileContents);
8
+ async function getSignatures(paths) {
9
+ return pMap(paths, async (path) => {
10
+ const content = await readFile(path);
11
+ return content.length > 0 ? await hash_1.getHashSignature(path, content) : null;
12
+ }, { concurrency: 20 });
31
13
  }
14
+ exports.getSignatures = getSignatures;
32
15
  //# sourceMappingURL=signatures.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signatures.js","sourceRoot":"","sources":["../lib/signatures.ts"],"names":[],"mappings":";;;AAAA,2BAA8B;AAE9B,uCAAgD;AAChD,mCAA4C;AAC5C,8BAA+B;AAE/B,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAQ,CAAC;AAEvB,KAAK,UAAU,wBAAwB,CAC5C,SAAmB,EACnB,WAAmC,SAAS;IAE5C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,OAAO,EAAE;QAClD,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;KACrD;IACD,IAAI,uBAAuB,GAAG,yBAAyB,CAAC;IACxD,IAAI,QAAQ,KAAK,OAAO,EAAE;QACxB,uBAAuB,GAAG,uBAAuB,CAAC;KACnD;IACD,OAAO,MAAM,IAAI,CAAC,SAAS,EAAE,uBAAuB,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAZD,4DAYC;AAED,KAAK,UAAU,yBAAyB,CACtC,QAAgB;IAEhB,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,6BAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACrD,CAAC;AAED,KAAK,UAAU,uBAAuB,CACpC,QAAgB;IAEhB,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,yBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"signatures.js","sourceRoot":"","sources":["../lib/signatures.ts"],"names":[],"mappings":";;;AAAA,2BAA8B;AAE9B,iCAA0C;AAC1C,8BAA+B;AAE/B,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAQ,CAAC;AAEvB,KAAK,UAAU,aAAa,CACjC,KAAiB;IAEjB,OAAO,IAAI,CACT,KAAK,EACL,KAAK,EAAE,IAAc,EAAE,EAAE;QACvB,MAAM,OAAO,GAAgB,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QAElD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,uBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,CAAC,EACD,EAAE,WAAW,EAAE,EAAE,EAAE,CACpB,CAAC;AACJ,CAAC;AAZD,sCAYC"}
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { DepGraphData } from '@snyk/dep-graph';
2
3
  export interface PluginResponse {
3
4
  scanResults: ScanResult[];
@@ -42,8 +43,8 @@ export interface Options {
42
43
  projectName?: string;
43
44
  'print-deps'?: boolean;
44
45
  'print-dep-paths'?: boolean;
46
+ supportUnmanagedVulnDB?: boolean;
45
47
  }
46
- export declare type SignatureHashAlgorithm = 'dubhash' | 'uhash';
47
48
  export interface Issue {
48
49
  pkgName: string;
49
50
  pkgVersion?: string;
@@ -64,13 +65,22 @@ export interface TestResult {
64
65
  issuesData: IssuesData;
65
66
  depGraphData: DepGraphData;
66
67
  depsFilePaths?: DepsFilePaths;
68
+ fileSignaturesDetails?: FileSignaturesDetails;
69
+ }
70
+ export interface FileSignaturesDetails {
71
+ [pkgKey: string]: {
72
+ confidence: number;
73
+ filePaths: string[];
74
+ };
67
75
  }
68
76
  export interface SignatureResult {
69
77
  path: string;
78
+ size: number;
70
79
  hashes_ffm: FullFileHash[];
71
80
  }
72
- interface FullFileHash {
81
+ export interface FullFileHash {
73
82
  format: number;
74
83
  data: string;
75
84
  }
76
- export {};
85
+ export declare type FileContent = Buffer;
86
+ export declare type FilePath = string;
@@ -1,2 +1,2 @@
1
- /// <reference types="node" />
2
- export declare function isBinary(fileBuffer: Buffer): boolean;
1
+ import { FileContent } from '../types';
2
+ export declare function isBinary(content: FileContent): boolean;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBinary = void 0;
4
- function isBinary(fileBuffer) {
5
- // The spec defines a binary file as anything containing a null byte
6
- return fileBuffer.includes(0);
4
+ function isBinary(content) {
5
+ return content.includes(0);
7
6
  }
8
7
  exports.isBinary = isBinary;
9
8
  //# sourceMappingURL=binary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"binary.js","sourceRoot":"","sources":["../../lib/utils/binary.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,UAAkB;IACzC,oEAAoE;IACpE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAHD,4BAGC"}
1
+ {"version":3,"file":"binary.js","sourceRoot":"","sources":["../../lib/utils/binary.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CAAC,OAAoB;IAC3C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,32 @@
1
+ import { FileContent } from '../types';
2
+ /**
3
+ * Check if the UTF-8 BOM is present in the first three bytes
4
+ *
5
+ * @param {FileContent} content
6
+ * @returns {boolean}
7
+ */
8
+ export declare function isUtf8BomPresent(content: FileContent): boolean;
9
+ /**
10
+ * Check if char is not whitespace
11
+ *
12
+ * @param {number} char
13
+ * @returns {boolean}
14
+ */
15
+ export declare function isNotWhiteSpace(char: number): boolean;
16
+ /**
17
+ * Remove whitespaces from the file
18
+ *
19
+ * @param {FileContent} content
20
+ * @param {number} startingIndex
21
+ * @returns {FileContent}
22
+ */
23
+ export declare function removeWhitespaceBytewise(content: FileContent, startingIndex: number): FileContent;
24
+ /**
25
+ * Remove unwanted bytes from the file
26
+ *
27
+ * If it is UTF-8 BOM we start parsing the file content from index 3
28
+ *
29
+ * @param {FileContent} content
30
+ * @returns {FileContent}
31
+ */
32
+ export declare function removeWhitespaces(content: FileContent): FileContent;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeWhitespaces = exports.removeWhitespaceBytewise = exports.isNotWhiteSpace = exports.isUtf8BomPresent = void 0;
4
+ const Utf8Bom = Buffer.from(new Uint8Array([0xef, 0xbb, 0xbf]));
5
+ const asciiChars = {
6
+ space: 0x20,
7
+ carriageReturn: 0x0d,
8
+ newLine: 0x0a,
9
+ horizontalTab: 0x09,
10
+ verticalTab: 0x0b,
11
+ newPage: 0x0c,
12
+ };
13
+ /**
14
+ * Check if the UTF-8 BOM is present in the first three bytes
15
+ *
16
+ * @param {FileContent} content
17
+ * @returns {boolean}
18
+ */
19
+ function isUtf8BomPresent(content) {
20
+ if (content.length < 3) {
21
+ return false;
22
+ }
23
+ return Utf8Bom.compare(content.subarray(0, 3)) === 0;
24
+ }
25
+ exports.isUtf8BomPresent = isUtf8BomPresent;
26
+ /**
27
+ * Check if char is not whitespace
28
+ *
29
+ * @param {number} char
30
+ * @returns {boolean}
31
+ */
32
+ function isNotWhiteSpace(char) {
33
+ return (char > asciiChars.space ||
34
+ (char != asciiChars.space &&
35
+ char != asciiChars.carriageReturn &&
36
+ char != asciiChars.newLine &&
37
+ char != asciiChars.horizontalTab &&
38
+ char != asciiChars.verticalTab &&
39
+ char != asciiChars.newPage));
40
+ }
41
+ exports.isNotWhiteSpace = isNotWhiteSpace;
42
+ /**
43
+ * Remove whitespaces from the file
44
+ *
45
+ * @param {FileContent} content
46
+ * @param {number} startingIndex
47
+ * @returns {FileContent}
48
+ */
49
+ function removeWhitespaceBytewise(content, startingIndex) {
50
+ let writeIndex = 0;
51
+ for (let readIndex = startingIndex; readIndex < content.length; readIndex++) {
52
+ const c = content[readIndex];
53
+ if (isNotWhiteSpace(c)) {
54
+ content[writeIndex] = c;
55
+ writeIndex++;
56
+ }
57
+ }
58
+ return content.slice(0, writeIndex);
59
+ }
60
+ exports.removeWhitespaceBytewise = removeWhitespaceBytewise;
61
+ /**
62
+ * Remove unwanted bytes from the file
63
+ *
64
+ * If it is UTF-8 BOM we start parsing the file content from index 3
65
+ *
66
+ * @param {FileContent} content
67
+ * @returns {FileContent}
68
+ */
69
+ function removeWhitespaces(content) {
70
+ const startingIndex = isUtf8BomPresent(content) ? 3 : 0;
71
+ return removeWhitespaceBytewise(content, startingIndex);
72
+ }
73
+ exports.removeWhitespaces = removeWhitespaces;
74
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../lib/utils/format.ts"],"names":[],"mappings":";;;AAEA,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAChE,MAAM,UAAU,GAAG;IACjB,KAAK,EAAE,IAAI;IACX,cAAc,EAAE,IAAI;IACpB,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,OAA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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,OAAO,wBAAwB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAC1D,CAAC;AAHD,8CAGC"}
@@ -0,0 +1 @@
1
+ export declare function isEmpty(obj: Record<string, unknown>): boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmpty = void 0;
4
+ function isEmpty(obj) {
5
+ return obj && Object.keys(obj).length === 0;
6
+ }
7
+ exports.isEmpty = isEmpty;
8
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../lib/utils/object.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO,CAAC,GAA4B;IAClD,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC9C,CAAC;AAFD,0BAEC"}
package/package.json CHANGED
@@ -40,17 +40,18 @@
40
40
  "@types/debug": "^4.1.5",
41
41
  "@types/hosted-git-info": "^3.0.1",
42
42
  "@types/jest": "^25.2.3",
43
- "@types/node": "^10",
43
+ "@types/node": "^10.17.60",
44
44
  "@typescript-eslint/eslint-plugin": "^3.8.0",
45
45
  "@typescript-eslint/parser": "^3.8.0",
46
46
  "eslint": "^6.8.0",
47
47
  "eslint-config-prettier": "^6.11.0",
48
48
  "jest": "^25.5.4",
49
+ "os-name": "^3.0.0",
49
50
  "prettier": "^1.19.1",
50
51
  "ts-jest": "^25.5.1",
51
52
  "ts-node": "^10",
52
53
  "tsc-watch": "^4.2.9",
53
54
  "typescript": "^3.9.7"
54
55
  },
55
- "version": "2.12.4"
56
+ "version": "2.15.0"
56
57
  }
package/dist/dubhash.d.ts DELETED
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { SignatureResult } from './types';
3
- export declare function getDubHashSignature(filePath: string, fileContents: Buffer, getAltHash?: boolean): SignatureResult | null;
package/dist/dubhash.js DELETED
@@ -1,172 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDubHashSignature = void 0;
4
- // This module implements the "double hash" signature specification described in docs/signature_specification.md
5
- const crypto = require("crypto");
6
- const binary_1 = require("./utils/binary");
7
- const hashAlgorithm = 'md5';
8
- const regex = /=/g;
9
- var LineEndingFormat;
10
- (function (LineEndingFormat) {
11
- LineEndingFormat[LineEndingFormat["LINUX"] = 0] = "LINUX";
12
- LineEndingFormat[LineEndingFormat["WINDOWS"] = 1] = "WINDOWS";
13
- LineEndingFormat[LineEndingFormat["UNKNOWN"] = 2] = "UNKNOWN";
14
- })(LineEndingFormat || (LineEndingFormat = {}));
15
- const CR = 0x0d;
16
- const LF = 0x0a;
17
- function getDubHashSignature(filePath, fileContents, getAltHash = false) {
18
- // Unless getAltHash is true, we only need a single hash, AKA the "half double hash".
19
- if (!getAltHash) {
20
- return {
21
- path: filePath,
22
- hashes_ffm: [
23
- {
24
- data: getSingleDigest(fileContents),
25
- format: 1,
26
- },
27
- ],
28
- };
29
- }
30
- const [digest1, digest2] = getDubHashDigests(fileContents, binary_1.isBinary(fileContents));
31
- if (!digest1)
32
- throw Error(`Failed to generate hash of ${filePath}`);
33
- if (digest1 && !digest2) {
34
- return {
35
- path: filePath,
36
- hashes_ffm: [
37
- {
38
- data: digest1,
39
- format: 1,
40
- },
41
- ],
42
- };
43
- }
44
- return {
45
- path: filePath,
46
- hashes_ffm: [
47
- {
48
- data: digest1,
49
- format: 1,
50
- },
51
- {
52
- data: digest2,
53
- format: 1,
54
- },
55
- ],
56
- };
57
- }
58
- exports.getDubHashSignature = getDubHashSignature;
59
- function getDubHashDigests(fileContents, isBinary) {
60
- // If the file is binary, you only produce one hash
61
- // If the file does not have line endings, you treat it like a binary file
62
- // If the LF character is not found, the line endings are UNKNOWN, and we produce only one hash.
63
- const lineEndingFormat = detectLineEndingFormat(fileContents);
64
- if (isBinary ||
65
- !hasLineEndings(fileContents) ||
66
- lineEndingFormat === LineEndingFormat.UNKNOWN) {
67
- return [getSingleDigest(fileContents), null];
68
- }
69
- // NB: You MUST calculate the digest for the original file and store it, since transformLineEndings
70
- // will modify fileContents buffer.
71
- const digestForOriginal = getSingleDigest(fileContents);
72
- const transformedFile = transformLineEndings(fileContents, lineEndingFormat);
73
- return [digestForOriginal, getSingleDigest(transformedFile)];
74
- }
75
- function hasLineEndings(fileContents) {
76
- const lineEndingBytes = new Uint8Array([LF, CR]);
77
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
78
- if (lineEndingBytes.includes(fileContents[readIndex])) {
79
- return true;
80
- }
81
- }
82
- return false;
83
- }
84
- function detectLineEndingFormat(fileContents) {
85
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
86
- if (fileContents[readIndex] !== LF) {
87
- continue;
88
- }
89
- // If the first character in the file is LF (0x0a), the file is of type LINUX.
90
- if (readIndex === 0) {
91
- return LineEndingFormat.LINUX;
92
- }
93
- // If the file has a LF character (0x0a), check if the previous character is 0x0d (CR),
94
- // then the newline type is WINDOWS
95
- if (fileContents[readIndex - 1] === CR) {
96
- return LineEndingFormat.WINDOWS;
97
- }
98
- return LineEndingFormat.LINUX;
99
- }
100
- // If the LF character is not found, the line endings are UNKNOWN.
101
- return LineEndingFormat.UNKNOWN;
102
- }
103
- function transformLinuxToWindows(fileContents) {
104
- // In worst case, file is all 0x0a bytes, so we need to allocate double the memory
105
- const transformedFile = Buffer.alloc(2 * fileContents.length);
106
- let writeIndex = 0;
107
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
108
- // if byte is CR (0x0d), do not write byte
109
- if (fileContents[readIndex] === CR) {
110
- continue;
111
- }
112
- // if byte is LF and targetLineEndingFormat is WINDOWS, write CR (0x0d) LF (0x0a)
113
- // NB1: Check for targetLineEndingFormat === LineEndingFormat.WINDOWS is obviously not necessary here,
114
- // NB2: LineEndingFormat.UNKOWN is also not possible here, due to early return in getDubHashDigests
115
- if (fileContents[readIndex] === LF) {
116
- transformedFile[writeIndex] = CR;
117
- transformedFile[writeIndex + 1] = LF;
118
- writeIndex += 2;
119
- continue;
120
- }
121
- // else: write byte
122
- transformedFile[writeIndex] = fileContents[readIndex];
123
- writeIndex++;
124
- }
125
- return transformedFile.slice(0, writeIndex);
126
- }
127
- function transformWindowsToLinux(fileContents) {
128
- let writeIndex = 0;
129
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
130
- // if byte is CR (0x0d), do not write byte
131
- if (fileContents[readIndex] === CR) {
132
- continue;
133
- }
134
- // if byte is LF (0x0a): if target line ending is UNIX, write LF (0x0a)
135
- // NB1: Check for targetLineEndingFormat === LineEndingFormat.WINDOWS is obviously not necessary here,
136
- // NB2: LineEndingFormat.UNKOWN is also not possible here, due to early return in getDubHashDigests
137
- if (fileContents[readIndex] === LF) {
138
- if (readIndex !== writeIndex)
139
- fileContents[writeIndex] = LF;
140
- writeIndex++;
141
- continue;
142
- }
143
- // else: write byte
144
- if (readIndex !== writeIndex)
145
- fileContents[writeIndex] = fileContents[readIndex];
146
- writeIndex++;
147
- }
148
- return fileContents.slice(0, writeIndex);
149
- }
150
- function transformLineEndings(fileContents, lineEndingFormat) {
151
- const targetLineEndingFormat = lineEndingFormat === LineEndingFormat.LINUX
152
- ? LineEndingFormat.WINDOWS
153
- : LineEndingFormat.LINUX;
154
- if (targetLineEndingFormat === LineEndingFormat.WINDOWS)
155
- return transformLinuxToWindows(fileContents);
156
- if (targetLineEndingFormat === LineEndingFormat.LINUX)
157
- return transformWindowsToLinux(fileContents);
158
- // This line is unreachable, but Typescript doesn't know it because of LineEndingFormat.UNKNOWN.
159
- return Buffer.from('');
160
- }
161
- function getSingleDigest(fileContents) {
162
- if (hashAlgorithm == 'md5') {
163
- const hash = crypto.createHash(hashAlgorithm).update(fileContents);
164
- return hash.digest('base64').replace(regex, '');
165
- }
166
- else {
167
- // Placeholder for other planned hash algorithms, e.g. xxhash
168
- // return xxhash.hash64(fileContents, 0xcafebabe).digest();
169
- return '';
170
- }
171
- }
172
- //# sourceMappingURL=dubhash.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dubhash.js","sourceRoot":"","sources":["../lib/dubhash.ts"],"names":[],"mappings":";;;AAAA,gHAAgH;AAChH,iCAAiC;AAEjC,2CAA0C;AAE1C,MAAM,aAAa,GAAG,KAAK,CAAC;AAE5B,MAAM,KAAK,GAAG,IAAI,CAAC;AAEnB,IAAK,gBAIJ;AAJD,WAAK,gBAAgB;IACnB,yDAAK,CAAA;IACL,6DAAO,CAAA;IACP,6DAAO,CAAA;AACT,CAAC,EAJI,gBAAgB,KAAhB,gBAAgB,QAIpB;AAED,MAAM,EAAE,GAAG,IAAI,CAAC;AAChB,MAAM,EAAE,GAAG,IAAI,CAAC;AAIhB,SAAgB,mBAAmB,CACjC,QAAgB,EAChB,YAAoB,EACpB,UAAU,GAAG,KAAK;IAElB,qFAAqF;IACrF,IAAI,CAAC,UAAU,EAAE;QACf,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,eAAe,CAAC,YAAY,CAAC;oBACnC,MAAM,EAAE,CAAC;iBACV;aACF;SACF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,iBAAiB,CAC1C,YAAY,EACZ,iBAAQ,CAAC,YAAY,CAAC,CACvB,CAAC;IACF,IAAI,CAAC,OAAO;QAAE,MAAM,KAAK,CAAC,8BAA8B,QAAQ,EAAE,CAAC,CAAC;IACpE,IAAI,OAAO,IAAI,CAAC,OAAO,EAAE;QACvB,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,OAAO;oBACb,MAAM,EAAE,CAAC;iBACV;aACF;SACF,CAAC;KACH;IACD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV;gBACE,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,CAA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AAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;KACjD;SAAM;QACL,6DAA6D;QAC7D,2DAA2D;QAC3D,OAAO,EAAE,CAAC;KACX;AACH,CAAC"}
package/dist/uhash.d.ts DELETED
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { SignatureResult } from './types';
3
- export declare function getUhashSignature(filePath: string, fileContents: Buffer): SignatureResult;
package/dist/uhash.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUhashSignature = void 0;
4
- // This module implements the "uhash" signature specification described in docs/signature_specification.md
5
- const crypto = require("crypto");
6
- const binary_1 = require("./utils/binary");
7
- const hashAlgorithm = 'md5';
8
- const Utf8Bom = Buffer.from(new Uint8Array([0xef, 0xbb, 0xbf]));
9
- function getUhashSignature(filePath, fileContents) {
10
- const digest = getUhashDigest(fileContents, binary_1.isBinary(fileContents));
11
- const data = digest.slice(0, 24);
12
- return {
13
- path: filePath,
14
- hashes_ffm: [
15
- {
16
- data,
17
- format: 3,
18
- },
19
- ],
20
- };
21
- }
22
- exports.getUhashSignature = getUhashSignature;
23
- function getUhashDigest(fileContents, isBinary) {
24
- if (hashAlgorithm !== 'md5') {
25
- // placeholder for non-md5 hashing algorithm, e.g. xxhash
26
- throw new Error(`hashAlgorithm ${hashAlgorithm} is not supported`);
27
- }
28
- const file = isBinary ? fileContents : removeUnwantedBytes(fileContents);
29
- const hash = crypto.createHash(hashAlgorithm).update(file);
30
- return hash.digest('hex');
31
- }
32
- function removeUnwantedBytes(fileBuffer) {
33
- const startingIndex = isUtf8BomPresent(fileBuffer) ? 3 : 0;
34
- return removeWhitespaceBytewise(fileBuffer, startingIndex);
35
- }
36
- function isUtf8BomPresent(fileBuffer) {
37
- if (fileBuffer.length < 3)
38
- return false;
39
- return Utf8Bom.compare(fileBuffer.subarray(0, 3)) === 0;
40
- }
41
- function includeChar(c) {
42
- return (c > 0x20 ||
43
- (c != 0x20 && c != 0x0d && c != 0x0a && c != 0x09 && c != 0x0b && c != 0x0c));
44
- }
45
- function removeWhitespaceBytewise(fileBuffer, startingIndex) {
46
- let writeIndex = 0;
47
- for (let readIndex = startingIndex; readIndex < fileBuffer.length; readIndex++) {
48
- const c = fileBuffer[readIndex];
49
- if (includeChar(c)) {
50
- fileBuffer[writeIndex] = c;
51
- writeIndex++;
52
- }
53
- }
54
- return fileBuffer.slice(0, writeIndex);
55
- }
56
- //# sourceMappingURL=uhash.js.map
package/dist/uhash.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"uhash.js","sourceRoot":"","sources":["../lib/uhash.ts"],"names":[],"mappings":";;;AAAA,0GAA0G;AAC1G,iCAAiC;AAEjC,2CAA0C;AAE1C,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhE,SAAgB,iBAAiB,CAC/B,QAAgB,EAChB,YAAoB;IAEpB,MAAM,MAAM,GAAG,cAAc,CAAC,YAAY,EAAE,iBAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV;gBACE,IAAI;gBACJ,MAAM,EAAE,CAAC;aACV;SACF;KACF,CAAC;AACJ,CAAC;AAfD,8CAeC;AAED,SAAS,cAAc,CAAC,YAAoB,EAAE,QAAiB;IAC7D,IAAI,aAAa,KAAK,KAAK,EAAE;QAC3B,yDAAyD;QACzD,MAAM,IAAI,KAAK,CAAC,iBAAiB,aAAa,mBAAmB,CAAC,CAAC;KACpE;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC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