fuchsia_tee_manager_config/
lib.rs
1use anyhow::{anyhow, Result};
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10#[serde(rename_all = "camelCase", tag = "type")]
11enum Config {
12 GlobalPlatform(GlobalPlatformConfig),
13 BinderRpc(BinderRpcConfig),
14}
15
16#[derive(Serialize, Deserialize, Debug, Clone)]
18#[serde(rename_all = "camelCase")]
19struct GlobalPlatformConfig {
20 single_instance: bool,
22 multi_session: bool,
25 instance_keep_alive: bool,
28}
29
30#[derive(Serialize, Deserialize, Debug, Clone)]
32#[serde(rename_all = "camelCase")]
33struct BinderRpcConfig {
34 startup_behavior: StartupBehavior,
35}
36
37#[derive(Serialize, Deserialize, Debug, Clone)]
38#[serde(rename_all = "camelCase")]
39enum StartupBehavior {
40 Lazy,
41 Eager,
42}
43
44#[derive(Serialize, Deserialize, Debug, Clone)]
46#[serde(rename_all = "camelCase")]
47pub struct TAConfig {
48 pub url: String,
50 config: Config,
52 capabilities: Vec<()>,
54}
55
56impl TAConfig {
57 pub fn new(url: String) -> Self {
58 Self {
59 url,
60 config: Config::GlobalPlatform(GlobalPlatformConfig {
61 single_instance: false,
62 multi_session: false,
63 instance_keep_alive: false,
64 }),
65 capabilities: vec![],
66 }
67 }
68
69 pub fn parse_config(path: &PathBuf) -> Result<Self> {
70 let contents = std::fs::read_to_string(path)
71 .map_err(|e| anyhow!("Could not read config file at {path:?}: {e}"))?;
72 let parsed = serde_json::from_str(&contents)
73 .map_err(|e| anyhow!("Could not deserialize {path:?} from json: {e}"))?;
74 Ok(parsed)
75 }
76}