Skip to content

Commit

Permalink
SP-717 Adds scan filter criteria on local crypto scannning
Browse files Browse the repository at this point in the history
* SP-717 Adds scan filter criteria on local crypto scannning

---------

Co-authored-by: Franco Stramana <franco.stramana@gmail.com>
  • Loading branch information
agustingroh and francostramana committed May 21, 2024
1 parent 5de67be commit 9f0874d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cli/commands/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { DependencyFilter } from '../../sdk/tree/Filters/DependencyFilter';
import { CryptoCfg } from '../../sdk/Cryptography/CryptoCfg';
import fs from 'fs';
import { BinaryFilter } from '../../sdk/tree/Filters/BinaryFilter';
import { ScanFilter } from '../../sdk/tree/Filters/ScanFilter';
import { FilterAND } from '../../sdk/tree/Filters/FilterAND';
import { isBinaryFileSync } from 'isbinaryfile';

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

console.log("Searching for local cryptography...")
Expand Down
22 changes: 22 additions & 0 deletions src/sdk/tree/Filters/FilterAND.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Node from "../Node";
import { Filter } from "./Filter";

export class FilterAND extends Filter {

private filters: Array<Filter>;

constructor(filters: Array<Filter>) {
super();
this.filters = filters;
}

public evaluate(node: Node): boolean {
let valid = false;
for(let i = 0; i < this.filters.length; i++) {
valid = this.filters[i].evaluate(node);
if(!valid) return false;
}
return valid;
}

}

0 comments on commit 9f0874d

Please sign in to comment.