Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
// ©AngelaMos | 2026
// json.rs
use serde_json::{Value, json};
use crate::advisory::{Advisory, OPERATOR_INPUTS, Provenance};
pub const GHSA_ECOSYSTEM_FOR_C_LIBRARIES: &str = "other";
const DECLINED_REASON: &str = "reason";
const DECLINED_FIELD: &str = "field";
fn declined() -> Value {
Value::Array(
OPERATOR_INPUTS
.iter()
.map(|input| {
json!({
DECLINED_FIELD: input.field(),
DECLINED_REASON: input.why(),
})
})
.collect(),
)
}
fn weakness(advisory: &Advisory) -> Value {
advisory.weakness().map_or(
Value::Null,
|weakness| json!({ "cwe_id": weakness.id, "name": weakness.name }),
)
}
#[must_use]
pub fn render(advisory: &Advisory) -> Value {
json!({
"target": advisory.target(),
"dedup_key": advisory.key(),
"class": advisory.class(),
"severity": advisory.severity().as_str(),
"severity_is_assessed": advisory.severity_is_assessed(),
"security_relevant": advisory.is_security_relevant(),
"weakness": weakness(advisory),
"crash_site": advisory.crash_site(),
"frames": advisory.frames(),
"crash_count": advisory.crash_count(),
"reproducer_bytes": advisory.reproducer_bytes(),
"disclosable": advisory.is_disclosable(),
"provenance": match advisory.provenance() {
Provenance::Field => "field",
Provenance::SyntheticBenchmark => "synthetic_benchmark",
},
"tree_provenance": advisory.tree().as_str(),
"sanitizer_report": advisory.sanitizer_report(),
"declined": declined(),
"ghsa": {
"ecosystem": GHSA_ECOSYSTEM_FOR_C_LIBRARIES,
"package_name": advisory.target(),
"vulnerable_version_range": Value::Null,
"patched_versions": Value::Null,
"cvss_vector_string": Value::Null,
"cve_id": Value::Null,
},
})
}
#[must_use]
pub fn render_string(advisory: &Advisory) -> String {
serde_json::to_string_pretty(&render(advisory))
.expect("a serde_json::Value built from owned strings and numbers always serializes")
}