1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use proptest::test_runner::TestRunner;
use std::{fmt, ops::Deref, str::FromStr};
pub mod commands;
pub mod fuzz_targets;
pub trait FuzzTargetImpl: Sync + Send + fmt::Debug {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn generate(&self, runner: &mut TestRunner) -> Vec<u8>;
fn fuzz(&self, data: &[u8]);
}
#[derive(Copy, Clone, Debug)]
pub struct FuzzTarget(&'static (dyn FuzzTargetImpl + 'static));
impl Deref for FuzzTarget {
type Target = dyn FuzzTargetImpl + 'static;
fn deref(&self) -> &Self::Target {
self.0
}
}
impl FromStr for FuzzTarget {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
FuzzTarget::by_name(s).ok_or_else(|| format!("Fuzz target '{}' not found (run `list`)", s))
}
}