aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-15 18:53:32 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-15 18:53:32 -0800
commit6c54316bd512a1ad365f5c1e2cb17e7e53ea193c (patch)
tree3e654feee9ba13c52c7349eaecfa9180e914ea66
parentb06d6ac43a12f928ce2a1d4b4d57f4d12de80b15 (diff)
downloadnitrocli-6c54316bd512a1ad365f5c1e2cb17e7e53ea193c.tar.gz
nitrocli-6c54316bd512a1ad365f5c1e2cb17e7e53ea193c.tar.bz2
Introduce storage hidden subcommand scaffolding
This change introduces a new subcommand to the storage command called 'hidden'. This subcommand can be used to interact with hidden volumes. Right now we support three operations pertaining hidden volumes: create, open, and close. This patch merely provides the infrastructure for parsing the commands and all their arguments, it does not yet implement them fully.
-rw-r--r--nitrocli/src/args.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 756176d..4c9ed52 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -193,6 +193,7 @@ fn status(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
Enum! {StorageCommand, [
Close => ("close", storage_close),
+ Hidden => ("hidden", storage_hidden),
Open => ("open", storage_open),
Status => ("status", storage_status)
]}
@@ -249,6 +250,90 @@ fn storage_status(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
commands::storage_status(ctx)
}
+Enum! {HiddenCommand, [
+ Close => ("close", storage_hidden_close),
+ Create => ("create", storage_hidden_create),
+ Open => ("open", storage_hidden_open)
+]}
+
+/// Execute a storage hidden subcommand.
+fn storage_hidden(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
+ let mut subcommand = HiddenCommand::Open;
+ let help = cmd_help!(subcommand);
+ let mut subargs = vec![];
+ let mut parser = argparse::ArgumentParser::new();
+ parser.set_description("Interact with a hidden volume");
+ let _ =
+ parser
+ .refer(&mut subcommand)
+ .required()
+ .add_argument("subcommand", argparse::Store, &help);
+ let _ = parser.refer(&mut subargs).add_argument(
+ "arguments",
+ argparse::List,
+ "The arguments for the subcommand",
+ );
+ parser.stop_on_first_argument(true);
+ parse(ctx, &parser, args)?;
+ drop(parser);
+
+ subargs.insert(
+ 0,
+ format!(
+ "nitrocli {} {} {}",
+ Command::Storage,
+ StorageCommand::Hidden,
+ subcommand
+ ),
+ );
+ subcommand.execute(ctx, subargs)
+}
+
+fn storage_hidden_create(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
+ let mut slot: u8 = 0;
+ let mut start: u8 = 0;
+ let mut end: u8 = 0;
+ let mut parser = argparse::ArgumentParser::new();
+ parser.set_description("Creates a hidden volume on a Nitrokey Storage");
+ let _ = parser.refer(&mut slot).required().add_argument(
+ "slot",
+ argparse::Store,
+ "The hidden volume slot to use",
+ );
+ let _ = parser.refer(&mut start).required().add_argument(
+ "start",
+ argparse::Store,
+ "The start location of the hidden volume as percentage of the \
+ encrypted volume's size (0-99)",
+ );
+ let _ = parser.refer(&mut end).required().add_argument(
+ "end",
+ argparse::Store,
+ "The end location of the hidden volume as percentage of the \
+ encrypted volume's size (1-100)",
+ );
+ parse(ctx, &parser, args)?;
+ drop(parser);
+
+ Ok(())
+}
+
+fn storage_hidden_open(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
+ let mut parser = argparse::ArgumentParser::new();
+ parser.set_description("Opens a hidden volume on a Nitrokey Storage");
+ parse(ctx, &parser, args)?;
+
+ Ok(())
+}
+
+fn storage_hidden_close(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
+ let mut parser = argparse::ArgumentParser::new();
+ parser.set_description("Closes the hidden volume on a Nitrokey Storage");
+ parse(ctx, &parser, args)?;
+
+ Ok(())
+}
+
/// Execute a config subcommand.
fn config(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut subcommand = ConfigCommand::Get;