aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/aesxx/utils
diff options
context:
space:
mode:
Diffstat (limited to 'aesxx/utils')
-rw-r--r--aesxx/utils/CMakeLists.txt3
-rw-r--r--aesxx/utils/block_cmd_parser.hpp3
-rw-r--r--aesxx/utils/block_dumper.hpp14
-rw-r--r--aesxx/utils/block_input.hpp5
-rw-r--r--aesxx/utils/decrypt_block.cpp7
-rw-r--r--aesxx/utils/decrypt_bmp.cpp3
-rw-r--r--aesxx/utils/decrypt_file.cpp3
-rw-r--r--aesxx/utils/encrypt_block.cpp7
-rw-r--r--aesxx/utils/encrypt_bmp.cpp3
-rw-r--r--aesxx/utils/encrypt_file.cpp3
-rw-r--r--aesxx/utils/file_cmd_parser.hpp3
-rw-r--r--aesxx/utils/helpers/command_line.hpp14
12 files changed, 40 insertions, 28 deletions
diff --git a/aesxx/utils/CMakeLists.txt b/aesxx/utils/CMakeLists.txt
index 9ee06d0..de6c206 100644
--- a/aesxx/utils/CMakeLists.txt
+++ b/aesxx/utils/CMakeLists.txt
@@ -1,4 +1,4 @@
-find_package(Boost CONFIG REQUIRED COMPONENTS filesystem program_options)
+find_package(Boost CONFIG REQUIRED COMPONENTS program_options)
function(add_util name src)
set(target "util_${name}")
@@ -6,7 +6,6 @@ function(add_util name src)
target_link_libraries("${target}" PRIVATE
aesxx
Boost::disable_autolinking
- Boost::filesystem
Boost::program_options)
set_target_properties("${target}" PROPERTIES OUTPUT_NAME "${name}")
install(TARGETS "${target}" RUNTIME DESTINATION bin)
diff --git a/aesxx/utils/block_cmd_parser.hpp b/aesxx/utils/block_cmd_parser.hpp
index 3ae0eac..c179556 100644
--- a/aesxx/utils/block_cmd_parser.hpp
+++ b/aesxx/utils/block_cmd_parser.hpp
@@ -16,6 +16,7 @@
#include <deque>
#include <iterator>
#include <string>
+#include <string_view>
#include <utility>
#include <vector>
@@ -29,7 +30,7 @@ public:
std::vector<Input> inputs;
- explicit BlockSettings(const std::string& argv0) : SettingsParser{argv0} {
+ 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",
diff --git a/aesxx/utils/block_dumper.hpp b/aesxx/utils/block_dumper.hpp
index 226ba20..c725670 100644
--- a/aesxx/utils/block_dumper.hpp
+++ b/aesxx/utils/block_dumper.hpp
@@ -8,13 +8,15 @@
#include <aesxx/all.hpp>
#include <cstdlib>
+#include <format>
#include <iostream>
+#include <string_view>
#include <type_traits>
template <aes::Algorithm algorithm>
-void dump_block(const char* header, const typename aes::Types<algorithm>::Block& block) {
- std::cout << header << ": " << aes::to_string<algorithm>(block) << "\n";
- std::cout << aes::to_matrix_string<algorithm>(block) << "\n";
+void dump_block(std::string_view header, const typename aes::Types<algorithm>::Block& block) {
+ std::cout << std::format("{}: {}\n", header, aes::to_string<algorithm>(block));
+ std::cout << std::format("{}\n", aes::to_matrix_string<algorithm>(block));
}
template <aes::Algorithm algorithm>
@@ -24,7 +26,7 @@ void dump_plaintext(const typename aes::Types<algorithm>::Block& block) {
template <aes::Algorithm algorithm>
void dump_key(const typename aes::Types<algorithm>::Key& key) {
- std::cout << "Key: " << aes::to_string<algorithm>(key) << "\n\n";
+ std::cout << std::format("Key: {}\n\n", aes::to_string<algorithm>(key));
}
template <aes::Algorithm algorithm>
@@ -40,9 +42,9 @@ 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) {
- std::cout << header << ":\n";
+ std::cout << std::format("{}:\n", header);
for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i)
- std::cout << "\t[" << i << "]: " << aes::to_string<algorithm>(round_keys.keys[i]) << "\n";
+ std::cout << std::format("\t[{}]: {}\n", i, aes::to_string<algorithm>(round_keys.keys[i]));
std::cout << "\n";
}
diff --git a/aesxx/utils/block_input.hpp b/aesxx/utils/block_input.hpp
index 1dd3f70..042a680 100644
--- a/aesxx/utils/block_input.hpp
+++ b/aesxx/utils/block_input.hpp
@@ -6,15 +6,16 @@
#pragma once
#include <string>
+#include <string_view>
#include <utility>
#include <vector>
class Input {
public:
- Input(const std::string& key, const std::string& iv, std::vector<std::string>&& blocks)
+ Input(std::string_view key, std::string_view iv, std::vector<std::string>&& blocks)
: key{key}, iv{iv}, blocks{std::move(blocks)} {}
- Input(const std::string& key, std::vector<std::string>&& blocks)
+ Input(std::string key, std::vector<std::string>&& blocks)
: key{key}, blocks{std::move(blocks)} {}
const std::string key;
diff --git a/aesxx/utils/decrypt_block.cpp b/aesxx/utils/decrypt_block.cpp
index 42e496e..d432e31 100644
--- a/aesxx/utils/decrypt_block.cpp
+++ b/aesxx/utils/decrypt_block.cpp
@@ -12,6 +12,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
#include <stdexcept>
#include <string>
@@ -48,7 +49,7 @@ void decrypt_with_mode(const Input& input, bool verbose = false) {
dump_plaintext<algorithm>(plaintext);
dump_next_iv<algorithm, mode>(decrypt);
} else {
- std::cout << aes::to_string<algorithm>(plaintext) << '\n';
+ std::cout << std::format("{}\n", aes::to_string<algorithm>(plaintext));
}
}
}
@@ -112,7 +113,7 @@ void decrypt_using_particular_box(aes::Box& box, const std::vector<std::string>&
aes::Box::Block plaintext;
box.decrypt_block(ciphertext, plaintext);
- std::cout << box.format_block(plaintext) << '\n';
+ std::cout << std::format("{}\n", box.format_block(plaintext));
}
}
@@ -161,7 +162,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/decrypt_bmp.cpp b/aesxx/utils/decrypt_bmp.cpp
index 86f6b7d..397ec02 100644
--- a/aesxx/utils/decrypt_bmp.cpp
+++ b/aesxx/utils/decrypt_bmp.cpp
@@ -14,6 +14,7 @@
#include <windows.h>
#include <exception>
+#include <format>
#include <iostream>
#include <string>
@@ -69,7 +70,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/decrypt_file.cpp b/aesxx/utils/decrypt_file.cpp
index 727362c..192f1f6 100644
--- a/aesxx/utils/decrypt_file.cpp
+++ b/aesxx/utils/decrypt_file.cpp
@@ -11,6 +11,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
#include <string>
#include <vector>
@@ -67,7 +68,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/encrypt_block.cpp b/aesxx/utils/encrypt_block.cpp
index b6bdca9..e132256 100644
--- a/aesxx/utils/encrypt_block.cpp
+++ b/aesxx/utils/encrypt_block.cpp
@@ -12,6 +12,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
#include <stdexcept>
#include <string>
@@ -48,7 +49,7 @@ void encrypt_with_mode(const Input& input, bool verbose = false) {
dump_ciphertext<algorithm>(ciphertext);
dump_next_iv<algorithm, mode>(encrypt);
} else {
- std::cout << aes::to_string<algorithm>(ciphertext) << '\n';
+ std::cout << std::format("{}\n", aes::to_string<algorithm>(ciphertext));
}
}
}
@@ -113,7 +114,7 @@ void encrypt_using_particular_box(aes::Box& box,
aes::Box::Block ciphertext;
box.encrypt_block(plaintext, ciphertext);
- std::cout << box.format_block(ciphertext) << '\n';
+ std::cout << std::format("{}\n", box.format_block(ciphertext));
}
}
@@ -162,7 +163,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/encrypt_bmp.cpp b/aesxx/utils/encrypt_bmp.cpp
index 01f3a78..5b74fb9 100644
--- a/aesxx/utils/encrypt_bmp.cpp
+++ b/aesxx/utils/encrypt_bmp.cpp
@@ -12,6 +12,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
#include <string>
@@ -67,7 +68,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/encrypt_file.cpp b/aesxx/utils/encrypt_file.cpp
index 4a774fd..2862bfb 100644
--- a/aesxx/utils/encrypt_file.cpp
+++ b/aesxx/utils/encrypt_file.cpp
@@ -11,6 +11,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
#include <string>
#include <vector>
@@ -67,7 +68,7 @@ int main(int argc, char** argv) {
std::cerr << e;
return 1;
} catch (const std::exception& e) {
- std::cerr << e.what() << "\n";
+ std::cerr << std::format("{}\n", e.what());
return 1;
}
return 0;
diff --git a/aesxx/utils/file_cmd_parser.hpp b/aesxx/utils/file_cmd_parser.hpp
index 4a504c8..2389d41 100644
--- a/aesxx/utils/file_cmd_parser.hpp
+++ b/aesxx/utils/file_cmd_parser.hpp
@@ -15,6 +15,7 @@
#include <ostream>
#include <string>
+#include <string_view>
#include <utility>
class FileSettings : public command_line::SettingsParser {
@@ -27,7 +28,7 @@ public:
std::string key;
std::string iv;
- explicit FileSettings(const std::string& argv0) : SettingsParser{argv0} {
+ explicit FileSettings(std::string_view argv0) : SettingsParser{argv0} {
visible.add_options()("algorithm,a",
boost::program_options::value<aes::Algorithm>(&algorithm)
->required()
diff --git a/aesxx/utils/helpers/command_line.hpp b/aesxx/utils/helpers/command_line.hpp
index 9a2da05..cc05a6a 100644
--- a/aesxx/utils/helpers/command_line.hpp
+++ b/aesxx/utils/helpers/command_line.hpp
@@ -5,19 +5,21 @@
#pragma once
-#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <exception>
+#include <filesystem>
+#include <format>
#include <iostream>
#include <ostream>
#include <string>
+#include <string_view>
namespace command_line {
class SettingsParser {
public:
- explicit SettingsParser(const std::string& argv0) : prog_name{extract_filename(argv0)} {
+ explicit SettingsParser(std::string_view argv0) : prog_name{extract_filename(argv0)} {
visible.add_options()("help,h", "show this message and exit");
}
@@ -49,7 +51,7 @@ public:
}
void usage_error(const std::exception& e) const {
- std::cerr << "usage error: " << e.what() << '\n';
+ std::cerr << std::format("usage error: {}\n", e.what());
std::cerr << *this;
}
@@ -59,15 +61,15 @@ protected:
boost::program_options::positional_options_description positional;
private:
- static std::string extract_filename(const std::string& path) {
- return boost::filesystem::path{path}.filename().string();
+ static std::string extract_filename(std::string_view path) {
+ return std::filesystem::path{path}.filename().string();
}
const std::string prog_name;
friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser) {
const auto short_descr = parser.get_short_description();
- os << "usage: " << parser.prog_name << ' ' << short_descr << '\n';
+ os << std::format("usage: {} {}\n", parser.prog_name, short_descr);
os << parser.visible;
return os;
}