/// command line options /// /// this module contains structs and enums that are used to parse command line arguments. /// /// Author: Christoph J. Scherr /// License: MIT /// Source: /// use clap::{Args, Parser, Subcommand}; use clap_num::maybe_hex; /// This is just structures for parsing Cli args #[derive(Parser, Debug, Clone)] #[command(author, version, about, long_about)] // Read from `Cargo.toml` #[command( help_template = "{about-section}\n\t{name} {version}\n\tAuthor: {author-with-newline}\n{usage-heading} {usage} \n {all-args} {tab}" )] pub struct Cli { /// Which submodule to use #[command(subcommand)] pub command: Commands, /// Machine output #[arg(short, long, default_value_t = false, global = true)] pub machine: bool, /// Verbose output #[arg(short, long, default_value_t = false, global = true)] pub verbose: bool, } #[derive(Subcommand, Debug, Clone)] #[command(author, version, about, long_about = None)] // Read from `Cargo.toml` pub enum Commands { /// Use math functions Math(MathCommand), /// Use binary functions Binary(BinaryCommand), /// Use custom algorithms Algo(AlgoCommand), } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct MathCommand { #[command(subcommand)] pub action: MathActions } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct BinaryCommand { #[command(subcommand)] pub action: BinaryActions } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct AlgoCommand { #[command(subcommand)] pub action: AlgoActions } #[derive(Subcommand, Clone, Debug, PartialEq, Eq)] pub enum MathActions { #[command(name="modexp")] Modexp(ModexpArgs), Modred(ModredArgs), Pm1(PM1Args), } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct ModexpArgs { pub base: String, pub exp: String, pub field: String } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct ModredArgs { #[clap(value_parser=maybe_hex::)] pub polynomial: u64, #[clap(value_parser=maybe_hex::)] pub relation: u64, } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct PM1Args { #[clap(value_parser=maybe_hex::)] pub n: u128, #[clap(value_parser=maybe_hex::)] pub max_prime: u128, } #[derive(Subcommand, Clone, Debug, PartialEq, Eq)] pub enum BinaryActions { /// bit rotation/circular shifting (only 32bit) #[command(name="rotate")] Rotate(RotateArgs), Xor(XorArgs) } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct RotateArgs { #[arg(short, long, default_value_t = false)] pub left: bool, #[clap(value_parser=maybe_hex::)] pub base: u32, #[clap(value_parser=maybe_hex::)] pub shift_width: u32, } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct XorArgs { #[clap(value_parser=maybe_hex::)] pub a: u128, #[clap(value_parser=maybe_hex::)] pub b: u128, } #[derive(Subcommand, Clone, Debug, PartialEq, Eq)] pub enum AlgoActions { #[command(name="feistel0-i")] Feistel0Inner(Feistel0InnerArgs), #[command(name="feistel0-sbox")] Feistel0SBOX(Feistel0SBOXArgs), #[command(name="feistel0")] Feistel0(Feistel0Args) } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct Feistel0InnerArgs { #[clap(value_parser=maybe_hex::)] pub input: u16, #[clap(value_parser=maybe_hex::)] pub key: u16, } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct Feistel0SBOXArgs { #[clap(value_parser=maybe_hex::)] pub index: u8, } #[derive(Args, Clone, Debug, PartialEq, Eq)] pub struct Feistel0Args{ #[clap(value_parser=maybe_hex::)] pub input: u32, #[clap(value_parser=maybe_hex::)] pub key: u32, #[arg(short, long, default_value_t = false)] pub decrypt: bool, }