summaryrefslogtreecommitdiffstatshomepage
path: root/aesxx/include
diff options
context:
space:
mode:
Diffstat (limited to 'aesxx/include')
-rw-r--r--aesxx/include/aesxx/aes.hpp25
-rw-r--r--aesxx/include/aesxx/api.hpp15
-rw-r--r--aesxx/include/aesxx/box.hpp29
-rw-r--r--aesxx/include/aesxx/debug.hpp25
-rw-r--r--aesxx/include/aesxx/error.hpp5
5 files changed, 35 insertions, 64 deletions
diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp
index c3457c8..dedd366 100644
--- a/aesxx/include/aesxx/aes.hpp
+++ b/aesxx/include/aesxx/aes.hpp
@@ -14,6 +14,7 @@
#include <cstddef>
#include <string>
+#include <string_view>
namespace aes {
namespace aes128 {
@@ -37,8 +38,8 @@ inline std::size_t get_number_of_rounds<AES_AES128>() {
}
template <>
-inline void from_string<AES_AES128>(aes128::Block& dest, const char* src) {
- aes_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES128>(aes128::Block& dest, std::string_view src) {
+ aes_AES128_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
@@ -56,8 +57,8 @@ inline std::string to_matrix_string<AES_AES128>(const aes128::Block& src) {
}
template <>
-inline void from_string<AES_AES128>(aes128::Key& dest, const char* src) {
- aes_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES128>(aes128::Key& dest, std::string_view src) {
+ aes_AES128_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
@@ -110,8 +111,8 @@ inline std::size_t get_number_of_rounds<AES_AES192>() {
}
template <>
-inline void from_string<AES_AES192>(aes192::Block& dest, const char* src) {
- aes_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES192>(aes192::Block& dest, std::string_view src) {
+ aes_AES192_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
@@ -129,8 +130,8 @@ inline std::string to_matrix_string<AES_AES192>(const aes192::Block& src) {
}
template <>
-inline void from_string<AES_AES192>(aes192::Key& dest, const char* src) {
- aes_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES192>(aes192::Key& dest, std::string_view src) {
+ aes_AES192_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
@@ -183,8 +184,8 @@ inline std::size_t get_number_of_rounds<AES_AES256>() {
}
template <>
-inline void from_string<AES_AES256>(aes256::Block& dest, const char* src) {
- aes_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES256>(aes256::Block& dest, std::string_view src) {
+ aes_AES256_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
@@ -202,8 +203,8 @@ inline std::string to_matrix_string<AES_AES256>(const aes256::Block& src) {
}
template <>
-inline void from_string<AES_AES256>(aes256::Key& dest, const char* src) {
- aes_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
+inline void from_string<AES_AES256>(aes256::Key& dest, std::string_view src) {
+ aes_AES256_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{});
}
template <>
diff --git a/aesxx/include/aesxx/api.hpp b/aesxx/include/aesxx/api.hpp
index 759ff0c..4c1c868 100644
--- a/aesxx/include/aesxx/api.hpp
+++ b/aesxx/include/aesxx/api.hpp
@@ -10,6 +10,7 @@
#include <cstddef>
#include <string>
+#include <string_view>
#include <type_traits>
namespace aes {
@@ -21,12 +22,7 @@ template <Algorithm algorithm>
std::size_t get_number_of_rounds();
template <Algorithm algorithm>
-void from_string(typename Types<algorithm>::Block&, const char*);
-
-template <Algorithm algorithm>
-void from_string(typename Types<algorithm>::Block& dest, const std::string& src) {
- from_string<algorithm>(dest, src.c_str());
-}
+void from_string(typename Types<algorithm>::Block&, std::string_view);
template <Algorithm algorithm>
std::string to_string(const typename Types<algorithm>::Block&);
@@ -35,12 +31,7 @@ template <Algorithm algorithm>
std::string to_matrix_string(const typename Types<algorithm>::Block&);
template <Algorithm algorithm>
-void from_string(typename Types<algorithm>::Key&, const char*);
-
-template <Algorithm algorithm>
-void from_string(typename Types<algorithm>::Key& dest, const std::string& src) {
- from_string<algorithm>(dest, src.c_str());
-}
+void from_string(typename Types<algorithm>::Key&, std::string_view);
template <Algorithm algorithm>
std::string to_string(const typename Types<algorithm>::Key&);
diff --git a/aesxx/include/aesxx/box.hpp b/aesxx/include/aesxx/box.hpp
index 540688b..fb42525 100644
--- a/aesxx/include/aesxx/box.hpp
+++ b/aesxx/include/aesxx/box.hpp
@@ -13,6 +13,7 @@
#include <cstddef>
#include <string>
+#include <string_view>
#include <vector>
namespace aes {
@@ -34,20 +35,12 @@ public:
return reinterpret_cast<const char*>(&str);
}
- static void parse_block(Block& dest, Algorithm algorithm, const char* src) {
- aes_box_parse_block(&dest, algorithm, src, ErrorDetailsThrowsInDestructor{});
+ static void parse_block(Block& dest, Algorithm algorithm, std::string_view src) {
+ aes_box_parse_block(&dest, algorithm, src.data(), ErrorDetailsThrowsInDestructor{});
}
- static void parse_block(Block& dest, Algorithm algorithm, const std::string& src) {
- parse_block(dest, algorithm, src.c_str());
- }
-
- static void parse_key(Key& dest, Algorithm algorithm, const char* src) {
- aes_box_parse_key(&dest, algorithm, src, ErrorDetailsThrowsInDestructor{});
- }
-
- static void parse_key(Key& dest, Algorithm algorithm, const std::string& src) {
- parse_key(dest, algorithm, src.c_str());
+ static void parse_key(Key& dest, Algorithm algorithm, std::string_view src) {
+ aes_box_parse_key(&dest, algorithm, src.data(), ErrorDetailsThrowsInDestructor{});
}
Box(Algorithm algorithm, const Key& key) : algorithm{algorithm}, mode{AES_ECB} {
@@ -115,22 +108,14 @@ public:
return format_key(src, get_algorithm());
}
- void parse_block(Block& dest, const char* src) {
+ void parse_block(Block& dest, std::string_view src) {
parse_block(dest, get_algorithm(), src);
}
- void parse_block(Block& dest, const std::string& src) {
- parse_block(dest, src.c_str());
- }
-
- void parse_key(Key& dest, const char* src) {
+ void parse_key(Key& dest, std::string_view src) {
parse_key(dest, get_algorithm(), src);
}
- void parse_key(Key& dest, const std::string& src) {
- parse_key(dest, src.c_str());
- }
-
Algorithm get_algorithm() const {
return algorithm;
}
diff --git a/aesxx/include/aesxx/debug.hpp b/aesxx/include/aesxx/debug.hpp
index d54605d..13ea898 100644
--- a/aesxx/include/aesxx/debug.hpp
+++ b/aesxx/include/aesxx/debug.hpp
@@ -13,8 +13,10 @@
#endif
#include <cstddef>
+#include <format>
#include <sstream>
#include <string>
+#include <string_view>
namespace aes {
namespace aux {
@@ -34,37 +36,28 @@ public:
private:
template <typename T>
static std::string put_between_brackets(const T& x) {
- std::ostringstream oss;
- oss << "[" << x << "]";
- return oss.str();
- }
-
- template <typename T>
- static std::string stringify(const T& x) {
- std::ostringstream oss;
- oss << x;
- return oss.str();
+ return std::format("[{}]", x);
}
static std::string format_address_fallback(const void* addr) {
return put_between_brackets(addr);
}
- static std::string format_module(const std::string& module_name, const void* offset = nullptr) {
+ static std::string format_module(std::string_view module_name, const void* offset = nullptr) {
if (offset == nullptr)
return put_between_brackets(module_name);
else
- return put_between_brackets(module_name + "+" + stringify(offset));
+ return put_between_brackets(std::format("{}+{}", module_name, offset));
}
- static std::string format_symbol(const std::string& symbol_name, const void* offset = nullptr) {
+ static std::string format_symbol(std::string_view symbol_name, const void* offset = nullptr) {
return format_module(symbol_name, offset);
}
- static std::string format_symbol(const std::string& module_name,
- const std::string& symbol_name,
+ static std::string format_symbol(std::string_view module_name,
+ std::string_view symbol_name,
const void* offset = nullptr) {
- return format_symbol(module_name + "!" + symbol_name, offset);
+ return format_symbol(std::format("{}!{}", module_name, symbol_name), offset);
}
#ifdef WIN32
diff --git a/aesxx/include/aesxx/error.hpp b/aesxx/include/aesxx/error.hpp
index e5c5803..72a50b3 100644
--- a/aesxx/include/aesxx/error.hpp
+++ b/aesxx/include/aesxx/error.hpp
@@ -14,6 +14,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>
+#include <format>
#include <functional>
#include <ostream>
#include <stdexcept>
@@ -60,10 +61,10 @@ private:
};
inline std::ostream& operator<<(std::ostream& os, const Error& error) {
- os << "AES error: " << error.what() << '\n';
+ os << std::format("AES error: {}\n", error.what());
os << "Call stack:\n";
error.for_each_addr([&os](const void* addr, const std::string& name) {
- os << '\t' << addr << ' ' << name << '\n';
+ os << std::format("\t{} {}\n", addr, name);
});
return os;
}