aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/aesxx/utils
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-22 17:57:37 +0200
committerEgor Tensin <egor@tensin.name>2026-06-22 17:57:37 +0200
commit05691f614baa782801c4b22efa2ee9a73de4b3b3 (patch)
tree99a1af51ac882a2b1bb7db3e95c5d462b7879118 /aesxx/utils
parentMerge pull request #7 from egor-tensin/dependabot/github_actions/actions/chec... (diff)
downloadaes-tools-05691f614baa782801c4b22efa2ee9a73de4b3b3.tar.gz
aes-tools-05691f614baa782801c4b22efa2ee9a73de4b3b3.zip
aesxx/utils: refactoring
Diffstat (limited to 'aesxx/utils')
-rw-r--r--aesxx/utils/block_cmd_parser.hpp2
-rw-r--r--aesxx/utils/decrypt_bmp.cpp4
-rw-r--r--aesxx/utils/decrypt_file.cpp4
-rw-r--r--aesxx/utils/encrypt_bmp.cpp4
-rw-r--r--aesxx/utils/encrypt_file.cpp4
-rw-r--r--aesxx/utils/file_cmd_parser.hpp2
-rw-r--r--aesxx/utils/helpers/bmp.hpp4
-rw-r--r--aesxx/utils/helpers/command_line.hpp4
-rw-r--r--aesxx/utils/helpers/file.hpp12
9 files changed, 16 insertions, 24 deletions
diff --git a/aesxx/utils/block_cmd_parser.hpp b/aesxx/utils/block_cmd_parser.hpp
index 5bfdb1e..a20f4f5 100644
--- a/aesxx/utils/block_cmd_parser.hpp
+++ b/aesxx/utils/block_cmd_parser.hpp
@@ -20,7 +20,7 @@
#include <utility>
#include <vector>
-class BlockSettings : public command_line::SettingsParser {
+class BlockSettings : public SettingsParser {
public:
aes::Algorithm algorithm = AES_AES128;
aes::Mode mode = AES_ECB;
diff --git a/aesxx/utils/decrypt_bmp.cpp b/aesxx/utils/decrypt_bmp.cpp
index 50060eb..3247d63 100644
--- a/aesxx/utils/decrypt_bmp.cpp
+++ b/aesxx/utils/decrypt_bmp.cpp
@@ -25,9 +25,9 @@ void decrypt_bmp(
const std::string& ciphertext_path,
const std::string& plaintext_path
) {
- bmp::BmpFile bmp{file::read_file(ciphertext_path)};
+ BmpFile bmp{file::read(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());
+ file::write(plaintext_path, bmp.get_buffer(), bmp.get_size());
}
void decrypt_bmp(const FileSettings& settings) {
diff --git a/aesxx/utils/decrypt_file.cpp b/aesxx/utils/decrypt_file.cpp
index 892d07b..85476a9 100644
--- a/aesxx/utils/decrypt_file.cpp
+++ b/aesxx/utils/decrypt_file.cpp
@@ -23,9 +23,9 @@ void decrypt_file(
const std::string& ciphertext_path,
const std::string& plaintext_path
) {
- const auto ciphertext_buf = file::read_file(ciphertext_path);
+ const auto ciphertext_buf = file::read(ciphertext_path);
const auto plaintext_buf = box.decrypt_buffer(ciphertext_buf.data(), ciphertext_buf.size());
- file::write_file(plaintext_path, plaintext_buf);
+ file::write(plaintext_path, plaintext_buf);
}
void decrypt_file(const FileSettings& settings) {
diff --git a/aesxx/utils/encrypt_bmp.cpp b/aesxx/utils/encrypt_bmp.cpp
index f206537..2be1e4f 100644
--- a/aesxx/utils/encrypt_bmp.cpp
+++ b/aesxx/utils/encrypt_bmp.cpp
@@ -23,9 +23,9 @@ void encrypt_bmp(
const std::string& plaintext_path,
const std::string& ciphertext_path
) {
- bmp::BmpFile bmp{file::read_file(plaintext_path)};
+ BmpFile bmp{file::read(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());
+ file::write(ciphertext_path, bmp.get_buffer(), bmp.get_size());
}
void encrypt_bmp(const FileSettings& settings) {
diff --git a/aesxx/utils/encrypt_file.cpp b/aesxx/utils/encrypt_file.cpp
index 4ac544c..94ed47c 100644
--- a/aesxx/utils/encrypt_file.cpp
+++ b/aesxx/utils/encrypt_file.cpp
@@ -23,9 +23,9 @@ void encrypt_file(
const std::string& plaintext_path,
const std::string& ciphertext_path
) {
- const auto plaintext_buf = file::read_file(plaintext_path);
+ const auto plaintext_buf = file::read(plaintext_path);
const auto ciphertext_buf = box.encrypt_buffer(plaintext_buf.data(), plaintext_buf.size());
- file::write_file(ciphertext_path, ciphertext_buf);
+ file::write(ciphertext_path, ciphertext_buf);
}
void encrypt_file(const FileSettings& settings) {
diff --git a/aesxx/utils/file_cmd_parser.hpp b/aesxx/utils/file_cmd_parser.hpp
index dc0c27e..5cb109b 100644
--- a/aesxx/utils/file_cmd_parser.hpp
+++ b/aesxx/utils/file_cmd_parser.hpp
@@ -17,7 +17,7 @@
#include <string_view>
#include <utility>
-class FileSettings : public command_line::SettingsParser {
+class FileSettings : public SettingsParser {
public:
aes::Algorithm algorithm = AES_AES128;
aes::Mode mode = AES_ECB;
diff --git a/aesxx/utils/helpers/bmp.hpp b/aesxx/utils/helpers/bmp.hpp
index c256a7a..086be00 100644
--- a/aesxx/utils/helpers/bmp.hpp
+++ b/aesxx/utils/helpers/bmp.hpp
@@ -11,8 +11,6 @@
#include <utility>
#include <vector>
-namespace bmp {
-
class BmpFile {
public:
BmpFile(std::vector<char>&& buffer)
@@ -52,5 +50,3 @@ private:
std::vector<char> buffer;
std::size_t header_size;
};
-
-} // namespace bmp
diff --git a/aesxx/utils/helpers/command_line.hpp b/aesxx/utils/helpers/command_line.hpp
index c68d739..607253c 100644
--- a/aesxx/utils/helpers/command_line.hpp
+++ b/aesxx/utils/helpers/command_line.hpp
@@ -15,8 +15,6 @@
#include <string>
#include <string_view>
-namespace command_line {
-
class SettingsParser {
public:
explicit SettingsParser(std::string_view argv0) : prog_name{extract_filename(argv0)} {
@@ -76,5 +74,3 @@ private:
return os;
}
};
-
-} // namespace command_line
diff --git a/aesxx/utils/helpers/file.hpp b/aesxx/utils/helpers/file.hpp
index 76e3e96..085d78c 100644
--- a/aesxx/utils/helpers/file.hpp
+++ b/aesxx/utils/helpers/file.hpp
@@ -23,15 +23,15 @@ inline std::size_t cast_to_size_t(std::streamoff size) {
return static_cast<std::size_t>(size);
}
-inline std::size_t get_file_size(const std::string& path) {
+inline std::size_t get_size(const std::string& path) {
std::ifstream ifs;
ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit);
ifs.open(path, std::ifstream::binary | std::ifstream::ate);
return cast_to_size_t(ifs.tellg());
}
-inline std::vector<char> read_file(const std::string& path) {
- const auto size = get_file_size(path);
+inline std::vector<char> read(const std::string& path) {
+ const auto size = get_size(path);
std::ifstream ifs;
ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit);
@@ -43,15 +43,15 @@ inline std::vector<char> read_file(const std::string& path) {
return src_buf;
}
-inline void write_file(const std::string& path, const void* buffer, const std::size_t size) {
+inline void write(const std::string& path, const void* buffer, const std::size_t size) {
std::ofstream ofs;
ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit);
ofs.open(path, std::ofstream::binary);
ofs.write(reinterpret_cast<const char*>(buffer), size);
}
-inline void write_file(const std::string& path, const std::vector<unsigned char>& src) {
- write_file(path, src.data(), src.size());
+inline void write(const std::string& path, const std::vector<unsigned char>& src) {
+ write(path, src.data(), src.size());
}
} // namespace file