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 | |
parent | utils: code style (diff) | |
download | aes-tools-a151a774f4ce6c4b13c819502efcfe919bbf050b.tar.gz aes-tools-a151a774f4ce6c4b13c819502efcfe919bbf050b.zip |
code style
-rw-r--r-- | cxx/include/aesxx/aes.hpp | 36 | ||||
-rw-r--r-- | cxx/include/aesxx/api.hpp | 24 | ||||
-rw-r--r-- | cxx/include/aesxx/error.hpp | 2 | ||||
-rw-r--r-- | src/error.c | 4 | ||||
-rw-r--r-- | utils/block_cmd_parser.hpp | 175 | ||||
-rw-r--r-- | utils/block_dumper.hpp | 169 | ||||
-rw-r--r-- | utils/block_input.hpp | 33 | ||||
-rw-r--r-- | utils/data_parsers.hpp | 4 | ||||
-rw-r--r-- | utils/file_cmd_parser.hpp | 117 |
9 files changed, 276 insertions, 288 deletions
diff --git a/cxx/include/aesxx/aes.hpp b/cxx/include/aesxx/aes.hpp index d1f68d2..efac790 100644 --- a/cxx/include/aesxx/aes.hpp +++ b/cxx/include/aesxx/aes.hpp @@ -34,19 +34,19 @@ namespace aes }; template <> - std::size_t get_number_of_rounds<AES_AES128>() + inline std::size_t get_number_of_rounds<AES_AES128>() { return 11; } template <> - void from_string<AES_AES128>(aes128::Block& dest, const char* src) + inline void from_string<AES_AES128>(aes128::Block& dest, const char* src) { aes_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES128>(const aes128::Block& src) + inline std::string to_string<AES_AES128>(const aes128::Block& src) { AES_AES128_BlockString str; aes_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -54,7 +54,7 @@ namespace aes } template <> - std::string to_matrix_string<AES_AES128>(const aes128::Block& src) + inline std::string to_matrix_string<AES_AES128>(const aes128::Block& src) { AES_AES128_BlockMatrixString str; aes_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -62,13 +62,13 @@ namespace aes } template <> - void from_string<AES_AES128>(aes128::Key& dest, const char* src) + inline void from_string<AES_AES128>(aes128::Key& dest, const char* src) { aes_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES128>(const aes128::Key& src) + inline std::string to_string<AES_AES128>(const aes128::Key& src) { AES_AES128_KeyString str; aes_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -119,19 +119,19 @@ namespace aes }; template <> - std::size_t get_number_of_rounds<AES_AES192>() + inline std::size_t get_number_of_rounds<AES_AES192>() { return 13; } template <> - void from_string<AES_AES192>(aes192::Block& dest, const char* src) + inline void from_string<AES_AES192>(aes192::Block& dest, const char* src) { aes_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES192>(const aes192::Block& src) + inline std::string to_string<AES_AES192>(const aes192::Block& src) { AES_AES192_BlockString str; aes_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -139,7 +139,7 @@ namespace aes } template <> - std::string to_matrix_string<AES_AES192>(const aes192::Block& src) + inline std::string to_matrix_string<AES_AES192>(const aes192::Block& src) { AES_AES192_BlockMatrixString str; aes_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -147,13 +147,13 @@ namespace aes } template <> - void from_string<AES_AES192>(aes192::Key& dest, const char* src) + inline void from_string<AES_AES192>(aes192::Key& dest, const char* src) { aes_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES192>(const aes192::Key& src) + inline std::string to_string<AES_AES192>(const aes192::Key& src) { AES_AES192_KeyString str; aes_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -204,19 +204,19 @@ namespace aes }; template <> - std::size_t get_number_of_rounds<AES_AES256>() + inline std::size_t get_number_of_rounds<AES_AES256>() { return 15; } template <> - void from_string<AES_AES256>(aes256::Block& dest, const char* src) + inline void from_string<AES_AES256>(aes256::Block& dest, const char* src) { aes_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES256>(const aes256::Block& src) + inline std::string to_string<AES_AES256>(const aes256::Block& src) { AES_AES256_BlockString str; aes_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -224,7 +224,7 @@ namespace aes } template <> - std::string to_matrix_string<AES_AES256>(const aes256::Block& src) + inline std::string to_matrix_string<AES_AES256>(const aes256::Block& src) { AES_AES256_BlockMatrixString str; aes_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); @@ -232,13 +232,13 @@ namespace aes } template <> - void from_string<AES_AES256>(aes256::Key& dest, const char* src) + inline void from_string<AES_AES256>(aes256::Key& dest, const char* src) { aes_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{}); } template <> - std::string to_string<AES_AES256>(const aes256::Key& src) + inline std::string to_string<AES_AES256>(const aes256::Key& src) { AES_AES256_KeyString str; aes_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); diff --git a/cxx/include/aesxx/api.hpp b/cxx/include/aesxx/api.hpp index 2d0871f..789320f 100644 --- a/cxx/include/aesxx/api.hpp +++ b/cxx/include/aesxx/api.hpp @@ -27,7 +27,7 @@ namespace aes const char*); template <Algorithm algorithm> - inline void from_string( + void from_string( typename Types<algorithm>::Block& dest, const std::string& src) { @@ -46,7 +46,7 @@ namespace aes const char*); template <Algorithm algorithm> - inline void from_string( + void from_string( typename Types<algorithm>::Key& dest, const std::string& src) { @@ -57,30 +57,30 @@ namespace aes std::string to_string(const typename Types<algorithm>::Key&); template <Algorithm algorithm> - inline void expand_key( + void expand_key( const typename Types<algorithm>::Key& key, typename Types<algorithm>::RoundKeys& encryption_keys); template <Algorithm algorithm> - inline void derive_decryption_keys( + void derive_decryption_keys( const typename Types<algorithm>::RoundKeys& encryption_keys, typename Types<algorithm>::RoundKeys& decryption_keys); template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void encrypt_block( + void encrypt_block( const typename Types<algorithm>::Block& plaintext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block& iv, typename Types<algorithm>::Block& ciphertext); template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void encrypt_block( + void encrypt_block( const typename Types<algorithm>::Block& plaintext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block& ciphertext); template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void encrypt_block( + void encrypt_block( const typename Types<algorithm>::Block& plaintext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block&, @@ -90,20 +90,20 @@ namespace aes } template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void decrypt_block( + void decrypt_block( const typename Types<algorithm>::Block& ciphertext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block& iv, typename Types<algorithm>::Block& plaintext); template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void decrypt_block( + void decrypt_block( const typename Types<algorithm>::Block& ciphertext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block& plaintext); template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> - inline void decrypt_block( + void decrypt_block( const typename Types<algorithm>::Block& ciphertext, const typename Types<algorithm>::RoundKeys& round_keys, typename Types<algorithm>::Block&, @@ -122,7 +122,7 @@ namespace aes expand_key<algorithm>(key, encryption_keys); } - inline void encrypt_block( + void encrypt_block( const typename Types<algorithm>::Block& plaintext, typename Types<algorithm>::Block& ciphertext) { @@ -154,7 +154,7 @@ namespace aes } } - inline void decrypt_block( + void decrypt_block( const typename Types<algorithm>::Block& ciphertext, typename Types<algorithm>::Block& plaintext) { diff --git a/cxx/include/aesxx/error.hpp b/cxx/include/aesxx/error.hpp index 21f65d5..4d2c783 100644 --- a/cxx/include/aesxx/error.hpp +++ b/cxx/include/aesxx/error.hpp @@ -69,7 +69,7 @@ namespace aes const void* call_stack[AES_MAX_CALL_STACK_LENGTH] = {nullptr}; }; - std::ostream& operator<<(std::ostream& os, const Error& error) + inline std::ostream& operator<<(std::ostream& os, const Error& error) { os << "AES error: " << error.what() << '\n'; os << "Call stack:\n"; diff --git a/src/error.c b/src/error.c index fefe7a2..654c7a9 100644 --- a/src/error.c +++ b/src/error.c @@ -19,7 +19,7 @@ #define snprintf c99_snprintf #define vsnprintf c99_vsnprintf -__inline int c99_vsnprintf(char *dest, size_t dest_size, const char *fmt, va_list ap) +static int c99_vsnprintf(char *dest, size_t dest_size, const char *fmt, va_list ap) { int dest_len = -1; @@ -31,7 +31,7 @@ __inline int c99_vsnprintf(char *dest, size_t dest_size, const char *fmt, va_lis return dest_len; } -__inline int c99_snprintf(char *dest, size_t dest_size, const char *fmt, ...) +static int c99_snprintf(char *dest, size_t dest_size, const char *fmt, ...) { va_list ap; va_start(ap, fmt); 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; +}; diff --git a/utils/block_dumper.hpp b/utils/block_dumper.hpp index ff28c75..00f75f1 100644 --- a/utils/block_dumper.hpp +++ b/utils/block_dumper.hpp @@ -12,91 +12,88 @@ #include <iostream> #include <type_traits> -namespace +template <aes::Algorithm algorithm> +void dump_block( + const char* header, + const typename aes::Types<algorithm>::Block& block) { - template <aes::Algorithm algorithm> - void dump_block( - const char* header, - const typename aes::Types<algorithm>::Block& block) - { - std::cout << header << ": " << aes::to_string<algorithm>(block) << "\n"; - std::cout << aes::to_matrix_string<algorithm>(block) << "\n"; - } - - template <aes::Algorithm algorithm> - void dump_plaintext(const typename aes::Types<algorithm>::Block& block) - { - dump_block<algorithm>("Plaintext", block); - } - - template <aes::Algorithm algorithm> - void dump_key(const typename aes::Types<algorithm>::Key& key) - { - std::cout << "Key: " << aes::to_string<algorithm>(key) << "\n\n"; - } - - template <aes::Algorithm algorithm> - void dump_ciphertext(const typename aes::Types<algorithm>::Block& ciphertext) - { - dump_block<algorithm>("Ciphertext", ciphertext); - } - - template <aes::Algorithm algorithm> - void dump_iv(const typename aes::Types<algorithm>::Block& iv) - { - dump_block<algorithm>("Initialization vector", iv); - } - - template <aes::Algorithm algorithm> - void dump_round_keys(const char* header, const typename aes::Types<algorithm>::RoundKeys& round_keys) - { - std::cout << header << ":\n"; - for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i) - std::cout << "\t[" << i << "]: " << aes::to_string<algorithm>(round_keys.keys[i]) << "\n"; - std::cout << "\n"; - } - - template <aes::Algorithm algorithm> - void dump_encryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) - { - dump_round_keys<algorithm>("Encryption round keys", round_keys); - } - - template <aes::Algorithm algorithm> - void dump_decryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) - { - dump_round_keys<algorithm>("Decryption round keys", round_keys); - } - - template <aes::Algorithm algorithm, aes::Mode mode> - void dump_wrapper(const aes::EncryptWrapper<algorithm, mode>& wrapper) - { - dump_encryption_keys<algorithm>(wrapper.encryption_keys); - } - - template <aes::Algorithm algorithm, aes::Mode mode> - void dump_wrapper(const aes::DecryptWrapper<algorithm, mode>& wrapper) - { - dump_decryption_keys<algorithm>(wrapper.decryption_keys); - } - - template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> - void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>& wrapper) - { - dump_block<algorithm>("Next initialization vector", wrapper.iv); - } - - template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> - void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>&) - { } - - template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> - void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>& wrapper) - { - dump_block<algorithm>("Next initialization vector", wrapper.iv); - } - - template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> - void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>&) - { } + std::cout << header << ": " << aes::to_string<algorithm>(block) << "\n"; + std::cout << aes::to_matrix_string<algorithm>(block) << "\n"; } + +template <aes::Algorithm algorithm> +void dump_plaintext(const typename aes::Types<algorithm>::Block& block) +{ + dump_block<algorithm>("Plaintext", block); +} + +template <aes::Algorithm algorithm> +void dump_key(const typename aes::Types<algorithm>::Key& key) +{ + std::cout << "Key: " << aes::to_string<algorithm>(key) << "\n\n"; +} + +template <aes::Algorithm algorithm> +void dump_ciphertext(const typename aes::Types<algorithm>::Block& ciphertext) +{ + dump_block<algorithm>("Ciphertext", ciphertext); +} + +template <aes::Algorithm algorithm> +void dump_iv(const typename aes::Types<algorithm>::Block& iv) +{ + dump_block<algorithm>("Initialization vector", iv); +} + +template <aes::Algorithm algorithm> +void dump_round_keys(const char* header, const typename aes::Types<algorithm>::RoundKeys& round_keys) +{ + std::cout << header << ":\n"; + for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i) + std::cout << "\t[" << i << "]: " << aes::to_string<algorithm>(round_keys.keys[i]) << "\n"; + std::cout << "\n"; +} + +template <aes::Algorithm algorithm> +void dump_encryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) +{ + dump_round_keys<algorithm>("Encryption round keys", round_keys); +} + +template <aes::Algorithm algorithm> +void dump_decryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) +{ + dump_round_keys<algorithm>("Decryption round keys", round_keys); +} + +template <aes::Algorithm algorithm, aes::Mode mode> +void dump_wrapper(const aes::EncryptWrapper<algorithm, mode>& wrapper) +{ + dump_encryption_keys<algorithm>(wrapper.encryption_keys); +} + +template <aes::Algorithm algorithm, aes::Mode mode> +void dump_wrapper(const aes::DecryptWrapper<algorithm, mode>& wrapper) +{ + dump_decryption_keys<algorithm>(wrapper.decryption_keys); +} + +template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>& wrapper) +{ + dump_block<algorithm>("Next initialization vector", wrapper.iv); +} + +template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>&) +{ } + +template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>& wrapper) +{ + dump_block<algorithm>("Next initialization vector", wrapper.iv); +} + +template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>&) +{ } diff --git a/utils/block_input.hpp b/utils/block_input.hpp index 549e3f2..f629062 100644 --- a/utils/block_input.hpp +++ b/utils/block_input.hpp @@ -9,24 +9,21 @@ #include <utility> #include <vector> -namespace +class Input { - class Input - { - public: - Input(const std::string& key, const std::string& iv, std::vector<std::string>&& blocks) - : key{key} - , iv{iv} - , blocks{std::move(blocks)} - { } +public: + Input(const std::string& key, const std::string& iv, std::vector<std::string>&& blocks) + : key{key} + , iv{iv} + , blocks{std::move(blocks)} + { } - Input(const std::string& key, std::vector<std::string>&& blocks) - : key{key} - , blocks{std::move(blocks)} - { } + Input(const std::string& key, std::vector<std::string>&& blocks) + : key{key} + , blocks{std::move(blocks)} + { } - const std::string key; - const std::string iv; - const std::vector<std::string> blocks; - }; -} + const std::string key; + const std::string iv; + const std::vector<std::string> blocks; +}; diff --git a/utils/data_parsers.hpp b/utils/data_parsers.hpp index e4f0ae2..1207c7c 100644 --- a/utils/data_parsers.hpp +++ b/utils/data_parsers.hpp @@ -14,7 +14,7 @@ #include <string> #include <unordered_map> -static std::istream& operator>>(std::istream& is, aes::Mode& dest) +inline std::istream& operator>>(std::istream& is, aes::Mode& dest) { std::string src; is >> src; @@ -37,7 +37,7 @@ static std::istream& operator>>(std::istream& is, aes::Mode& dest) return is; } -static std::istream& operator>>(std::istream& is, aes::Algorithm& dest) +inline std::istream& operator>>(std::istream& is, aes::Algorithm& dest) { std::string src; is >> src; diff --git a/utils/file_cmd_parser.hpp b/utils/file_cmd_parser.hpp index 6d7a962..e199409 100644 --- a/utils/file_cmd_parser.hpp +++ b/utils/file_cmd_parser.hpp @@ -17,70 +17,67 @@ #include <string> #include <utility> -namespace +class FileSettings : public command_line::SettingsParser { - class FileSettings : 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; - std::string input_path; - std::string output_path; - std::string key; - std::string iv; + std::string input_path; + std::string output_path; + std::string key; + std::string iv; - explicit FileSettings(const std::string& argv0) - : SettingsParser{argv0} - { - visible.add_options() - ("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") - ("key,k", - boost::program_options::value<std::string>(&key) - ->required() - ->value_name("KEY"), - "set encryption key") - ("iv,v", - boost::program_options::value<std::string>(&iv) - ->value_name("BLOCK"), - "set initialization vector") - ("input,i", - boost::program_options::value<std::string>(&input_path) - ->required() - ->value_name("PATH"), - "set input file path") - ("output,o", - boost::program_options::value<std::string>(&output_path) - ->required() - ->value_name("PATH"), - "set output file path"); - } + explicit FileSettings(const std::string& argv0) + : SettingsParser{argv0} + { + visible.add_options() + ("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") + ("key,k", + boost::program_options::value<std::string>(&key) + ->required() + ->value_name("KEY"), + "set encryption key") + ("iv,v", + boost::program_options::value<std::string>(&iv) + ->value_name("BLOCK"), + "set initialization vector") + ("input,i", + boost::program_options::value<std::string>(&input_path) + ->required() + ->value_name("PATH"), + "set input file path") + ("output,o", + boost::program_options::value<std::string>(&output_path) + ->required() + ->value_name("PATH"), + "set output file path"); + } - const char* get_short_description() const override - { - return "[-h|--help] [-a|--algorithm NAME] [-m|--mode MODE]" - " [-k|--key KEY] [-v|--iv BLOCK]" - " [-i|--input PATH] [-o|--output PATH]"; - } + const char* get_short_description() const override + { + return "[-h|--help] [-a|--algorithm NAME] [-m|--mode MODE]" + " [-k|--key KEY] [-v|--iv BLOCK]" + " [-i|--input PATH] [-o|--output PATH]"; + } - void parse(int argc, char** argv) override - { - SettingsParser::parse(argc, argv); + void parse(int argc, char** argv) override + { + SettingsParser::parse(argc, argv); - if (aes::mode_requires_init_vector(mode) && iv.empty()) - { - throw boost::program_options::error{ - "an initialization vector is required for the selected mode of operation"}; - } + if (aes::mode_requires_init_vector(mode) && iv.empty()) + { + throw boost::program_options::error{ + "an initialization vector is required for the selected mode of operation"}; } - }; -} + } +}; |