arcs_ctf_yaml_parser/
accessors.rs

1use std::path::Path;
2
3use crate::{YamlShape, YamlVerifyError, YamlCorrectness, categories::structs::Category, deploy::structs::DeployOptions, files::structs::File};
4
5use crate::files::structs::Files;
6
7impl YamlShape {
8    pub fn try_from_str(s: &str, correctness: &YamlCorrectness, base_path: Option<&Path>) -> Result<YamlShape, YamlVerifyError> {
9        let curr_path = std::env::current_dir().map_err(|_| YamlVerifyError::OsError)?;
10        super::verify_yaml(s, Some(correctness.clone()), base_path.unwrap_or(curr_path.as_path()))
11    }
12}
13impl YamlShape {
14    pub fn file_path_iter(&self) -> Option<impl Iterator<Item = &Path>> {
15        self.files.as_ref().map(Files::iter_paths)
16    }
17    pub fn file_iter(&self) -> Option<impl Iterator<Item = &File>> {
18        self.files.as_ref().map(Files::iter)
19    }
20    pub fn files(&self) -> Option<&[File]> {
21        self.files.as_ref().map(Files::slice)
22    }
23
24    pub fn author_iter(&self) -> impl Iterator<Item = &str> {
25        self.authors.iter()
26    }
27    pub fn authors(&self) -> &[String] {
28        self.authors.slice()
29    }
30
31    pub fn category_str_iter(&self) -> impl Iterator<Item = &str> {
32        self.categories.iter().map(Category::as_str)
33    }
34    pub fn category_iter(&self) -> impl Iterator<Item = &Category> {
35        self.categories.iter()
36    }
37    pub fn categories(&self) -> &[Category] {
38        self.categories.slice()
39    }
40
41    pub fn hint_iter(&self) -> impl Iterator<Item = &str> {
42        self.hints.iter()
43    }
44    pub fn hints(&self) -> &[String] {
45        self.hints.slice()
46    }
47
48    pub fn deploy(&self) -> Option<&DeployOptions> {
49        self.deploy.as_ref()
50    }
51}
52
53impl YamlShape {
54    pub fn flag_str(&self) -> &str {
55        self.flag.as_str()
56    }
57    pub fn flag_filepath(&self) -> Option<&Path> {
58        self.flag.path()
59    }
60}
61
62impl YamlShape {
63    pub fn chall_name(&self) -> &str { &self.name }
64    pub fn description(&self) -> &str { &self.description }
65    
66    pub fn points(&self) -> u64 { self.points }
67
68    pub fn visible(&self) -> bool { self.visible }
69}
70