starnix_container_structured_config/
starnix_container_structured_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_starnixcontainerstructuredconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0xc6, 0xed, 0x26, 0x7d, 0x69, 0x99, 0xcf, 0x61, 0x8e, 0x2b, 0xc2, 0xf4, 0x7d, 0x1a, 0x76, 0x50,
8    0xfd, 0x1e, 0xd9, 0x0f, 0xdd, 0x82, 0x48, 0x96, 0x86, 0xa7, 0xe9, 0x21, 0x8c, 0xef, 0xd4, 0x47,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub cached_zx_map_info_bytes: u32,
13    pub crash_report_throttling: bool,
14    pub enable_utc_time_adjustment: bool,
15    pub extra_features: Vec<String>,
16    pub mlock_always_onfault: bool,
17    pub mlock_pin_flavor: String,
18    pub selinux_exceptions: Vec<String>,
19    pub ui_visual_debugging_level: u8,
20}
21impl Config {
22    #[doc = r" Take the config startup handle and parse its contents."]
23    #[doc = r""]
24    #[doc = r" # Panics"]
25    #[doc = r""]
26    #[doc = r" If the config startup handle was already taken or if it is not valid."]
27    pub fn take_from_startup_handle() -> Self {
28        <Self as ComponentConfig>::take_from_startup_handle()
29    }
30    #[doc = r" Parse `Self` from `vmo`."]
31    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
32        <Self as ComponentConfig>::from_vmo(vmo)
33    }
34    #[doc = r" Parse `Self` from `bytes`."]
35    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
36        <Self as ComponentConfig>::from_bytes(bytes)
37    }
38    pub fn record_inspect(&self, inspector_node: &Node) {
39        <Self as ComponentConfig>::record_inspect(self, inspector_node)
40    }
41}
42impl ComponentConfig for Config {
43    #[doc = r" Parse `Self` from `bytes`."]
44    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
45        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
46        let checksum_len_bytes: [u8; 2] =
47            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
48        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
49        let (observed_checksum, bytes) =
50            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
51        if observed_checksum != EXPECTED_CHECKSUM {
52            return Err(Error::ChecksumMismatch {
53                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
54                observed_checksum: observed_checksum.to_vec(),
55            });
56        }
57        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
58        Ok(Self {
59            cached_zx_map_info_bytes: fidl_config.cached_zx_map_info_bytes,
60            crash_report_throttling: fidl_config.crash_report_throttling,
61            enable_utc_time_adjustment: fidl_config.enable_utc_time_adjustment,
62            extra_features: fidl_config.extra_features,
63            mlock_always_onfault: fidl_config.mlock_always_onfault,
64            mlock_pin_flavor: fidl_config.mlock_pin_flavor,
65            selinux_exceptions: fidl_config.selinux_exceptions,
66            ui_visual_debugging_level: fidl_config.ui_visual_debugging_level,
67        })
68    }
69    fn record_inspect(&self, inspector_node: &Node) {
70        inspector_node
71            .record_uint("cached_zx_map_info_bytes", self.cached_zx_map_info_bytes as u64);
72        inspector_node.record_bool("crash_report_throttling", self.crash_report_throttling);
73        inspector_node.record_bool("enable_utc_time_adjustment", self.enable_utc_time_adjustment);
74        let arr = inspector_node.create_string_array("extra_features", self.extra_features.len());
75        for i in 0..self.extra_features.len() {
76            arr.set(i, &self.extra_features[i]);
77        }
78        inspector_node.record(arr);
79        inspector_node.record_bool("mlock_always_onfault", self.mlock_always_onfault);
80        inspector_node.record_string("mlock_pin_flavor", &self.mlock_pin_flavor);
81        let arr =
82            inspector_node.create_string_array("selinux_exceptions", self.selinux_exceptions.len());
83        for i in 0..self.selinux_exceptions.len() {
84            arr.set(i, &self.selinux_exceptions[i]);
85        }
86        inspector_node.record(arr);
87        inspector_node
88            .record_uint("ui_visual_debugging_level", self.ui_visual_debugging_level as u64);
89    }
90}