diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-22 19:24:27 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-22 19:29:28 +0200 |
| commit | fe12cdce3fa13d490852e7f389015a1958a6f2c6 (patch) | |
| tree | 0802935a5fd6f494cc57d66c8a7282185267c12d | |
| parent | aesxx/utils: more refactoring (diff) | |
| download | aes-tools-fe12cdce3fa13d490852e7f389015a1958a6f2c6.tar.gz aes-tools-fe12cdce3fa13d490852e7f389015a1958a6f2c6.zip | |
aesxx/utils: some more basic refactoring
| -rw-r--r-- | aesxx/utils/decrypt_block.cpp | 2 | ||||
| -rw-r--r-- | aesxx/utils/decrypt_bmp.cpp | 14 | ||||
| -rw-r--r-- | aesxx/utils/decrypt_file.cpp | 14 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_block.cpp | 2 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_bmp.cpp | 14 | ||||
| -rw-r--r-- | aesxx/utils/encrypt_file.cpp | 14 | ||||
| -rw-r--r-- | aesxx/utils/helpers/cmd_parser.hpp | 8 | ||||
| -rw-r--r-- | aesxx/utils/helpers/cmd_parser_file.hpp | 42 |
8 files changed, 70 insertions, 40 deletions
diff --git a/aesxx/utils/decrypt_block.cpp b/aesxx/utils/decrypt_block.cpp index be5c003..cb14bef 100644 --- a/aesxx/utils/decrypt_block.cpp +++ b/aesxx/utils/decrypt_block.cpp @@ -156,7 +156,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/decrypt_bmp.cpp b/aesxx/utils/decrypt_bmp.cpp index d805c62..84286ef 100644 --- a/aesxx/utils/decrypt_bmp.cpp +++ b/aesxx/utils/decrypt_bmp.cpp @@ -31,21 +31,21 @@ void decrypt_bmp( } void decrypt_bmp(const FileSettings& settings) { - const auto& algorithm = settings.algorithm; - const auto& mode = settings.mode; + const auto algorithm = settings.get_algorithm(); + const auto mode = settings.get_mode(); aes::Box::Key key; - aes::Box::parse_key(key, algorithm, settings.key); + aes::Box::parse_key(key, algorithm, settings.get_key()); if (aes::mode_requires_init_vector(mode)) { aes::Box::Block iv; - aes::Box::parse_block(iv, algorithm, settings.iv); + aes::Box::parse_block(iv, algorithm, settings.get_iv()); aes::Box box{algorithm, key, mode, iv}; - decrypt_bmp(box, settings.input_path, settings.output_path); + decrypt_bmp(box, settings.get_input_path(), settings.get_output_path()); } else { aes::Box box{algorithm, key}; - decrypt_bmp(box, settings.input_path, settings.output_path); + decrypt_bmp(box, settings.get_input_path(), settings.get_output_path()); } } @@ -62,7 +62,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/decrypt_file.cpp b/aesxx/utils/decrypt_file.cpp index 42fe3e9..39084fd 100644 --- a/aesxx/utils/decrypt_file.cpp +++ b/aesxx/utils/decrypt_file.cpp @@ -29,21 +29,21 @@ void decrypt_file( } void decrypt_file(const FileSettings& settings) { - const auto& algorithm = settings.algorithm; - const auto& mode = settings.mode; + const auto algorithm = settings.get_algorithm(); + const auto mode = settings.get_mode(); aes::Box::Key key; - aes::Box::parse_key(key, algorithm, settings.key); + aes::Box::parse_key(key, algorithm, settings.get_key()); if (aes::mode_requires_init_vector(mode)) { aes::Box::Block iv; - aes::Box::parse_block(iv, algorithm, settings.iv); + aes::Box::parse_block(iv, algorithm, settings.get_iv()); aes::Box box{algorithm, key, mode, iv}; - decrypt_file(box, settings.input_path, settings.output_path); + decrypt_file(box, settings.get_input_path(), settings.get_output_path()); } else { aes::Box box{algorithm, key}; - decrypt_file(box, settings.input_path, settings.output_path); + decrypt_file(box, settings.get_input_path(), settings.get_output_path()); } } @@ -60,7 +60,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/encrypt_block.cpp b/aesxx/utils/encrypt_block.cpp index 2e59634..e1a4c1e 100644 --- a/aesxx/utils/encrypt_block.cpp +++ b/aesxx/utils/encrypt_block.cpp @@ -159,7 +159,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/encrypt_bmp.cpp b/aesxx/utils/encrypt_bmp.cpp index 5c9acbf..2a22e73 100644 --- a/aesxx/utils/encrypt_bmp.cpp +++ b/aesxx/utils/encrypt_bmp.cpp @@ -29,21 +29,21 @@ void encrypt_bmp( } void encrypt_bmp(const FileSettings& settings) { - const auto& algorithm = settings.algorithm; - const auto& mode = settings.mode; + const auto algorithm = settings.get_algorithm(); + const auto mode = settings.get_mode(); aes::Box::Key key; - aes::Box::parse_key(key, algorithm, settings.key); + aes::Box::parse_key(key, algorithm, settings.get_key()); if (aes::mode_requires_init_vector(mode)) { aes::Box::Block iv; - aes::Box::parse_block(iv, algorithm, settings.iv); + aes::Box::parse_block(iv, algorithm, settings.get_iv()); aes::Box box{algorithm, key, mode, iv}; - encrypt_bmp(box, settings.input_path, settings.output_path); + encrypt_bmp(box, settings.get_input_path(), settings.get_output_path()); } else { aes::Box box{algorithm, key}; - encrypt_bmp(box, settings.input_path, settings.output_path); + encrypt_bmp(box, settings.get_input_path(), settings.get_output_path()); } } @@ -60,7 +60,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/encrypt_file.cpp b/aesxx/utils/encrypt_file.cpp index e069ec7..9f08378 100644 --- a/aesxx/utils/encrypt_file.cpp +++ b/aesxx/utils/encrypt_file.cpp @@ -29,21 +29,21 @@ void encrypt_file( } void encrypt_file(const FileSettings& settings) { - const auto& algorithm = settings.algorithm; - const auto& mode = settings.mode; + const auto algorithm = settings.get_algorithm(); + const auto mode = settings.get_mode(); aes::Box::Key key; - aes::Box::parse_key(key, algorithm, settings.key); + aes::Box::parse_key(key, algorithm, settings.get_key()); if (aes::mode_requires_init_vector(mode)) { aes::Box::Block iv; - aes::Box::parse_block(iv, algorithm, settings.iv); + aes::Box::parse_block(iv, algorithm, settings.get_iv()); aes::Box box{algorithm, key, mode, iv}; - encrypt_file(box, settings.input_path, settings.output_path); + encrypt_file(box, settings.get_input_path(), settings.get_output_path()); } else { aes::Box box{algorithm, key}; - encrypt_file(box, settings.input_path, settings.output_path); + encrypt_file(box, settings.get_input_path(), settings.get_output_path()); } } @@ -60,7 +60,7 @@ int main(int argc, char** argv) { return 1; } - if (settings.exit_with_usage) { + if (settings.exit_with_usage()) { settings.usage(); return 0; } diff --git a/aesxx/utils/helpers/cmd_parser.hpp b/aesxx/utils/helpers/cmd_parser.hpp index 607253c..11146e8 100644 --- a/aesxx/utils/helpers/cmd_parser.hpp +++ b/aesxx/utils/helpers/cmd_parser.hpp @@ -39,12 +39,14 @@ public: vm ); if (vm.count("help")) - exit_with_usage = true; + _exit_with_usage = true; else boost::program_options::notify(vm); } - bool exit_with_usage = false; + bool exit_with_usage() const { + return _exit_with_usage; + } void usage() const { std::cout << *this; @@ -73,4 +75,6 @@ private: os << parser.visible; return os; } + + bool _exit_with_usage = false; }; diff --git a/aesxx/utils/helpers/cmd_parser_file.hpp b/aesxx/utils/helpers/cmd_parser_file.hpp index fd6072a..81562f5 100644 --- a/aesxx/utils/helpers/cmd_parser_file.hpp +++ b/aesxx/utils/helpers/cmd_parser_file.hpp @@ -19,14 +19,6 @@ class FileSettings : public SettingsParser { 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; - explicit FileSettings(std::string_view argv0) : SettingsParser{argv0} { visible.add_options()( "algorithm,a", @@ -79,4 +71,38 @@ public: }; } } + + aes::Algorithm get_algorithm() const { + return algorithm; + } + + aes::Mode get_mode() const { + return mode; + } + + std::string get_input_path() const { + return input_path; + } + + std::string get_output_path() const { + return output_path; + } + + std::string get_key() const { + return key; + } + + std::string get_iv() const { + return iv; + } + +private: + aes::Algorithm algorithm; + aes::Mode mode; + + std::string input_path; + std::string output_path; + + std::string key; + std::string iv; }; |
