Skip to content

Commit fd165f7

Browse files
perf(datasecurity): take scan input by value to avoid cloning the JSON payload
1 parent bf86718 commit fd165f7

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

pkg/collector/sharedlibrary/rustchecks/checks/datasecurity/src/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ fn run_sub_task(
9696
/// TODO(dsec-161): add tests for the scan.
9797
fn run_scan(scanner: &Scanner, sub_task: &SubTask) -> Result<Vec<Match>> {
9898
let data = backend::fetch_data(sub_task).context("fetching sub task data")?;
99-
scanner.scan(&data).context("scanning sub task data")
99+
scanner.scan(data).context("scanning sub task data")
100100
}

pkg/collector/sharedlibrary/rustchecks/checks/datasecurity/src/scanning/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ impl Scanner {
4242
}
4343

4444
/// Scans `{ column: [values] }` and returns one `Match` per (column, rule).
45-
pub fn scan(&self, data: &Value) -> Result<Vec<Match>> {
46-
let mut event = data.clone();
45+
pub fn scan(&self, data: Value) -> Result<Vec<Match>> {
46+
let mut event = data;
4747
let hits = self
4848
.scanner
4949
.scan(&mut event)

pkg/collector/sharedlibrary/rustchecks/checks/datasecurity/src/scanning/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ scan_data: []
155155
]
156156
});
157157

158-
let matches = scanner.scan(&data).expect("failed to scan data");
158+
let matches = scanner.scan(data).expect("failed to scan data");
159159

160160
// `alice@example.com` is suppressed; the other two rows match.
161161
assert_eq!(
@@ -190,7 +190,7 @@ scan_data: []
190190
]
191191
});
192192

193-
let matches = scanner.scan(&data).expect("failed to scan data");
193+
let matches = scanner.scan(data).expect("failed to scan data");
194194

195195
// Only the row with the `token` keyword nearby matches.
196196
assert_eq!(
@@ -225,7 +225,7 @@ scan_data: []
225225
]
226226
});
227227

228-
let matches = scanner.scan(&data).expect("failed to scan data");
228+
let matches = scanner.scan(data).expect("failed to scan data");
229229

230230
// The row preceded by the `test` keyword is excluded.
231231
assert_eq!(
@@ -254,7 +254,7 @@ scan_data: []
254254
// same row path, so the row is counted once.
255255
let data = json!({ "email": ["alice@corp.io and bob@corp.io"] });
256256

257-
let matches = scanner.scan(&data).expect("failed to scan data");
257+
let matches = scanner.scan(data).expect("failed to scan data");
258258

259259
assert_eq!(
260260
matches,
@@ -287,7 +287,7 @@ scan_data: []
287287
]
288288
});
289289

290-
let matches = scanner.scan(&data).expect("failed to scan data");
290+
let matches = scanner.scan(data).expect("failed to scan data");
291291

292292
// Only the Luhn-valid number is kept.
293293
assert_eq!(
@@ -314,7 +314,7 @@ scan_data: []
314314

315315
let data = json!({ "name": ["alice", "bob"] });
316316

317-
let matches = scanner.scan(&data).expect("failed to scan data");
317+
let matches = scanner.scan(data).expect("failed to scan data");
318318

319319
assert!(matches.is_empty());
320320
}
@@ -335,7 +335,7 @@ scan_data: []
335335
// `foo[bar][0]`; only the trailing row subscript should be stripped.
336336
let data = json!({ "foo[bar]": ["alice@corp.io"] });
337337

338-
let matches = scanner.scan(&data).expect("failed to scan data");
338+
let matches = scanner.scan(data).expect("failed to scan data");
339339

340340
assert_eq!(
341341
matches,
@@ -363,7 +363,7 @@ scan_data: []
363363
// so it survives verbatim even though `.` is the Path segment separator.
364364
let data = json!({ "first.last": ["alice@corp.io", "bob@corp.io"] });
365365

366-
let matches = scanner.scan(&data).expect("failed to scan data");
366+
let matches = scanner.scan(data).expect("failed to scan data");
367367

368368
assert_eq!(
369369
matches,

0 commit comments

Comments
 (0)