#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MarkingForm {
pub title: &'static str,
pub banner: &'static str,
pub portion: &'static str,
}
pub static MARKING_FORMS: &[MarkingForm] = &[
MarkingForm {
title: "TALENT KEYHOLE",
banner: "TK",
portion: "TK",
},
MarkingForm {
title: "RESTRICTED DATA",
banner: "RD",
portion: "RD",
},
MarkingForm {
title: "FORMERLY RESTRICTED DATA",
banner: "FRD",
portion: "FRD",
},
MarkingForm {
title: "TRANSCLASSIFIED FOREIGN NUCLEAR INFORMATION",
banner: "TFNI",
portion: "TFNI",
},
MarkingForm {
title: "CRITICAL NUCLEAR WEAPON DESIGN INFORMATION",
banner: "CNWDI",
portion: "CNWDI",
},
MarkingForm {
title: "DOD UNCLASSIFIED CONTROLLED NUCLEAR INFORMATION",
banner: "DOD UCNI",
portion: "DCNI",
},
MarkingForm {
title: "DOE UNCLASSIFIED CONTROLLED NUCLEAR INFORMATION",
banner: "DOE UCNI",
portion: "UCNI",
},
MarkingForm {
title: "NOT RELEASABLE TO FOREIGN NATIONALS",
banner: "NOFORN",
portion: "NF",
},
MarkingForm {
title: "ORIGINATOR CONTROLLED-USGOV",
banner: "ORCON-USGOV",
portion: "OC-USGOV",
},
MarkingForm {
title: "ORIGINATOR CONTROLLED",
banner: "ORCON",
portion: "OC",
},
MarkingForm {
title: "CONTROLLED IMAGERY",
banner: "IMCON",
portion: "IMC",
},
MarkingForm {
title: "CAUTION-PROPRIETARY INFORMATION INVOLVED",
banner: "PROPIN",
portion: "PR",
},
MarkingForm {
title: "RISK SENSITIVE",
banner: "RSEN",
portion: "RS",
},
MarkingForm {
title: "DEA SENSITIVE",
banner: "DEA SENSITIVE",
portion: "DSEN",
},
MarkingForm {
title: "FOR OFFICIAL USE ONLY",
banner: "FOUO",
portion: "FOUO",
},
MarkingForm {
title: "RELEASABLE BY INFORMATION DISCLOSURE OFFICIAL",
banner: "RELIDO",
portion: "RELIDO",
},
MarkingForm {
title: "FOREIGN INTELLIGENCE SURVEILLANCE ACT",
banner: "FISA",
portion: "FISA",
},
MarkingForm {
title: "LIMITED DISTRIBUTION",
banner: "LIMDIS",
portion: "DS",
},
MarkingForm {
title: "EXCLUSIVE DISTRIBUTION",
banner: "EXDIS",
portion: "XD",
},
MarkingForm {
title: "NO DISTRIBUTION",
banner: "NODIS",
portion: "ND",
},
MarkingForm {
title: "SENSITIVE BUT UNCLASSIFIED",
banner: "SBU",
portion: "SBU",
},
MarkingForm {
title: "SENSITIVE BUT UNCLASSIFIED NOFORN",
banner: "SBU NOFORN",
portion: "SBU-NF",
},
MarkingForm {
title: "LAW ENFORCEMENT SENSITIVE",
banner: "LES",
portion: "LES",
},
MarkingForm {
title: "LAW ENFORCEMENT SENSITIVE NOFORN",
banner: "LES NOFORN",
portion: "LES-NF",
},
MarkingForm {
title: "SENSITIVE SECURITY INFORMATION",
banner: "SSI",
portion: "SSI",
},
];
pub fn banner_to_portion(banner: &str) -> Option<&'static str> {
MARKING_FORMS
.iter()
.find(|f| f.banner == banner && f.banner != f.portion)
.map(|f| f.portion)
}
pub fn portion_to_banner(portion: &str) -> Option<&'static str> {
MARKING_FORMS
.iter()
.find(|f| f.portion == portion && f.banner != f.portion)
.map(|f| f.banner)
}
pub fn title_to_portion(title: &str) -> Option<&'static str> {
MARKING_FORMS
.iter()
.find(|f| f.title == title && f.title != f.banner)
.map(|f| f.portion)
}
pub fn title_to_banner(title: &str) -> Option<&'static str> {
MARKING_FORMS
.iter()
.find(|f| f.title == title && f.title != f.banner)
.map(|f| f.banner)
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use super::*;
#[test]
fn banner_to_portion_known_entries() {
assert_eq!(banner_to_portion("NOFORN"), Some("NF"));
assert_eq!(banner_to_portion("ORCON"), Some("OC"));
assert_eq!(banner_to_portion("IMCON"), Some("IMC"));
assert_eq!(banner_to_portion("DEA SENSITIVE"), Some("DSEN"));
assert_eq!(banner_to_portion("PROPIN"), Some("PR"));
assert_eq!(banner_to_portion("RSEN"), Some("RS"));
assert_eq!(banner_to_portion("LIMDIS"), Some("DS"));
assert_eq!(banner_to_portion("EXDIS"), Some("XD"));
assert_eq!(banner_to_portion("NODIS"), Some("ND"));
assert_eq!(banner_to_portion("SBU NOFORN"), Some("SBU-NF"));
assert_eq!(banner_to_portion("LES NOFORN"), Some("LES-NF"));
assert_eq!(banner_to_portion("DOD UCNI"), Some("DCNI"));
assert_eq!(banner_to_portion("DOE UCNI"), Some("UCNI"));
}
#[test]
fn portion_to_banner_known_entries() {
assert_eq!(portion_to_banner("NF"), Some("NOFORN"));
assert_eq!(portion_to_banner("OC"), Some("ORCON"));
assert_eq!(portion_to_banner("IMC"), Some("IMCON"));
assert_eq!(portion_to_banner("DSEN"), Some("DEA SENSITIVE"));
assert_eq!(portion_to_banner("PR"), Some("PROPIN"));
assert_eq!(portion_to_banner("RS"), Some("RSEN"));
assert_eq!(portion_to_banner("DS"), Some("LIMDIS"));
assert_eq!(portion_to_banner("XD"), Some("EXDIS"));
assert_eq!(portion_to_banner("ND"), Some("NODIS"));
assert_eq!(portion_to_banner("SBU-NF"), Some("SBU NOFORN"));
assert_eq!(portion_to_banner("LES-NF"), Some("LES NOFORN"));
assert_eq!(portion_to_banner("DCNI"), Some("DOD UCNI"));
assert_eq!(portion_to_banner("UCNI"), Some("DOE UCNI"));
}
#[test]
fn banner_to_portion_returns_none_for_unknown() {
assert_eq!(banner_to_portion("BANANAPHONE"), None);
}
#[test]
fn portion_to_banner_returns_none_for_unknown() {
assert_eq!(portion_to_banner("BANANAPHONE"), None);
}
#[test]
fn banner_to_portion_returns_none_for_portion_form() {
assert_eq!(banner_to_portion("NF"), None);
assert_eq!(banner_to_portion("OC"), None);
}
#[test]
fn portion_to_banner_returns_none_for_banner_form() {
assert_eq!(portion_to_banner("NOFORN"), None);
assert_eq!(portion_to_banner("ORCON"), None);
}
#[test]
fn same_form_entries_return_none_from_conversion_helpers() {
for &same_form in &[
"FOUO", "RELIDO", "FISA", "SBU", "LES", "SSI", "TK", "RD", "FRD", "TFNI", "CNWDI",
] {
assert_eq!(
banner_to_portion(same_form),
None,
"banner_to_portion({same_form:?}) should be None for same-form entry"
);
assert_eq!(
portion_to_banner(same_form),
None,
"portion_to_banner({same_form:?}) should be None for same-form entry"
);
}
}
#[test]
fn no_duplicate_banner_entries() {
for (i, a) in MARKING_FORMS.iter().enumerate() {
for (j, b) in MARKING_FORMS.iter().enumerate() {
if i != j {
assert_ne!(a.banner, b.banner, "duplicate banner entry: {:?}", a.banner);
}
}
}
}
#[test]
fn no_duplicate_portion_entries() {
for (i, a) in MARKING_FORMS.iter().enumerate() {
for (j, b) in MARKING_FORMS.iter().enumerate() {
if i != j {
assert_ne!(
a.portion, b.portion,
"duplicate portion entry: {:?}",
a.portion
);
}
}
}
}
#[test]
fn banner_and_portion_forms_are_valid() {
for f in MARKING_FORMS {
if f.banner != f.portion {
} else {
assert_ne!(
f.title, f.banner,
"same-form entry has title equal to banner (S001 would never fire): {:?}",
f.banner
);
}
}
}
#[test]
fn title_to_portion_known_entries() {
assert_eq!(
title_to_portion("NOT RELEASABLE TO FOREIGN NATIONALS"),
Some("NF")
);
assert_eq!(title_to_portion("ORIGINATOR CONTROLLED"), Some("OC"));
assert_eq!(title_to_portion("CONTROLLED IMAGERY"), Some("IMC"));
assert_eq!(
title_to_portion("CAUTION-PROPRIETARY INFORMATION INVOLVED"),
Some("PR")
);
assert_eq!(title_to_portion("RISK SENSITIVE"), Some("RS"));
assert_eq!(title_to_portion("LIMITED DISTRIBUTION"), Some("DS"));
assert_eq!(title_to_portion("EXCLUSIVE DISTRIBUTION"), Some("XD"));
assert_eq!(title_to_portion("NO DISTRIBUTION"), Some("ND"));
assert_eq!(
title_to_portion("SENSITIVE BUT UNCLASSIFIED NOFORN"),
Some("SBU-NF")
);
assert_eq!(
title_to_portion("LAW ENFORCEMENT SENSITIVE NOFORN"),
Some("LES-NF")
);
assert_eq!(
title_to_portion("DOD UNCLASSIFIED CONTROLLED NUCLEAR INFORMATION"),
Some("DCNI")
);
assert_eq!(
title_to_portion("DOE UNCLASSIFIED CONTROLLED NUCLEAR INFORMATION"),
Some("UCNI")
);
}
#[test]
fn title_to_banner_known_entries() {
assert_eq!(
title_to_banner("NOT RELEASABLE TO FOREIGN NATIONALS"),
Some("NOFORN")
);
assert_eq!(title_to_banner("ORIGINATOR CONTROLLED"), Some("ORCON"));
assert_eq!(title_to_banner("CONTROLLED IMAGERY"), Some("IMCON"));
assert_eq!(
title_to_banner("CAUTION-PROPRIETARY INFORMATION INVOLVED"),
Some("PROPIN")
);
assert_eq!(title_to_banner("RISK SENSITIVE"), Some("RSEN"));
assert_eq!(title_to_banner("LIMITED DISTRIBUTION"), Some("LIMDIS"));
assert_eq!(title_to_banner("EXCLUSIVE DISTRIBUTION"), Some("EXDIS"));
assert_eq!(title_to_banner("NO DISTRIBUTION"), Some("NODIS"));
}
#[test]
fn title_lookups_return_none_for_dea_sensitive() {
assert_eq!(title_to_portion("DEA SENSITIVE"), None);
assert_eq!(title_to_banner("DEA SENSITIVE"), None);
}
#[test]
fn title_lookups_return_none_for_unknown() {
assert_eq!(title_to_portion("BANANAPHONE"), None);
assert_eq!(title_to_banner("BANANAPHONE"), None);
assert_eq!(title_to_portion("NOFORN"), None);
assert_eq!(title_to_banner("NOFORN"), None);
}
#[test]
fn no_duplicate_title_entries() {
for (i, a) in MARKING_FORMS.iter().enumerate() {
for (j, b) in MARKING_FORMS.iter().enumerate() {
if i != j {
assert_ne!(a.title, b.title, "duplicate title entry: {:?}", a.title);
}
}
}
}
#[test]
fn dea_sensitive_is_the_only_title_equal_banner() {
let same_form: Vec<&'static str> = MARKING_FORMS
.iter()
.filter(|f| f.title == f.banner)
.map(|f| f.title)
.collect();
assert_eq!(
same_form,
vec!["DEA SENSITIVE"],
"only DEA SENSITIVE should have `title == banner` today \
(CAPCO-2016 §G.1 Table 4 line 831). If this fails, a new \
row without a distinct abbreviation has been added — \
update S001 tests accordingly."
);
}
}