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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
use anyhow::Result;
use serde::de::DeserializeOwned;
use thiserror::Error;

fn render_url(endpoint: &str, project: &str) -> String {
    format!("https://introspector.oss-fuzz.com/api/{endpoint}?project={project}")
}

#[derive(Debug, Error)]
pub enum IntroSpectorAPIError {
    #[error(transparent)]
    ReqWestError(#[from] reqwest::Error),
    #[error("Introspector api query unsuccesful.")]
    IntrospectorAPIError,
}

async fn get<T: DeserializeOwned>(
    endpoint: &str,
    project: &str,
) -> std::result::Result<T, reqwest::Error> {
    let url = render_url(endpoint, project);
    let response = reqwest::get(&url).await?;
    Ok(response.json().await?)
}

pub async fn annotated_config(project: &str) -> Result<types::annotated_config::Project> {
    let root: types::annotated_config::Root = get("annotated-cfg", project).await?;
    if root.result != "success" {
        return Err(IntroSpectorAPIError::IntrospectorAPIError.into());
    }
    Ok(root.project)
}

pub async fn far_reach_but_low_coverage(
    project: &str,
) -> Result<Vec<types::far_but_reach_low_coverage::Function>> {
    let root: types::far_but_reach_low_coverage::Root =
        get("far-reach-but-low-coverage", project).await?;
    if root.result != "succes" {
        return Err(IntroSpectorAPIError::IntrospectorAPIError.into());
    }
    Ok(root.functions)
}

pub async fn project_summary(project: &str) -> Result<types::project_summary::Project> {
    let root: types::project_summary::Root = get("project-summary", project).await?;
    if root.result != "success" {
        return Err(IntroSpectorAPIError::IntrospectorAPIError.into());
    }
    Ok(root.project)
}

pub async fn branch_blockers(project: &str) -> Result<Vec<types::branch_blockers::Blocker>> {
    let root: types::branch_blockers::Root = get("branch-blockers", project).await?;
    if root.result != "success" {
        return Err(IntroSpectorAPIError::IntrospectorAPIError.into());
    }
    Ok(root.project_blockers)
}

pub async fn all_functions(project: &str) -> Result<Vec<types::all_functions::Function>> {
    let root: types::all_functions::Root = get("all-functions", project).await?;
    if root.result != "succes" {
        return Err(IntroSpectorAPIError::IntrospectorAPIError.into());
    }
    Ok(root.functions)
}

pub mod types {
    pub mod annotated_config {
        use serde_derive::Deserialize;
        use serde_derive::Serialize;

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Root {
            pub project: Project,
            pub result: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Project {
            #[serde(rename = "annotated-cfg")]
            pub annotated_cfg: AnnotatedCfg,
            pub name: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct AnnotatedCfg {
            #[serde(rename = "tokener_parse_ex_fuzzer")]
            pub tokener_parse_ex_fuzzer: TokenerParseExFuzzer,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct TokenerParseExFuzzer {
            pub destinations: Vec<Destination>,
            #[serde(rename = "src_file")]
            pub src_file: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Destination {
            #[serde(rename = "accummulated-cyclomatic-complexity")]
            pub accummulated_cyclomatic_complexity: i64,
            #[serde(rename = "arg-names")]
            pub arg_names: Vec<String>,
            #[serde(rename = "arg-types")]
            pub arg_types: Vec<String>,
            #[serde(rename = "cyclomatic-complexity")]
            pub cyclomatic_complexity: i64,
            #[serde(rename = "function-name")]
            pub function_name: String,
            #[serde(rename = "raw-function-name")]
            pub raw_function_name: String,
            #[serde(rename = "return-type")]
            pub return_type: String,
            #[serde(rename = "source-file")]
            pub source_file: String,
        }
    }

    pub mod far_but_reach_low_coverage {
        use serde_derive::Deserialize;
        use serde_derive::Serialize;
        use serde_json::Value;

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Root {
            pub functions: Vec<Function>,
            pub result: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Function {
            #[serde(rename = "accummulated-complexity")]
            pub accummulated_complexity: i64,
            #[serde(rename = "function-argument-names")]
            pub function_argument_names: Vec<String>,
            #[serde(rename = "function-arguments")]
            pub function_arguments: Vec<String>,
            #[serde(rename = "function-name")]
            pub function_name: String,
            #[serde(rename = "function_filename")]
            pub function_filename: String,
            #[serde(rename = "is-reached")]
            pub is_reached: bool,
            #[serde(rename = "raw-function-name")]
            pub raw_function_name: String,
            #[serde(rename = "reached-by-fuzzers")]
            pub reached_by_fuzzers: Vec<Value>,
            #[serde(rename = "return-type")]
            pub return_type: String,
            #[serde(rename = "runtime-coverage-percent")]
            pub runtime_coverage_percent: f64,
        }
    }

    pub mod project_summary {
        use serde_derive::Deserialize;
        use serde_derive::Serialize;

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Root {
            pub project: Project,
            pub result: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Project {
            #[serde(rename = "introspector-data")]
            pub introspector_data: IntrospectorData,
            pub name: String,
            #[serde(rename = "runtime-coverage-data")]
            pub runtime_coverage_data: RuntimeCoverageData,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct IntrospectorData {
            #[serde(rename = "annotated_cfg")]
            pub annotated_cfg: AnnotatedCfg,
            #[serde(rename = "branch_pairs")]
            pub branch_pairs: Vec<BranchPair>,
            #[serde(rename = "coverage_lines")]
            pub coverage_lines: f64,
            #[serde(rename = "function_count")]
            pub function_count: i64,
            #[serde(rename = "functions_covered_estimate")]
            pub functions_covered_estimate: f64,
            #[serde(rename = "fuzzer_count")]
            pub fuzzer_count: i64,
            #[serde(rename = "introspector_report_url")]
            pub introspector_report_url: String,
            #[serde(rename = "static_reachability")]
            pub static_reachability: f64,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct AnnotatedCfg {
            #[serde(rename = "tokener_parse_ex_fuzzer")]
            pub tokener_parse_ex_fuzzer: TokenerParseExFuzzer,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct TokenerParseExFuzzer {
            pub destinations: Vec<Destination>,
            #[serde(rename = "src_file")]
            pub src_file: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Destination {
            #[serde(rename = "accummulated-cyclomatic-complexity")]
            pub accummulated_cyclomatic_complexity: i64,
            #[serde(rename = "arg-names")]
            pub arg_names: Vec<String>,
            #[serde(rename = "arg-types")]
            pub arg_types: Vec<String>,
            #[serde(rename = "cyclomatic-complexity")]
            pub cyclomatic_complexity: i64,
            #[serde(rename = "function-name")]
            pub function_name: String,
            #[serde(rename = "raw-function-name")]
            pub raw_function_name: String,
            #[serde(rename = "return-type")]
            pub return_type: String,
            #[serde(rename = "source-file")]
            pub source_file: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct BranchPair {
            #[serde(rename = "blocked-runtime-coverage")]
            pub blocked_runtime_coverage: i64,
            #[serde(rename = "function-name")]
            pub function_name: String,
            pub project: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct RuntimeCoverageData {
            #[serde(rename = "coverage_url")]
            pub coverage_url: String,
            #[serde(rename = "line_coverage")]
            pub line_coverage: LineCoverage,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct LineCoverage {
            pub count: i64,
            pub covered: i64,
            pub percent: f64,
        }
    }

    pub mod branch_blockers {
        use serde_derive::Deserialize;
        use serde_derive::Serialize;

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Root {
            #[serde(rename = "project-blockers")]
            pub project_blockers: Vec<Blocker>,
            pub result: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Blocker {
            #[serde(rename = "blocked_unique_functions")]
            pub blocked_unique_functions: Vec<String>,
            #[serde(rename = "function-name")]
            pub function_name: String,
            #[serde(rename = "project-name")]
            pub project_name: String,
            #[serde(rename = "source_file")]
            pub source_file: String,
            #[serde(rename = "src_linenumber")]
            pub src_linenumber: String,
            #[serde(rename = "unique_blocked_coverage")]
            pub unique_blocked_coverage: i64,
        }
    }

    pub mod all_functions {
        use serde_derive::Deserialize;
        use serde_derive::Serialize;
        use serde_json::Value;

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Root {
            pub functions: Vec<Function>,
            pub result: String,
        }

        #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct Function {
            #[serde(rename = "accummulated-complexity")]
            pub accummulated_complexity: i64,
            #[serde(rename = "function-argument-names")]
            pub function_argument_names: Vec<String>,
            #[serde(rename = "function-arguments")]
            pub function_arguments: Vec<String>,
            #[serde(rename = "function-filename")]
            pub function_filename: String,
            #[serde(rename = "function-name")]
            pub function_name: String,
            #[serde(rename = "is-reached")]
            pub is_reached: bool,
            #[serde(rename = "raw-function-name")]
            pub raw_function_name: String,
            #[serde(rename = "reached-by-fuzzers")]
            pub reached_by_fuzzers: Vec<Value>,
            #[serde(rename = "return-type")]
            pub return_type: String,
            #[serde(rename = "runtime-coverage-percent")]
            pub runtime_coverage_percent: f64,
        }
    }
}