diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-22 18:09:30 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-22 18:09:30 +0200 |
| commit | 1f6cacd70c7309fd38b76a14ec7d58af04debe07 (patch) | |
| tree | a54b2af969552b34d47bff56f83338e55d5a8cf0 /aesxx/utils/helpers/cmd_parser_file.hpp | |
| parent | aesxx/utils: refactoring (diff) | |
| download | aes-tools-1f6cacd70c7309fd38b76a14ec7d58af04debe07.tar.gz aes-tools-1f6cacd70c7309fd38b76a14ec7d58af04debe07.zip | |
aesxx/utils: move helper headers to helpers/
Diffstat (limited to 'aesxx/utils/helpers/cmd_parser_file.hpp')
| -rw-r--r-- | aesxx/utils/helpers/cmd_parser_file.hpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/aesxx/utils/helpers/cmd_parser_file.hpp b/aesxx/utils/helpers/cmd_parser_file.hpp new file mode 100644 index 0000000..fd6072a --- /dev/null +++ b/aesxx/utils/helpers/cmd_parser_file.hpp @@ -0,0 +1,82 @@ +// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com> +// This file is part of the "AES tools" project. +// For details, see https://github.com/egor-tensin/aes-tools. +// Distributed under the MIT License. + +#pragma once + +#include "cmd_parser.hpp" +#include "data_parsers.hpp" + +#include <aesxx/all.hpp> + +#include <boost/program_options.hpp> + +#include <ostream> +#include <string> +#include <string_view> +#include <utility> + +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", + 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()( + "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" + ); + 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" + ); + } + + 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); + + 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" + }; + } + } +}; |
