fuzz: move consume_random_bytes to a util file

This commit is contained in:
Bruno Garcia 2025-03-03 13:47:52 -03:00
parent eb8ecd5e3c
commit 35e7027a08
2 changed files with 13 additions and 11 deletions

View File

@ -1,16 +1,7 @@
use honggfuzz::fuzz;
fn consume_random_bytes<'a>(data: &mut &'a [u8]) -> &'a [u8] {
if data.is_empty() {
return &[];
}
let length = (data[0] as usize) % (data.len() + 1);
let (bytes, rest) = data.split_at(length);
*data = rest;
bytes
}
mod fuzz_utils;
use fuzz_utils::consume_random_bytes;
fn do_test(data: &[u8]) {
let mut new_data = data;

View File

@ -0,0 +1,11 @@
pub fn consume_random_bytes<'a>(data: &mut &'a [u8]) -> &'a [u8] {
if data.is_empty() {
return &[];
}
let length = (data[0] as usize) % (data.len() + 1);
let (bytes, rest) = data.split_at(length);
*data = rest;
bytes
}