1use std::num::ParseIntError;
2
3use clap::{Args, Parser, Subcommand};
4use twizzler::object::ObjID;
5
6#[derive(Parser, Debug)]
7#[command(version, about, long_about = None)]
8pub struct CliArgs {
9 #[command(subcommand)]
10 pub command: Commands,
11}
12
13#[derive(Subcommand, Debug)]
14pub enum Commands {
15 #[command(subcommand)]
17 Ctx(CtxCommands),
18 #[command(subcommand)]
20 Key(KeyCommands),
21
22 #[command(subcommand)]
24 Obj(ObjCommands),
25}
26
27#[derive(Subcommand, Debug)]
28pub enum CtxCommands {
29 New(NewCtxArgs),
31
32 Inspect(CtxInspectArgs),
34
35 #[command(subcommand)]
37 Add(CtxAddCommands),
38}
39
40#[derive(Subcommand, Debug)]
41pub enum KeyCommands {
42 #[command(short_flag = 'n')]
43 NewPair,
44}
45
46#[derive(Subcommand, Debug)]
47pub enum CtxAddCommands {
48 Cap(CapAddArgs),
49}
50
51#[derive(Args, Debug)]
52pub struct CapAddArgs {
53 #[arg(short = 's', long, value_parser=parse_obj_id)]
55 pub signing_key_id: ObjID,
56
57 #[arg(short = 'm', long, value_parser=parse_obj_id)]
59 pub modifying_ctx: ObjID,
60
61 #[arg(short = 't', long, value_parser=parse_obj_id)]
63 pub target_obj: ObjID,
64
65 #[arg(short = 'e', long, value_parser=parse_obj_id)]
68 pub executing_ctx: Option<ObjID>,
69}
70
71#[derive(Subcommand, Debug)]
72pub enum ObjCommands {
73 New(NewObjectArgs),
75
76 Sealed(SealedObjectArgs),
79
80 Inspect(ObjInspectArgs),
82}
83
84#[derive(Args, Debug)]
85pub struct NewObjectArgs {
86 #[arg(short = 'v', long, value_parser=parse_obj_id)]
88 pub verifying_key_id: ObjID,
89
90 #[arg(short, long)]
92 pub message: String,
93}
94
95#[derive(Args, Debug)]
96pub struct SealedObjectArgs {
97 #[arg(short = 'v', long, value_parser=parse_obj_id)]
99 pub verifying_key_id: ObjID,
100
101 #[arg(short = 's', long, value_parser=parse_obj_id)]
102 pub signing_key_id: ObjID,
105
106 #[arg(short = 'c', long, value_parser=parse_obj_id)]
108 pub sec_ctx_id: Option<ObjID>,
109
110 #[arg(short, long)]
112 pub message: String,
113}
114
115#[derive(Args, Debug)]
116pub struct ObjInspectArgs {
117 #[arg(short = 's', long, value_parser=parse_obj_id)]
119 pub sec_ctx_id: Option<ObjID>,
120
121 #[arg(short = 'o', long, value_parser=parse_obj_id)]
123 pub obj_id: ObjID,
124}
125
126#[derive(Args, Debug)]
127pub struct CtxInspectArgs {
128 #[arg(short = 's', long, value_parser=parse_obj_id)]
130 pub sec_ctx_id: ObjID,
131}
132
133fn parse_obj_id(arg: &str) -> Result<ObjID, ParseIntError> {
134 let as_num = u128::from_str_radix(arg, 16)?;
135 Ok(ObjID::from(as_num))
136}
137
138#[derive(Args, Debug)]
139pub struct NewCtxArgs {
140 #[arg(short, long, default_value = "false")]
142 pub undetachable: bool,
143}
144
145#[derive(Debug, Args)]
146pub struct AccessArgs {
147 #[arg(short, long)]
148 pub obj_id: String,
149 #[arg(short, long)]
150 pub sec_ctx_id: String,
151}