summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-22 18:59:57 +0200
committerEgor Tensin <egor@tensin.name>2026-06-22 19:02:05 +0200
commit72c774265d8d740e7fd6f5a6b8c5abff7d79237c (patch)
treeece7008a9e32ad36922860fca24ac834b731ade4
parentaesxx/utils: move helper headers to helpers/ (diff)
downloadaes-tools-72c774265d8d740e7fd6f5a6b8c5abff7d79237c.tar.gz
aes-tools-72c774265d8d740e7fd6f5a6b8c5abff7d79237c.zip
aesxx: refactoring
-rw-r--r--aesxx/utils/CMakeLists.txt3
-rw-r--r--aesxx/utils/decrypt_block.cpp31
-rw-r--r--aesxx/utils/encrypt_block.cpp31
-rw-r--r--aesxx/utils/helpers/block_input.hpp24
-rw-r--r--aesxx/utils/helpers/cmd_parser_block.hpp27
5 files changed, 65 insertions, 51 deletions
diff --git a/aesxx/utils/CMakeLists.txt b/aesxx/utils/CMakeLists.txt
index 4958bef..81bd818 100644
--- a/aesxx/utils/CMakeLists.txt
+++ b/aesxx/utils/CMakeLists.txt
@@ -16,8 +16,7 @@ function(add_util name src)
endfunction()
set(block_util_headers
- block_dumper.hpp
- block_input.hpp
+ helpers/block_dumper.hpp
helpers/cmd_parser.hpp
helpers/cmd_paresr_block.hpp
helpers/data_parsers.hpp
diff --git a/aesxx/utils/decrypt_block.cpp b/aesxx/utils/decrypt_block.cpp
index bcd3381..f6bd8a3 100644
--- a/aesxx/utils/decrypt_block.cpp
+++ b/aesxx/utils/decrypt_block.cpp
@@ -4,7 +4,6 @@
// Distributed under the MIT License.
#include "helpers/block_dumper.hpp"
-#include "helpers/block_input.hpp"
#include "helpers/cmd_parser_block.hpp"
#include <aesxx/all.hpp>
@@ -20,18 +19,18 @@
namespace {
template <aes::Algorithm algorithm, aes::Mode mode>
-void decrypt_with_mode(const Input& input, bool verbose = false) {
+void decrypt_with_mode(const BlockSettings::Input& input, bool verbose = false) {
typename aes::Types<algorithm>::Block iv;
aes::make_block(iv, 0, 0, 0, 0);
if constexpr (aes::mode_requires_init_vector(mode)) {
- aes::from_string<algorithm>(iv, input.iv);
+ aes::from_string<algorithm>(iv, input.get_iv());
if (verbose)
dump_iv<algorithm>(iv);
}
typename aes::Types<algorithm>::Key key;
- aes::from_string<algorithm>(key, input.key);
+ aes::from_string<algorithm>(key, input.get_key());
if (verbose)
dump_key<algorithm>(key);
@@ -39,7 +38,7 @@ void decrypt_with_mode(const Input& input, bool verbose = false) {
if (verbose)
dump_wrapper<algorithm, mode>(decrypt);
- for (const auto& block : input.blocks) {
+ for (const auto& block : input.get_blocks()) {
typename aes::Types<algorithm>::Block ciphertext, plaintext;
aes::from_string<algorithm>(ciphertext, block);
@@ -56,7 +55,11 @@ void decrypt_with_mode(const Input& input, bool verbose = false) {
}
template <aes::Algorithm algorithm>
-void decrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = false) {
+void decrypt_with_algorithm(
+ aes::Mode mode,
+ const BlockSettings::Input& input,
+ bool verbose = false
+) {
switch (mode) {
case AES_ECB:
decrypt_with_mode<algorithm, AES_ECB>(input, verbose);
@@ -87,7 +90,7 @@ 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,
+ const BlockSettings::Input& input,
bool verbose = false
) {
switch (algorithm) {
@@ -120,19 +123,23 @@ void decrypt_using_particular_box(aes::Box& box, const std::vector<std::string>&
}
}
-void decrypt_using_boxes(aes::Algorithm algorithm, aes::Mode mode, const Input& input) {
+void decrypt_using_boxes(
+ aes::Algorithm algorithm,
+ aes::Mode mode,
+ const BlockSettings::Input& input
+) {
aes::Box::Key key;
- aes::Box::parse_key(key, algorithm, input.key);
+ aes::Box::parse_key(key, algorithm, input.get_key());
if (aes::mode_requires_init_vector(mode)) {
aes::Box::Block iv;
- aes::Box::parse_block(iv, algorithm, input.iv);
+ aes::Box::parse_block(iv, algorithm, input.get_iv());
aes::Box box{algorithm, key, mode, iv};
- decrypt_using_particular_box(box, input.blocks);
+ decrypt_using_particular_box(box, input.get_blocks());
} else {
aes::Box box{algorithm, key};
- decrypt_using_particular_box(box, input.blocks);
+ decrypt_using_particular_box(box, input.get_blocks());
}
}
diff --git a/aesxx/utils/encrypt_block.cpp b/aesxx/utils/encrypt_block.cpp
index d6e5534..a67cd6b 100644
--- a/aesxx/utils/encrypt_block.cpp
+++ b/aesxx/utils/encrypt_block.cpp
@@ -4,7 +4,6 @@
// Distributed under the MIT License.
#include "helpers/block_dumper.hpp"
-#include "helpers/block_input.hpp"
#include "helpers/cmd_parser_block.hpp"
#include <aesxx/all.hpp>
@@ -20,18 +19,18 @@
namespace {
template <aes::Algorithm algorithm, aes::Mode mode>
-void encrypt_with_mode(const Input& input, bool verbose = false) {
+void encrypt_with_mode(const BlockSettings::Input& input, bool verbose = false) {
typename aes::Types<algorithm>::Block iv;
aes::make_block(iv, 0, 0, 0, 0);
if constexpr (aes::mode_requires_init_vector(mode)) {
- aes::from_string<algorithm>(iv, input.iv);
+ aes::from_string<algorithm>(iv, input.get_iv());
if (verbose)
dump_iv<algorithm>(iv);
}
typename aes::Types<algorithm>::Key key;
- aes::from_string<algorithm>(key, input.key);
+ aes::from_string<algorithm>(key, input.get_key());
if (verbose)
dump_key<algorithm>(key);
@@ -39,7 +38,7 @@ void encrypt_with_mode(const Input& input, bool verbose = false) {
if (verbose)
dump_wrapper<algorithm, mode>(encrypt);
- for (const auto& input_block_string : input.blocks) {
+ for (const auto& input_block_string : input.get_blocks()) {
typename aes::Types<algorithm>::Block plaintext, ciphertext;
aes::from_string<algorithm>(plaintext, input_block_string);
@@ -56,7 +55,11 @@ void encrypt_with_mode(const Input& input, bool verbose = false) {
}
template <aes::Algorithm algorithm>
-void encrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = false) {
+void encrypt_with_algorithm(
+ aes::Mode mode,
+ const BlockSettings::Input& input,
+ bool verbose = false
+) {
switch (mode) {
case AES_ECB:
encrypt_with_mode<algorithm, AES_ECB>(input, verbose);
@@ -87,7 +90,7 @@ 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,
+ const BlockSettings::Input& input,
bool verbose = false
) {
switch (algorithm) {
@@ -123,19 +126,23 @@ void encrypt_using_particular_box(
}
}
-void encrypt_using_boxes(aes::Algorithm algorithm, aes::Mode mode, const Input& input) {
+void encrypt_using_boxes(
+ aes::Algorithm algorithm,
+ aes::Mode mode,
+ const BlockSettings::Input& input
+) {
aes::Box::Key key;
- aes::Box::parse_key(key, algorithm, input.key);
+ aes::Box::parse_key(key, algorithm, input.get_key());
if (aes::mode_requires_init_vector(mode)) {
aes::Box::Block iv;
- aes::Box::parse_block(iv, algorithm, input.iv);
+ aes::Box::parse_block(iv, algorithm, input.get_iv());
aes::Box box{algorithm, key, mode, iv};
- encrypt_using_particular_box(box, input.blocks);
+ encrypt_using_particular_box(box, input.get_blocks());
} else {
aes::Box box{algorithm, key};
- encrypt_using_particular_box(box, input.blocks);
+ encrypt_using_particular_box(box, input.get_blocks());
}
}
diff --git a/aesxx/utils/helpers/block_input.hpp b/aesxx/utils/helpers/block_input.hpp
deleted file mode 100644
index 042a680..0000000
--- a/aesxx/utils/helpers/block_input.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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 <string>
-#include <string_view>
-#include <utility>
-#include <vector>
-
-class Input {
-public:
- Input(std::string_view key, std::string_view iv, std::vector<std::string>&& blocks)
- : key{key}, iv{iv}, blocks{std::move(blocks)} {}
-
- Input(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;
-};
diff --git a/aesxx/utils/helpers/cmd_parser_block.hpp b/aesxx/utils/helpers/cmd_parser_block.hpp
index c8db431..0093617 100644
--- a/aesxx/utils/helpers/cmd_parser_block.hpp
+++ b/aesxx/utils/helpers/cmd_parser_block.hpp
@@ -5,7 +5,6 @@
#pragma once
-#include "block_input.hpp"
#include "cmd_parser.hpp"
#include "data_parsers.hpp"
@@ -22,6 +21,32 @@
class BlockSettings : public SettingsParser {
public:
+ class Input {
+ public:
+ Input(std::string_view key, std::string_view iv, std::vector<std::string>&& blocks)
+ : key{key}, iv{iv}, blocks{std::move(blocks)} {}
+
+ Input(std::string key, std::vector<std::string>&& blocks)
+ : key{key}, blocks{std::move(blocks)} {}
+
+ std::string get_key() const {
+ return key;
+ }
+
+ std::string get_iv() const {
+ return iv;
+ }
+
+ std::vector<std::string> get_blocks() const {
+ return blocks;
+ }
+
+ private:
+ std::string key;
+ std::string iv;
+ std::vector<std::string> blocks;
+ };
+
aes::Algorithm algorithm = AES_AES128;
aes::Mode mode = AES_ECB;