omaha_client_structured_config/
omaha-client-structured-config-lib_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_omahaclientstructuredconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x5f, 0xb4, 0x48, 0x47, 0xb9, 0xf7, 0xd4, 0xf6, 0xa9, 0x9b, 0xd2, 0x74, 0x25, 0x53, 0x5f, 0xfa,
8 0xae, 0x07, 0xab, 0x80, 0x63, 0x23, 0x49, 0xba, 0x72, 0xb8, 0x70, 0xea, 0xca, 0xc0, 0x0c, 0x00,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub allow_reboot_when_idle: bool,
13 pub app_id: String,
14 pub fuzz_percentage_range: u8,
15 pub omaha_url: String,
16 pub ota_channel: String,
17 pub ota_realm: String,
18 pub periodic_interval_minutes: u16,
19 pub product_id: String,
20 pub retry_delay_seconds: u16,
21 pub startup_delay_seconds: u16,
22}
23impl Config {
24 #[doc = r" Take the config startup handle and parse its contents."]
25 #[doc = r""]
26 #[doc = r" # Panics"]
27 #[doc = r""]
28 #[doc = r" If the config startup handle was already taken or if it is not valid."]
29 pub fn take_from_startup_handle() -> Self {
30 <Self as ComponentConfig>::take_from_startup_handle()
31 }
32 #[doc = r" Parse `Self` from `vmo`."]
33 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
34 <Self as ComponentConfig>::from_vmo(vmo)
35 }
36 #[doc = r" Parse `Self` from `bytes`."]
37 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38 <Self as ComponentConfig>::from_bytes(bytes)
39 }
40 pub fn record_inspect(&self, inspector_node: &Node) {
41 <Self as ComponentConfig>::record_inspect(self, inspector_node)
42 }
43}
44impl ComponentConfig for Config {
45 #[doc = r" Parse `Self` from `bytes`."]
46 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
47 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
48 let checksum_len_bytes: [u8; 2] =
49 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
50 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
51 let (observed_checksum, bytes) =
52 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
53 if observed_checksum != EXPECTED_CHECKSUM {
54 return Err(Error::ChecksumMismatch {
55 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
56 observed_checksum: observed_checksum.to_vec(),
57 });
58 }
59 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
60 Ok(Self {
61 allow_reboot_when_idle: fidl_config.allow_reboot_when_idle,
62 app_id: fidl_config.app_id,
63 fuzz_percentage_range: fidl_config.fuzz_percentage_range,
64 omaha_url: fidl_config.omaha_url,
65 ota_channel: fidl_config.ota_channel,
66 ota_realm: fidl_config.ota_realm,
67 periodic_interval_minutes: fidl_config.periodic_interval_minutes,
68 product_id: fidl_config.product_id,
69 retry_delay_seconds: fidl_config.retry_delay_seconds,
70 startup_delay_seconds: fidl_config.startup_delay_seconds,
71 })
72 }
73 fn record_inspect(&self, inspector_node: &Node) {
74 inspector_node.record_bool("allow_reboot_when_idle", self.allow_reboot_when_idle);
75 inspector_node.record_string("app_id", &self.app_id);
76 inspector_node.record_uint("fuzz_percentage_range", self.fuzz_percentage_range as u64);
77 inspector_node.record_string("omaha_url", &self.omaha_url);
78 inspector_node.record_string("ota_channel", &self.ota_channel);
79 inspector_node.record_string("ota_realm", &self.ota_realm);
80 inspector_node
81 .record_uint("periodic_interval_minutes", self.periodic_interval_minutes as u64);
82 inspector_node.record_string("product_id", &self.product_id);
83 inspector_node.record_uint("retry_delay_seconds", self.retry_delay_seconds as u64);
84 inspector_node.record_uint("startup_delay_seconds", self.startup_delay_seconds as u64);
85 }
86}