diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-12-28 03:26:46 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-12-28 03:26:46 +0300 |
commit | 6fe0f155b0a0daa5affe1482da50cbe152358b07 (patch) | |
tree | a305e26159bcb266c02cd8e9f9292bad839bda79 /utils/block | |
parent | utils: refactoring (diff) | |
download | aes-tools-6fe0f155b0a0daa5affe1482da50cbe152358b07.tar.gz aes-tools-6fe0f155b0a0daa5affe1482da50cbe152358b07.zip |
utils: interface update & refactoring
Diffstat (limited to '')
-rw-r--r-- | utils/block_cmd_parser.hpp | 67 | ||||
-rw-r--r-- | utils/block_input.hpp | 47 |
2 files changed, 53 insertions, 61 deletions
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 <aesnixx/all.hpp> -#include <boost/config.hpp> #include <boost/filesystem.hpp> #include <boost/program_options.hpp> @@ -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<std::string>&& input_block_strings) - : key_string(std::move(key_string)) - , iv_string(std::make_pair<bool, std::string>(true, std::move(iv_string))) - , input_block_strings(input_block_strings) - { } - - Input( - std::string&& key_string, - std::vector<std::string>&& input_block_strings) - : key_string(std::move(key_string)) - , iv_string(std::make_pair<bool, std::string>(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<std::string>& get_input_block_strings() const - { - return input_block_strings; - } - - private: - const std::string key_string; - const std::pair<bool, std::string> iv_string; - const std::vector<std::string> 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<aesni::Mode>(&settings.mode)->required(), "set mode of operation") ("algorithm,a", po::value<aesni::Algorithm>(&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(); } diff --git a/utils/block_input.hpp b/utils/block_input.hpp new file mode 100644 index 0000000..343bb2a --- /dev/null +++ b/utils/block_input.hpp @@ -0,0 +1,47 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include <string> +#include <vector> + +namespace +{ + class Input + { + public: + Input(const std::string& key_string, + const std::string& iv_string, + const std::vector<std::string>& input_block_strings) + : key_string(key_string) + , iv_string(iv_string) + , input_block_strings(input_block_strings) + { } + + Input(const std::string& key_string, + const std::vector<std::string>& input_block_strings) + : key_string(key_string) + , input_block_strings(input_block_strings) + { } + + const std::string& get_key_string() const { return key_string; } + + const std::string& get_iv_string() const { return iv_string; } + + const std::vector<std::string>& get_input_block_strings() const + { + return input_block_strings; + } + + private: + const std::string key_string; + const std::string iv_string; + const std::vector<std::string> input_block_strings; + }; +} |