Skip to content

Commit 9f0874d

Browse files
SP-717 Adds scan filter criteria on local crypto scannning
* SP-717 Adds scan filter criteria on local crypto scannning --------- Co-authored-by: Franco Stramana <[email protected]>
1 parent 5de67be commit 9f0874d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: src/cli/commands/crypto.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { DependencyFilter } from '../../sdk/tree/Filters/DependencyFilter';
1111
import { CryptoCfg } from '../../sdk/Cryptography/CryptoCfg';
1212
import fs from 'fs';
1313
import { BinaryFilter } from '../../sdk/tree/Filters/BinaryFilter';
14+
import { ScanFilter } from '../../sdk/tree/Filters/ScanFilter';
15+
import { FilterAND } from '../../sdk/tree/Filters/FilterAND';
16+
import { isBinaryFileSync } from 'isbinaryfile';
1417

1518
export async function cryptoHandler(rootPath: string, options: any): Promise<void> {
1619
rootPath = rootPath.replace(/\/$/, ''); // Remove trailing slash if exists
@@ -31,7 +34,7 @@ export async function cryptoHandler(rootPath: string, options: any): Promise<voi
3134
if (pathIsFolder) {
3235
const tree = new Tree(rootPath);
3336
tree.build();
34-
fileList = tree.getFileList(new BinaryFilter());
37+
fileList = tree.getFileList(new FilterAND([new BinaryFilter(), new ScanFilter('')]));
3538
}
3639

3740
console.log("Searching for local cryptography...")

Diff for: src/sdk/tree/Filters/FilterAND.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Node from "../Node";
2+
import { Filter } from "./Filter";
3+
4+
export class FilterAND extends Filter {
5+
6+
private filters: Array<Filter>;
7+
8+
constructor(filters: Array<Filter>) {
9+
super();
10+
this.filters = filters;
11+
}
12+
13+
public evaluate(node: Node): boolean {
14+
let valid = false;
15+
for(let i = 0; i < this.filters.length; i++) {
16+
valid = this.filters[i].evaluate(node);
17+
if(!valid) return false;
18+
}
19+
return valid;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)