starnix_container_structured_config/
starnix_container_structured_config_rust_config_lib_source.rs1use 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 0x7c, 0x13, 0x67, 0x3a, 0x47, 0x91, 0xa3, 0xd2, 0x95, 0x47, 0x32, 0x49, 0xce, 0x53, 0x85, 0x2b,
8 0x61, 0x41, 0xed, 0x90, 0x6b, 0xda, 0x09, 0x2e, 0xd0, 0xfe, 0xde, 0x3f, 0xa2, 0xfe, 0x98, 0x3b,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub enable_utc_time_adjustment: bool,
13 pub extra_features: Vec<String>,
14 pub mlock_always_onfault: bool,
15 pub mlock_pin_flavor: String,
16 pub selinux_exceptions: Vec<String>,
17 pub ui_visual_debugging_level: u8,
18}
19impl Config {
20 #[doc = r" Take the config startup handle and parse its contents."]
21 #[doc = r""]
22 #[doc = r" # Panics"]
23 #[doc = r""]
24 #[doc = r" If the config startup handle was already taken or if it is not valid."]
25 pub fn take_from_startup_handle() -> Self {
26 <Self as ComponentConfig>::take_from_startup_handle()
27 }
28 #[doc = r" Parse `Self` from `vmo`."]
29 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
30 <Self as ComponentConfig>::from_vmo(vmo)
31 }
32 #[doc = r" Parse `Self` from `bytes`."]
33 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
34 <Self as ComponentConfig>::from_bytes(bytes)
35 }
36 pub fn record_inspect(&self, inspector_node: &Node) {
37 <Self as ComponentConfig>::record_inspect(self, inspector_node)
38 }
39}
40impl ComponentConfig for Config {
41 #[doc = r" Parse `Self` from `bytes`."]
42 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
43 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
44 let checksum_len_bytes: [u8; 2] =
45 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
46 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
47 let (observed_checksum, bytes) =
48 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
49 if observed_checksum != EXPECTED_CHECKSUM {
50 return Err(Error::ChecksumMismatch {
51 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
52 observed_checksum: observed_checksum.to_vec(),
53 });
54 }
55 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
56 Ok(Self {
57 enable_utc_time_adjustment: fidl_config.enable_utc_time_adjustment,
58 extra_features: fidl_config.extra_features,
59 mlock_always_onfault: fidl_config.mlock_always_onfault,
60 mlock_pin_flavor: fidl_config.mlock_pin_flavor,
61 selinux_exceptions: fidl_config.selinux_exceptions,
62 ui_visual_debugging_level: fidl_config.ui_visual_debugging_level,
63 })
64 }
65 fn record_inspect(&self, inspector_node: &Node) {
66 inspector_node.record_bool("enable_utc_time_adjustment", self.enable_utc_time_adjustment);
67 let arr = inspector_node.create_string_array("extra_features", self.extra_features.len());
68 for i in 0..self.extra_features.len() {
69 arr.set(i, &self.extra_features[i]);
70 }
71 inspector_node.record(arr);
72 inspector_node.record_bool("mlock_always_onfault", self.mlock_always_onfault);
73 inspector_node.record_string("mlock_pin_flavor", &self.mlock_pin_flavor);
74 let arr =
75 inspector_node.create_string_array("selinux_exceptions", self.selinux_exceptions.len());
76 for i in 0..self.selinux_exceptions.len() {
77 arr.set(i, &self.selinux_exceptions[i]);
78 }
79 inspector_node.record(arr);
80 inspector_node
81 .record_uint("ui_visual_debugging_level", self.ui_visual_debugging_level as u64);
82 }
83}