1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub struct MarkingForm {
29 pub banner: &'static str,
31 pub portion: &'static str,
33}
34
35pub static MARKING_FORMS: &[MarkingForm] = &[
47 MarkingForm {
49 banner: "NOFORN",
50 portion: "NF",
51 },
52 MarkingForm {
53 banner: "ORCON-USGOV",
54 portion: "OC-USGOV",
55 },
56 MarkingForm {
57 banner: "ORCON",
58 portion: "OC",
59 },
60 MarkingForm {
61 banner: "IMCON",
62 portion: "IMC",
63 },
64 MarkingForm {
65 banner: "PROPIN",
66 portion: "PR",
67 },
68 MarkingForm {
69 banner: "RSEN",
70 portion: "RS",
71 },
72 MarkingForm {
73 banner: "DEA SENSITIVE",
74 portion: "DSEN",
75 },
76 MarkingForm {
78 banner: "LIMDIS",
79 portion: "DS",
80 },
81 MarkingForm {
82 banner: "EXDIS",
83 portion: "XD",
84 },
85 MarkingForm {
86 banner: "NODIS",
87 portion: "ND",
88 },
89 MarkingForm {
90 banner: "SBU NOFORN",
91 portion: "SBU-NF",
92 },
93 MarkingForm {
94 banner: "LES NOFORN",
95 portion: "LES-NF",
96 },
97 MarkingForm {
99 banner: "DOD UCNI",
100 portion: "DCNI",
101 },
102 MarkingForm {
103 banner: "DOE UCNI",
104 portion: "UCNI",
105 },
106 ];
109
110pub fn banner_to_portion(banner: &str) -> Option<&'static str> {
119 MARKING_FORMS
120 .iter()
121 .find(|f| f.banner == banner)
122 .map(|f| f.portion)
123}
124
125pub fn portion_to_banner(portion: &str) -> Option<&'static str> {
133 MARKING_FORMS
134 .iter()
135 .find(|f| f.portion == portion)
136 .map(|f| f.banner)
137}
138
139#[cfg(test)]
140mod tests {
141 use super::*;
142
143 #[test]
144 fn banner_to_portion_known_entries() {
145 assert_eq!(banner_to_portion("NOFORN"), Some("NF"));
146 assert_eq!(banner_to_portion("ORCON"), Some("OC"));
147 assert_eq!(banner_to_portion("IMCON"), Some("IMC"));
148 assert_eq!(banner_to_portion("DEA SENSITIVE"), Some("DSEN"));
149 assert_eq!(banner_to_portion("PROPIN"), Some("PR"));
150 assert_eq!(banner_to_portion("RSEN"), Some("RS"));
151 assert_eq!(banner_to_portion("LIMDIS"), Some("DS"));
152 assert_eq!(banner_to_portion("EXDIS"), Some("XD"));
153 assert_eq!(banner_to_portion("NODIS"), Some("ND"));
154 assert_eq!(banner_to_portion("SBU NOFORN"), Some("SBU-NF"));
155 assert_eq!(banner_to_portion("LES NOFORN"), Some("LES-NF"));
156 assert_eq!(banner_to_portion("DOD UCNI"), Some("DCNI"));
157 assert_eq!(banner_to_portion("DOE UCNI"), Some("UCNI"));
158 }
159
160 #[test]
161 fn portion_to_banner_known_entries() {
162 assert_eq!(portion_to_banner("NF"), Some("NOFORN"));
163 assert_eq!(portion_to_banner("OC"), Some("ORCON"));
164 assert_eq!(portion_to_banner("IMC"), Some("IMCON"));
165 assert_eq!(portion_to_banner("DSEN"), Some("DEA SENSITIVE"));
166 assert_eq!(portion_to_banner("PR"), Some("PROPIN"));
167 assert_eq!(portion_to_banner("RS"), Some("RSEN"));
168 assert_eq!(portion_to_banner("DS"), Some("LIMDIS"));
169 assert_eq!(portion_to_banner("XD"), Some("EXDIS"));
170 assert_eq!(portion_to_banner("ND"), Some("NODIS"));
172 assert_eq!(portion_to_banner("SBU-NF"), Some("SBU NOFORN"));
173 assert_eq!(portion_to_banner("LES-NF"), Some("LES NOFORN"));
174 assert_eq!(portion_to_banner("DCNI"), Some("DOD UCNI"));
175 assert_eq!(portion_to_banner("UCNI"), Some("DOE UCNI"));
176 }
177
178 #[test]
179 fn banner_to_portion_returns_none_for_unknown() {
180 assert_eq!(banner_to_portion("BANANAPHONE"), None);
181 }
182
183 #[test]
184 fn portion_to_banner_returns_none_for_unknown() {
185 assert_eq!(portion_to_banner("BANANAPHONE"), None);
186 }
187
188 #[test]
189 fn banner_to_portion_returns_none_for_portion_form() {
190 assert_eq!(banner_to_portion("NF"), None);
192 assert_eq!(banner_to_portion("OC"), None);
193 }
194
195 #[test]
196 fn portion_to_banner_returns_none_for_banner_form() {
197 assert_eq!(portion_to_banner("NOFORN"), None);
199 assert_eq!(portion_to_banner("ORCON"), None);
200 }
201
202 #[test]
203 fn no_duplicate_banner_entries() {
204 for (i, a) in MARKING_FORMS.iter().enumerate() {
205 for (j, b) in MARKING_FORMS.iter().enumerate() {
206 if i != j {
207 assert_ne!(a.banner, b.banner, "duplicate banner entry: {:?}", a.banner);
208 }
209 }
210 }
211 }
212
213 #[test]
214 fn no_duplicate_portion_entries() {
215 for (i, a) in MARKING_FORMS.iter().enumerate() {
216 for (j, b) in MARKING_FORMS.iter().enumerate() {
217 if i != j {
218 assert_ne!(
219 a.portion, b.portion,
220 "duplicate portion entry: {:?}",
221 a.portion
222 );
223 }
224 }
225 }
226 }
227
228 #[test]
229 fn banner_and_portion_never_equal() {
230 for f in MARKING_FORMS {
231 assert_ne!(
232 f.banner, f.portion,
233 "marking form has identical banner and portion: {:?}",
234 f.banner
235 );
236 }
237 }
238}