diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-13 19:06:16 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-13 19:06:16 +0200 |
| commit | 1b2505ac21ce8dd09a34aff86455a8a3677094a0 (patch) | |
| tree | 61124c0c28bb884842ac931f11a6c203a034fe7e /aesxx/utils | |
| parent | workflows/ci: add linting for Python test scripts (diff) | |
| download | aes-tools-1b2505ac21ce8dd09a34aff86455a8a3677094a0.tar.gz aes-tools-1b2505ac21ce8dd09a34aff86455a8a3677094a0.zip | |
finally, perfect .clang-format settings?
Diffstat (limited to 'aesxx/utils')
| -rw-r--r-- | aesxx/utils/block_cmd_parser.hpp | 44 | ||||
| -rw-r--r-- | aesxx/utils/block_dumper.hpp | 34 | ||||
| -rw-r--r-- | aesxx/utils/decrypt_block.cpp | 10 | ||||
| -rw-r--r-- | aesxx/utils/decrypt_bmp.cpp | 8 | ||||
| -rw-r--r-- | aesxx/utils/decrypt_file.cpp | 8 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_block.cpp | 16 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_bmp.cpp | 8 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_file.cpp | 8 | ||||
| -rw-r--r-- | aesxx/utils/file_cmd_parser.hpp | 44 | ||||
| -rw-r--r-- | aesxx/utils/helpers/command_line.hpp | 12 |
10 files changed, 118 insertions, 74 deletions
diff --git a/aesxx/utils/block_cmd_parser.hpp b/aesxx/utils/block_cmd_parser.hpp index c179556..5bfdb1e 100644 --- a/aesxx/utils/block_cmd_parser.hpp +++ b/aesxx/utils/block_cmd_parser.hpp @@ -32,22 +32,30 @@ public: explicit BlockSettings(std::string_view argv0) : SettingsParser{argv0} { visible.add_options()( - "verbose,v", boost::program_options::bool_switch(&verbose), "enable verbose output"); - visible.add_options()("algorithm,a", - boost::program_options::value<aes::Algorithm>(&algorithm) - ->required() - ->value_name("NAME"), - "set algorithm"); + "verbose,v", boost::program_options::bool_switch(&verbose), "enable verbose output" + ); + visible.add_options()( + "algorithm,a", + boost::program_options::value<aes::Algorithm>(&algorithm) + ->required() + ->value_name("NAME"), + "set algorithm" + ); visible.add_options()( "mode,m", boost::program_options::value<aes::Mode>(&mode)->required()->value_name("MODE"), - "set mode of operation"); - visible.add_options()("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"); + "set mode of operation" + ); + visible.add_options()( + "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); } @@ -58,8 +66,11 @@ public: 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())}); + parse_inputs( + std::deque<std::string>{ + std::make_move_iterator(args.begin()), std::make_move_iterator(args.end()) + } + ); } private: @@ -77,7 +88,8 @@ private: if (aes::mode_requires_init_vector(mode)) { if (src.empty()) { throw boost::program_options::error{ - "an initialization vector is required for the selected mode of operation"}; + "an initialization vector is required for the selected mode of operation" + }; } iv = std::move(src.front()); src.pop_front(); diff --git a/aesxx/utils/block_dumper.hpp b/aesxx/utils/block_dumper.hpp index c725670..f05d41c 100644 --- a/aesxx/utils/block_dumper.hpp +++ b/aesxx/utils/block_dumper.hpp @@ -40,8 +40,10 @@ void dump_iv(const typename aes::Types<algorithm>::Block& iv) { } template <aes::Algorithm algorithm> -void dump_round_keys(const char* header, - const typename aes::Types<algorithm>::RoundKeys& round_keys) { +void dump_round_keys( + const char* header, + const typename aes::Types<algorithm>::RoundKeys& round_keys +) { std::cout << std::format("{}:\n", header); for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i) std::cout << std::format("\t[{}]: {}\n", i, aes::to_string<algorithm>(round_keys.keys[i])); @@ -68,26 +70,30 @@ 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> +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> +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> +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> +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/aesxx/utils/decrypt_block.cpp b/aesxx/utils/decrypt_block.cpp index d432e31..317e6fd 100644 --- a/aesxx/utils/decrypt_block.cpp +++ b/aesxx/utils/decrypt_block.cpp @@ -83,10 +83,12 @@ void decrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = f } } -void decrypt_using_cxx_api(aes::Algorithm algorithm, - aes::Mode mode, - const Input& input, - bool verbose = false) { +void decrypt_using_cxx_api( + aes::Algorithm algorithm, + aes::Mode mode, + const Input& input, + bool verbose = false +) { switch (algorithm) { case AES_AES128: decrypt_with_algorithm<AES_AES128>(mode, input, verbose); diff --git a/aesxx/utils/decrypt_bmp.cpp b/aesxx/utils/decrypt_bmp.cpp index 397ec02..50060eb 100644 --- a/aesxx/utils/decrypt_bmp.cpp +++ b/aesxx/utils/decrypt_bmp.cpp @@ -20,9 +20,11 @@ namespace { -void decrypt_bmp(aes::Box& box, - const std::string& ciphertext_path, - const std::string& plaintext_path) { +void decrypt_bmp( + aes::Box& box, + const std::string& ciphertext_path, + const std::string& plaintext_path +) { bmp::BmpFile bmp{file::read_file(ciphertext_path)}; bmp.replace_pixels(box.decrypt_buffer(bmp.get_pixels(), bmp.get_pixels_size())); file::write_file(plaintext_path, bmp.get_buffer(), bmp.get_size()); diff --git a/aesxx/utils/decrypt_file.cpp b/aesxx/utils/decrypt_file.cpp index 192f1f6..892d07b 100644 --- a/aesxx/utils/decrypt_file.cpp +++ b/aesxx/utils/decrypt_file.cpp @@ -18,9 +18,11 @@ namespace { -void decrypt_file(aes::Box& box, - const std::string& ciphertext_path, - const std::string& plaintext_path) { +void decrypt_file( + aes::Box& box, + const std::string& ciphertext_path, + const std::string& plaintext_path +) { const auto ciphertext_buf = file::read_file(ciphertext_path); const auto plaintext_buf = box.decrypt_buffer(ciphertext_buf.data(), ciphertext_buf.size()); file::write_file(plaintext_path, plaintext_buf); diff --git a/aesxx/utils/encrypt_block.cpp b/aesxx/utils/encrypt_block.cpp index e132256..5fdefd0 100644 --- a/aesxx/utils/encrypt_block.cpp +++ b/aesxx/utils/encrypt_block.cpp @@ -83,10 +83,12 @@ void encrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = f } } -void encrypt_using_cxx_api(aes::Algorithm algorithm, - aes::Mode mode, - const Input& input, - bool verbose = false) { +void encrypt_using_cxx_api( + aes::Algorithm algorithm, + aes::Mode mode, + const Input& input, + bool verbose = false +) { switch (algorithm) { case AES_AES128: encrypt_with_algorithm<AES_AES128>(mode, input, verbose); @@ -106,8 +108,10 @@ void encrypt_using_cxx_api(aes::Algorithm algorithm, } } -void encrypt_using_particular_box(aes::Box& box, - const std::vector<std::string>& input_block_strings) { +void encrypt_using_particular_box( + aes::Box& box, + const std::vector<std::string>& input_block_strings +) { for (const auto& input_block_string : input_block_strings) { aes::Box::Block plaintext; box.parse_block(plaintext, input_block_string); diff --git a/aesxx/utils/encrypt_bmp.cpp b/aesxx/utils/encrypt_bmp.cpp index 5b74fb9..f206537 100644 --- a/aesxx/utils/encrypt_bmp.cpp +++ b/aesxx/utils/encrypt_bmp.cpp @@ -18,9 +18,11 @@ namespace { -void encrypt_bmp(aes::Box& box, - const std::string& plaintext_path, - const std::string& ciphertext_path) { +void encrypt_bmp( + aes::Box& box, + const std::string& plaintext_path, + const std::string& ciphertext_path +) { bmp::BmpFile bmp{file::read_file(plaintext_path)}; bmp.replace_pixels(box.encrypt_buffer(bmp.get_pixels(), bmp.get_pixels_size())); file::write_file(ciphertext_path, bmp.get_buffer(), bmp.get_size()); diff --git a/aesxx/utils/encrypt_file.cpp b/aesxx/utils/encrypt_file.cpp index 2862bfb..4ac544c 100644 --- a/aesxx/utils/encrypt_file.cpp +++ b/aesxx/utils/encrypt_file.cpp @@ -18,9 +18,11 @@ namespace { -void encrypt_file(aes::Box& box, - const std::string& plaintext_path, - const std::string& ciphertext_path) { +void encrypt_file( + aes::Box& box, + const std::string& plaintext_path, + const std::string& ciphertext_path +) { const auto plaintext_buf = file::read_file(plaintext_path); const auto ciphertext_buf = box.encrypt_buffer(plaintext_buf.data(), plaintext_buf.size()); file::write_file(ciphertext_path, ciphertext_buf); diff --git a/aesxx/utils/file_cmd_parser.hpp b/aesxx/utils/file_cmd_parser.hpp index 5dec009..dc0c27e 100644 --- a/aesxx/utils/file_cmd_parser.hpp +++ b/aesxx/utils/file_cmd_parser.hpp @@ -28,31 +28,40 @@ public: std::string iv; explicit FileSettings(std::string_view argv0) : SettingsParser{argv0} { - visible.add_options()("algorithm,a", - boost::program_options::value<aes::Algorithm>(&algorithm) - ->required() - ->value_name("NAME"), - "set algorithm"); + visible.add_options()( + "algorithm,a", + boost::program_options::value<aes::Algorithm>(&algorithm) + ->required() + ->value_name("NAME"), + "set algorithm" + ); visible.add_options()( "mode,m", boost::program_options::value<aes::Mode>(&mode)->required()->value_name("MODE"), - "set mode of operation"); + "set mode of operation" + ); visible.add_options()( "key,k", boost::program_options::value<std::string>(&key)->required()->value_name("KEY"), - "set encryption key"); - visible.add_options()("iv,v", - boost::program_options::value<std::string>(&iv)->value_name("BLOCK"), - "set initialization vector"); + "set encryption key" + ); + visible.add_options()( + "iv,v", + boost::program_options::value<std::string>(&iv)->value_name("BLOCK"), + "set initialization vector" + ); visible.add_options()( "input,i", boost::program_options::value<std::string>(&input_path)->required()->value_name("PATH"), - "set input file path"); - visible.add_options()("output,o", - boost::program_options::value<std::string>(&output_path) - ->required() - ->value_name("PATH"), - "set output file path"); + "set input file path" + ); + visible.add_options()( + "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 { @@ -66,7 +75,8 @@ public: 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"}; + "an initialization vector is required for the selected mode of operation" + }; } } }; diff --git a/aesxx/utils/helpers/command_line.hpp b/aesxx/utils/helpers/command_line.hpp index cc05a6a..c68d739 100644 --- a/aesxx/utils/helpers/command_line.hpp +++ b/aesxx/utils/helpers/command_line.hpp @@ -33,11 +33,13 @@ public: boost::program_options::options_description all; all.add(hidden).add(visible); boost::program_options::variables_map vm; - boost::program_options::store(boost::program_options::command_line_parser{argc, argv} - .options(all) - .positional(positional) - .run(), - vm); + boost::program_options::store( + boost::program_options::command_line_parser{argc, argv} + .options(all) + .positional(positional) + .run(), + vm + ); if (vm.count("help")) exit_with_usage = true; else |
