use serde::Serialize;
pub(crate) const ATTACK_VERSION: &str = "16";
pub(crate) const NAVIGATOR_VERSION: &str = "5.0.0";
pub(crate) const LAYER_VERSION: &str = "4.5";
pub(crate) const DOMAIN: &str = "enterprise-attack";
#[derive(Serialize)]
pub(crate) struct Layer {
pub(crate) name: String,
pub(crate) versions: Versions,
pub(crate) domain: &'static str,
pub(crate) description: String,
pub(crate) sorting: u8,
#[serde(rename = "hideDisabled")]
pub(crate) hide_disabled: bool,
pub(crate) gradient: Gradient,
pub(crate) techniques: Vec<NavTechnique>,
}
#[derive(Serialize)]
pub(crate) struct Versions {
pub(crate) attack: &'static str,
pub(crate) navigator: &'static str,
pub(crate) layer: &'static str,
}
impl Versions {
pub(crate) fn current() -> Self {
Self {
attack: ATTACK_VERSION,
navigator: NAVIGATOR_VERSION,
layer: LAYER_VERSION,
}
}
}
#[derive(Serialize)]
pub(crate) struct Gradient {
pub(crate) colors: Vec<&'static str>,
#[serde(rename = "minValue")]
pub(crate) min_value: u64,
#[serde(rename = "maxValue")]
pub(crate) max_value: u64,
}
#[derive(Serialize)]
pub(crate) struct NavTechnique {
#[serde(rename = "techniqueID")]
pub(crate) technique_id: String,
pub(crate) score: u64,
pub(crate) comment: String,
pub(crate) enabled: bool,
#[serde(rename = "showSubtechniques", skip_serializing_if = "is_false")]
pub(crate) show_subtechniques: bool,
}
fn is_false(b: &bool) -> bool {
!*b
}
pub(crate) fn to_pretty_json(layer: &Layer) -> String {
serde_json::to_string_pretty(layer).unwrap_or_else(|_| "{}".to_string())
}