From 6fe0f155b0a0daa5affe1482da50cbe152358b07 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 28 Dec 2015 03:26:46 +0300 Subject: utils: interface update & refactoring --- utils/block_cmd_parser.hpp | 67 +++++----------------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) (limited to 'utils/block_cmd_parser.hpp') diff --git a/utils/block_cmd_parser.hpp b/utils/block_cmd_parser.hpp index 988ef52..62b0f36 100644 --- a/utils/block_cmd_parser.hpp +++ b/utils/block_cmd_parser.hpp @@ -8,11 +8,11 @@ #pragma once +#include "block_input.hpp" #include "data_parsers.hpp" #include -#include #include #include @@ -25,66 +25,8 @@ namespace { - BOOST_NORETURN inline void throw_iv_required() - { - throw boost::program_options::error( - "initialization vector is required for the selected mode of operation"); - } - - BOOST_NORETURN inline void throw_not_implemented(aesni::Algorithm algorithm) - { - throw boost::program_options::error( - "the selected algorithm is not implemented"); - } - - BOOST_NORETURN inline void throw_not_implemented(aesni::Mode mode) - { - throw boost::program_options::error( - "the selected mode of operation is not implemented"); - } - class CommandLineParser; - class Input - { - public: - Input( - std::string&& key_string, - std::string&& iv_string, - std::vector&& input_block_strings) - : key_string(std::move(key_string)) - , iv_string(std::make_pair(true, std::move(iv_string))) - , input_block_strings(input_block_strings) - { } - - Input( - std::string&& key_string, - std::vector&& input_block_strings) - : key_string(std::move(key_string)) - , iv_string(std::make_pair(false, std::string())) - , input_block_strings(std::move(input_block_strings)) - { } - - const std::string& get_key_string() const { return key_string; } - - const std::string& get_iv_string() const - { - if (!iv_string.first) - throw_iv_required(); - return iv_string.second; - } - - const std::vector& get_input_block_strings() const - { - return input_block_strings; - } - - private: - const std::string key_string; - const std::pair iv_string; - const std::vector input_block_strings; - }; - class Settings { public: @@ -118,7 +60,7 @@ namespace options.add_options() ("help,h", "show this message and exit") - ("box,b", po::bool_switch(&settings.use_boxes_flag)->default_value(false), "use the \"boxes\" interface") + ("use-boxes,b", po::bool_switch(&settings.use_boxes_flag)->default_value(false), "use the \"boxes\" interface") ("mode,m", po::value(&settings.mode)->required(), "set mode of operation") ("algorithm,a", po::value(&settings.algorithm)->required(), "set algorithm") ("verbose,v", po::bool_switch(&settings.verbose_flag)->default_value(false), "enable verbose output"); @@ -173,7 +115,10 @@ namespace if (aesni::mode_requires_initialization_vector(settings.get_mode())) { if (args.empty()) - throw_iv_required(); + { + throw boost::program_options::error( + "an initialization vector is required for the selected mode of operation"); + } iv_string = std::move(args.front()); args.pop_front(); } -- cgit v1.2.3