diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-25 19:56:14 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-25 19:56:14 +0300 |
commit | a151a774f4ce6c4b13c819502efcfe919bbf050b (patch) | |
tree | 5cbed50713e2ea176c04327560b51df65bcd8b54 /utils/block_cmd_parser.hpp | |
parent | utils: code style (diff) | |
download | aes-tools-a151a774f4ce6c4b13c819502efcfe919bbf050b.tar.gz aes-tools-a151a774f4ce6c4b13c819502efcfe919bbf050b.zip |
code style
Diffstat (limited to 'utils/block_cmd_parser.hpp')
-rw-r--r-- | utils/block_cmd_parser.hpp | 175 |
1 files changed, 86 insertions, 89 deletions
diff --git a/utils/block_cmd_parser.hpp b/utils/block_cmd_parser.hpp index c748b3d..58f86d8 100644 --- a/utils/block_cmd_parser.hpp +++ b/utils/block_cmd_parser.hpp @@ -19,109 +19,106 @@ #include <utility> #include <vector> -namespace +class BlockSettings : public command_line::SettingsParser { - class BlockSettings : public command_line::SettingsParser - { - public: - aes::Algorithm algorithm = AES_AES128; - aes::Mode mode = AES_ECB; +public: + aes::Algorithm algorithm = AES_AES128; + aes::Mode mode = AES_ECB; - bool use_boxes = false; - bool verbose = false; + bool use_boxes = false; + bool verbose = false; - std::vector<Input> inputs; + std::vector<Input> inputs; - explicit BlockSettings(const std::string& argv0) - : SettingsParser{argv0} - { - visible.add_options() - ("verbose,v", - boost::program_options::bool_switch(&verbose), - "enable verbose output") - ("algorithm,a", - boost::program_options::value<aes::Algorithm>(&algorithm) - ->required() - ->value_name("NAME"), - "set algorithm") - ("mode,m", - boost::program_options::value<aes::Mode>(&mode) - ->required() - ->value_name("MODE"), - "set mode of operation") - ("use-boxes,b", - boost::program_options::bool_switch(&use_boxes), - "use the \"boxes\" interface"); - hidden.add_options() - ("args", - boost::program_options::value<std::vector<std::string>>(&args), - "shouldn't be visible"); - positional.add("args", -1); - } + explicit BlockSettings(const std::string& argv0) + : SettingsParser{argv0} + { + visible.add_options() + ("verbose,v", + boost::program_options::bool_switch(&verbose), + "enable verbose output") + ("algorithm,a", + boost::program_options::value<aes::Algorithm>(&algorithm) + ->required() + ->value_name("NAME"), + "set algorithm") + ("mode,m", + boost::program_options::value<aes::Mode>(&mode) + ->required() + ->value_name("MODE"), + "set mode of operation") + ("use-boxes,b", + boost::program_options::bool_switch(&use_boxes), + "use the \"boxes\" interface"); + hidden.add_options() + ("args", + boost::program_options::value<std::vector<std::string>>(&args), + "shouldn't be visible"); + positional.add("args", -1); + } + + const char* get_short_description() const override + { + return "[-h|--help] [-v|--verbose] [-a|--algorithm NAME] [-m|--mode MODE]" + " [-- KEY [IV] [BLOCK]...]..."; + } - const char* get_short_description() const override - { - return "[-h|--help] [-v|--verbose] [-a|--algorithm NAME] [-m|--mode MODE]" - " [-- KEY [IV] [BLOCK]...]..."; - } + void parse(int argc, char* argv[]) override + { + SettingsParser::parse(argc, argv); + parse_inputs(std::deque<std::string>{ + std::make_move_iterator(args.begin()), + std::make_move_iterator(args.end())}); + } + +private: + void parse_inputs(std::deque<std::string>&& src) + { + while (!src.empty()) + inputs.emplace_back(parse_input(src)); + } - void parse(int argc, char* argv[]) override - { - SettingsParser::parse(argc, argv); - parse_inputs(std::deque<std::string>{ - std::make_move_iterator(args.begin()), - std::make_move_iterator(args.end())}); - } + Input parse_input(std::deque<std::string>& src) const + { + std::string key{std::move(src.front())}; + src.pop_front(); - private: - void parse_inputs(std::deque<std::string>&& src) - { - while (!src.empty()) - inputs.emplace_back(parse_input(src)); - } + std::string iv; - Input parse_input(std::deque<std::string>& src) const + if (aes::mode_requires_init_vector(mode)) { - std::string key{std::move(src.front())}; - src.pop_front(); - - std::string iv; - - if (aes::mode_requires_init_vector(mode)) + if (src.empty()) { - if (src.empty()) - { - throw boost::program_options::error{ - "an initialization vector is required for the selected mode of operation"}; - } - iv = std::move(src.front()); - src.pop_front(); + throw boost::program_options::error{ + "an initialization vector is required for the selected mode of operation"}; } - - auto blocks = parse_blocks(src); - - if (aes::mode_requires_init_vector(mode)) - return {key, iv, std::move(blocks)}; - else - return {key, std::move(blocks)}; + iv = std::move(src.front()); + src.pop_front(); } - static std::vector<std::string> parse_blocks(std::deque<std::string>& src) - { - std::vector<std::string> blocks; + auto blocks = parse_blocks(src); - while (!src.empty()) - { - std::string block{std::move(src.front())}; - src.pop_front(); - if (block == "--") - break; - blocks.emplace_back(std::move(block)); - } + if (aes::mode_requires_init_vector(mode)) + return {key, iv, std::move(blocks)}; + else + return {key, std::move(blocks)}; + } + + static std::vector<std::string> parse_blocks(std::deque<std::string>& src) + { + std::vector<std::string> blocks; - return blocks; + while (!src.empty()) + { + std::string block{std::move(src.front())}; + src.pop_front(); + if (block == "--") + break; + blocks.emplace_back(std::move(block)); } - std::vector<std::string> args; - }; -} + return blocks; + } + + std::vector<std::string> args; +}; |