1use fidl::unpersist;
2use fidl_cf_sc_internal_pkgcacheconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0xc5, 0x55, 0x31, 0xdf, 0xbf, 0x5b, 0x38, 0x42, 0xcf, 0x71, 0x56, 0x5c, 0x84, 0x73, 0xa8, 0xec,
8 0x2e, 0xc5, 0x33, 0xbe, 0x0b, 0xfb, 0xb8, 0x4d, 0x2e, 0xf5, 0xf3, 0xdf, 0x26, 0x9a, 0x50, 0x03,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub all_packages_executable: bool,
14 pub blob_download_resumption_attempts_limit: u32,
15 pub blob_fetch_concurrency_limit: u16,
16 pub blob_network_body_timeout_seconds: u32,
17 pub blob_network_header_timeout_seconds: u32,
18 pub enable_upgradable_packages: bool,
19 pub require_system_image: bool,
20 pub startup_profiling_seconds: u32,
21 pub system_image_hash: String,
22 pub use_driver_blob_paging: bool,
23}
24impl Config {
25 #[doc = r" Take the config startup handle and parse its contents."]
26 #[doc = r""]
27 #[doc = r" # Panics"]
28 #[doc = r""]
29 #[doc = r" If the config startup handle was already taken or if it is not valid."]
30 pub fn take_from_startup_handle() -> Self {
31 <Self as ComponentConfig>::take_from_startup_handle()
32 }
33 #[doc = r" Parse `Self` from `vmo`."]
34 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35 <Self as ComponentConfig>::from_vmo(vmo)
36 }
37 #[doc = r" Parse `Self` from `bytes`."]
38 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39 <Self as ComponentConfig>::from_bytes(bytes)
40 }
41 pub fn record_inspect(&self, inspector_node: &Node) {
42 <Self as ComponentConfig>::record_inspect(self, inspector_node)
43 }
44}
45impl ComponentConfig for Config {
46 #[doc = r" Parse `Self` from `bytes`."]
47 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49 let checksum_len_bytes: [u8; 2] =
50 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52 let (observed_checksum, bytes) =
53 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54 if observed_checksum != EXPECTED_CHECKSUM {
55 return Err(Error::ChecksumMismatch {
56 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57 observed_checksum: observed_checksum.to_vec(),
58 });
59 }
60 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61 Ok(Self {
62 all_packages_executable: fidl_config.all_packages_executable,
63 blob_download_resumption_attempts_limit: fidl_config
64 .blob_download_resumption_attempts_limit,
65 blob_fetch_concurrency_limit: fidl_config.blob_fetch_concurrency_limit,
66 blob_network_body_timeout_seconds: fidl_config.blob_network_body_timeout_seconds,
67 blob_network_header_timeout_seconds: fidl_config.blob_network_header_timeout_seconds,
68 enable_upgradable_packages: fidl_config.enable_upgradable_packages,
69 require_system_image: fidl_config.require_system_image,
70 startup_profiling_seconds: fidl_config.startup_profiling_seconds,
71 system_image_hash: fidl_config.system_image_hash,
72 use_driver_blob_paging: fidl_config.use_driver_blob_paging,
73 })
74 }
75 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
76 let fidl_config = FidlConfig {
77 all_packages_executable: self.all_packages_executable.clone(),
78 blob_download_resumption_attempts_limit: self
79 .blob_download_resumption_attempts_limit
80 .clone(),
81 blob_fetch_concurrency_limit: self.blob_fetch_concurrency_limit.clone(),
82 blob_network_body_timeout_seconds: self.blob_network_body_timeout_seconds.clone(),
83 blob_network_header_timeout_seconds: self.blob_network_header_timeout_seconds.clone(),
84 enable_upgradable_packages: self.enable_upgradable_packages.clone(),
85 require_system_image: self.require_system_image.clone(),
86 startup_profiling_seconds: self.startup_profiling_seconds.clone(),
87 system_image_hash: self.system_image_hash.clone(),
88 use_driver_blob_paging: self.use_driver_blob_paging.clone(),
89 };
90 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
91 let mut bytes = Vec::with_capacity(
92 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
93 );
94 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
95 bytes.extend_from_slice(EXPECTED_CHECKSUM);
96 bytes.append(&mut fidl_bytes);
97 Ok(bytes)
98 }
99 fn record_inspect(&self, inspector_node: &Node) {
100 inspector_node.record_bool("all_packages_executable", self.all_packages_executable);
101 inspector_node.record_uint(
102 "blob_download_resumption_attempts_limit",
103 self.blob_download_resumption_attempts_limit as u64,
104 );
105 inspector_node
106 .record_uint("blob_fetch_concurrency_limit", self.blob_fetch_concurrency_limit as u64);
107 inspector_node.record_uint(
108 "blob_network_body_timeout_seconds",
109 self.blob_network_body_timeout_seconds as u64,
110 );
111 inspector_node.record_uint(
112 "blob_network_header_timeout_seconds",
113 self.blob_network_header_timeout_seconds as u64,
114 );
115 inspector_node.record_bool("enable_upgradable_packages", self.enable_upgradable_packages);
116 inspector_node.record_bool("require_system_image", self.require_system_image);
117 inspector_node
118 .record_uint("startup_profiling_seconds", self.startup_profiling_seconds as u64);
119 inspector_node.record_string("system_image_hash", &self.system_image_hash);
120 inspector_node.record_bool("use_driver_blob_paging", self.use_driver_blob_paging);
121 }
122}