From 6c54316bd512a1ad365f5c1e2cb17e7e53ea193c Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 15 Jan 2019 18:53:32 -0800 Subject: 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. --- nitrocli/src/args.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) 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) -> 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) -> 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) -> 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) -> 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) -> 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) -> 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) -> Result<()> { let mut subcommand = ConfigCommand::Get; -- cgit v1.2.3