aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-03 20:47:15 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-03 20:47:15 +0300
commit786480850ac3d16c62ee2abfe410c4e00d16f70b (patch)
tree2026f57a1455381083c487730474b5d171f83ea4
parentcommon.cmake: bugfix & refactoring (diff)
downloadaes-tools-786480850ac3d16c62ee2abfe410c4e00d16f70b.tar.gz
aes-tools-786480850ac3d16c62ee2abfe410c4e00d16f70b.zip
code style
-rw-r--r--cxx/include/aesxx/aes.hpp48
-rw-r--r--cxx/include/aesxx/box.hpp24
-rw-r--r--cxx/include/aesxx/error.hpp35
-rw-r--r--include/aes/error.h2
-rw-r--r--src/error.c4
-rw-r--r--utils/decrypt_block.cpp4
-rw-r--r--utils/decrypt_bmp.cpp4
-rw-r--r--utils/decrypt_file.cpp4
-rw-r--r--utils/encrypt_block.cpp4
-rw-r--r--utils/encrypt_bmp.cpp4
-rw-r--r--utils/encrypt_file.cpp4
11 files changed, 73 insertions, 64 deletions
diff --git a/cxx/include/aesxx/aes.hpp b/cxx/include/aesxx/aes.hpp
index c85bd26..d1f68d2 100644
--- a/cxx/include/aesxx/aes.hpp
+++ b/cxx/include/aesxx/aes.hpp
@@ -42,37 +42,37 @@ namespace aes
template <>
void from_string<AES_AES128>(aes128::Block& dest, const char* src)
{
- aes_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES128>(const aes128::Block& src)
{
AES_AES128_BlockString str;
- aes_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
std::string to_matrix_string<AES_AES128>(const aes128::Block& src)
{
AES_AES128_BlockMatrixString str;
- aes_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
void from_string<AES_AES128>(aes128::Key& dest, const char* src)
{
- aes_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES128>(const aes128::Key& src)
{
AES_AES128_KeyString str;
- aes_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
@@ -127,37 +127,37 @@ namespace aes
template <>
void from_string<AES_AES192>(aes192::Block& dest, const char* src)
{
- aes_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES192>(const aes192::Block& src)
{
AES_AES192_BlockString str;
- aes_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
std::string to_matrix_string<AES_AES192>(const aes192::Block& src)
{
AES_AES192_BlockMatrixString str;
- aes_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
void from_string<AES_AES192>(aes192::Key& dest, const char* src)
{
- aes_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES192>(const aes192::Key& src)
{
AES_AES192_KeyString str;
- aes_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
@@ -212,37 +212,37 @@ namespace aes
template <>
void from_string<AES_AES256>(aes256::Block& dest, const char* src)
{
- aes_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES256>(const aes256::Block& src)
{
AES_AES256_BlockString str;
- aes_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
std::string to_matrix_string<AES_AES256>(const aes256::Block& src)
{
AES_AES256_BlockMatrixString str;
- aes_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
void from_string<AES_AES256>(aes256::Key& dest, const char* src)
{
- aes_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor());
+ aes_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor{});
}
template <>
std::string to_string<AES_AES256>(const aes256::Key& src)
{
AES_AES256_KeyString str;
- aes_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor());
- return { str.str };
+ aes_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor{});
+ return {str.str};
}
template <>
diff --git a/cxx/include/aesxx/box.hpp b/cxx/include/aesxx/box.hpp
index ced4c28..3d9529b 100644
--- a/cxx/include/aesxx/box.hpp
+++ b/cxx/include/aesxx/box.hpp
@@ -30,7 +30,7 @@ namespace aes
{
AES_BoxKeyString str;
aes_box_format_key(
- &str, algorithm, &src, ErrorDetailsThrowsInDestructor());
+ &str, algorithm, &src, ErrorDetailsThrowsInDestructor{});
return reinterpret_cast<const char*>(&str);
}
@@ -38,7 +38,7 @@ namespace aes
{
AES_BoxBlockString str;
aes_box_format_block(
- &str, algorithm, &src, ErrorDetailsThrowsInDestructor());
+ &str, algorithm, &src, ErrorDetailsThrowsInDestructor{});
return reinterpret_cast<const char*>(&str);
}
@@ -48,7 +48,7 @@ namespace aes
const char* src)
{
aes_box_parse_block(&dest, algorithm, src,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
static void parse_block(
@@ -65,7 +65,7 @@ namespace aes
const char* src)
{
aes_box_parse_key(&dest, algorithm, src,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
static void parse_key(
@@ -81,7 +81,7 @@ namespace aes
, mode(AES_ECB)
{
aes_box_init(&impl, algorithm, &key, mode, nullptr,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
Box(Algorithm algorithm, const Key& key, Mode mode, const Block& iv)
@@ -89,21 +89,21 @@ namespace aes
, mode(mode)
{
aes_box_init(&impl, algorithm, &key, mode, &iv,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
void encrypt_block(const Block& plaintext, Block& ciphertext)
{
aes_box_encrypt_block(
&impl, &plaintext, &ciphertext,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
void decrypt_block(const Block& ciphertext, Block& plaintext)
{
aes_box_decrypt_block(
&impl, &ciphertext, &plaintext,
- ErrorDetailsThrowsInDestructor());
+ ErrorDetailsThrowsInDestructor{});
}
std::vector<unsigned char> encrypt_buffer(
@@ -118,7 +118,7 @@ namespace aes
src_size,
nullptr,
&dest_size,
- aes::ErrorDetailsThrowsInDestructor());
+ aes::ErrorDetailsThrowsInDestructor{});
std::vector<unsigned char> dest_buf;
dest_buf.resize(dest_size);
@@ -129,7 +129,7 @@ namespace aes
src_size,
dest_buf.data(),
&dest_size,
- aes::ErrorDetailsThrowsInDestructor());
+ aes::ErrorDetailsThrowsInDestructor{});
dest_buf.resize(dest_size);
return dest_buf;
@@ -147,7 +147,7 @@ namespace aes
src_size,
nullptr,
&dest_size,
- aes::ErrorDetailsThrowsInDestructor());
+ aes::ErrorDetailsThrowsInDestructor{});
std::vector<unsigned char> dest_buf;
dest_buf.resize(dest_size);
@@ -158,7 +158,7 @@ namespace aes
src_size,
dest_buf.data(),
&dest_size,
- aes::ErrorDetailsThrowsInDestructor());
+ aes::ErrorDetailsThrowsInDestructor{});
dest_buf.resize(dest_size);
return dest_buf;
diff --git a/cxx/include/aesxx/error.hpp b/cxx/include/aesxx/error.hpp
index 384a637..21f65d5 100644
--- a/cxx/include/aesxx/error.hpp
+++ b/cxx/include/aesxx/error.hpp
@@ -27,15 +27,20 @@ namespace aes
{
public:
Error(const AES_ErrorDetails& err_details)
- : std::runtime_error(format_error_message(err_details))
+ : std::runtime_error{format_error_message(err_details)}
{
- copy_call_stack(err_details);
+ fill_call_stack(err_details);
}
- void for_each_in_call_stack(const std::function<void (void*, const std::string&)>& callback) const
+ void for_each_addr(
+ const std::function<void (const void*, const std::string&)>& callback) const
{
aux::CallStackFormatter formatter;
- std::for_each(call_stack, call_stack + call_stack_size, [&formatter, &callback] (void* addr)
+
+ std::for_each(
+ call_stack,
+ call_stack + call_stack_len,
+ [&formatter, &callback] (const void* addr)
{
callback(addr, formatter.format_address(addr));
});
@@ -47,24 +52,28 @@ namespace aes
std::vector<char> buf;
buf.resize(aes_format_error(&err_details, NULL, 0));
aes_format_error(&err_details, buf.data(), buf.size());
- return { buf.begin(), buf.end() };
+ return {buf.begin(), buf.end()};
}
- void copy_call_stack(const AES_ErrorDetails& err_details)
+ void fill_call_stack(const AES_ErrorDetails& err_details)
{
- call_stack_size = err_details.call_stack_size;
- std::memcpy(call_stack, err_details.call_stack, call_stack_size * sizeof(void*));
+ call_stack_len = err_details.call_stack_len;
+
+ if (call_stack_len > AES_MAX_CALL_STACK_LENGTH)
+ call_stack_len = AES_MAX_CALL_STACK_LENGTH;
+
+ std::memcpy(call_stack, err_details.call_stack, call_stack_len * sizeof(const void*));
}
- void* call_stack[AES_MAX_CALL_STACK_LENGTH];
- std::size_t call_stack_size;
+ std::size_t call_stack_len = 0;
+ const void* call_stack[AES_MAX_CALL_STACK_LENGTH] = {nullptr};
};
- std::ostream& operator<<(std::ostream& os, const Error& e)
+ std::ostream& operator<<(std::ostream& os, const Error& error)
{
- os << "AES error: " << e.what() << '\n';
+ os << "AES error: " << error.what() << '\n';
os << "Call stack:\n";
- e.for_each_in_call_stack([&os] (void* addr, const std::string& name)
+ error.for_each_addr([&os] (const void* addr, const std::string& name)
{
os << '\t' << addr << ' ' << name << '\n';
});
diff --git a/include/aes/error.h b/include/aes/error.h
index 532edeb..e094f8a 100644
--- a/include/aes/error.h
+++ b/include/aes/error.h
@@ -51,7 +51,7 @@ typedef struct
params;
void* call_stack[AES_MAX_CALL_STACK_LENGTH];
- size_t call_stack_size;
+ size_t call_stack_len;
}
AES_ErrorDetails;
diff --git a/src/error.c b/src/error.c
index 3bf3ed2..fefe7a2 100644
--- a/src/error.c
+++ b/src/error.c
@@ -155,13 +155,13 @@ size_t aes_format_error(
static void aes_collect_call_stack(AES_ErrorDetails* err_details)
{
- err_details->call_stack_size = CaptureStackBackTrace(
+ err_details->call_stack_len = CaptureStackBackTrace(
1, AES_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL);
}
#else
static void aes_collect_call_stack(AES_ErrorDetails* err_details)
{
- err_details->call_stack_size = 0;
+ err_details->call_stack_len = 0;
}
#endif
diff --git a/utils/decrypt_block.cpp b/utils/decrypt_block.cpp
index 8c388c1..9e53d2b 100644
--- a/utils/decrypt_block.cpp
+++ b/utils/decrypt_block.cpp
@@ -148,13 +148,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, input.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
decrypt_using_particular_box(box, input.get_input_block_strings());
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
decrypt_using_particular_box(box, input.get_input_block_strings());
}
}
diff --git a/utils/decrypt_bmp.cpp b/utils/decrypt_bmp.cpp
index 1d287d2..17a64dd 100644
--- a/utils/decrypt_bmp.cpp
+++ b/utils/decrypt_bmp.cpp
@@ -46,13 +46,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
decrypt_bmp(box, ciphertext_path, plaintext_path);
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
decrypt_bmp(box, ciphertext_path, plaintext_path);
}
}
diff --git a/utils/decrypt_file.cpp b/utils/decrypt_file.cpp
index 3bbbb06..75f8fb8 100644
--- a/utils/decrypt_file.cpp
+++ b/utils/decrypt_file.cpp
@@ -43,13 +43,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
decrypt_file(box, ciphertext_path, plaintext_path);
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
decrypt_file(box, ciphertext_path, plaintext_path);
}
}
diff --git a/utils/encrypt_block.cpp b/utils/encrypt_block.cpp
index b51d59c..714dab7 100644
--- a/utils/encrypt_block.cpp
+++ b/utils/encrypt_block.cpp
@@ -148,13 +148,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, input.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
encrypt_using_particular_box(box, input.get_input_block_strings());
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
encrypt_using_particular_box(box, input.get_input_block_strings());
}
}
diff --git a/utils/encrypt_bmp.cpp b/utils/encrypt_bmp.cpp
index c28dbf2..ac6cb92 100644
--- a/utils/encrypt_bmp.cpp
+++ b/utils/encrypt_bmp.cpp
@@ -44,13 +44,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
encrypt_bmp(box, plaintext_path, ciphertext_path);
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
encrypt_bmp(box, plaintext_path, ciphertext_path);
}
}
diff --git a/utils/encrypt_file.cpp b/utils/encrypt_file.cpp
index 721b735..9a4ee5c 100644
--- a/utils/encrypt_file.cpp
+++ b/utils/encrypt_file.cpp
@@ -43,13 +43,13 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
- aes::Box box{ algorithm, key, mode, iv };
+ aes::Box box{algorithm, key, mode, iv};
encrypt_file(box, plaintext_path, ciphertext_path);
}
else
{
- aes::Box box{ algorithm, key };
+ aes::Box box{algorithm, key};
encrypt_file(box, plaintext_path, ciphertext_path);
}
}