aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/aes128ecb_decrypt_file.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--utils/aes128ecb_decrypt_file.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/utils/aes128ecb_decrypt_file.cpp b/utils/aes128ecb_decrypt_file.cpp
index 33e0515..23545f9 100644
--- a/utils/aes128ecb_decrypt_file.cpp
+++ b/utils/aes128ecb_decrypt_file.cpp
@@ -6,10 +6,13 @@
* See LICENSE.txt for details.
*/
+#include "common.hpp"
+
#include <aesni/all.h>
-#include <cstdio>
+#include <cstdlib>
+#include <exception>
#include <iostream>
#include <fstream>
#include <string>
@@ -51,27 +54,40 @@ int main(int argc, char** argv)
const std::string src_path(argv[2]);
const std::string dest_path(argv[3]);
- const auto src_size = get_file_size(src_path);
+ const auto src_size = static_cast<std::size_t>(get_file_size(src_path));
std::ifstream src_ifs;
src_ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit);
src_ifs.open(src_path, std::ifstream::binary);
std::vector<char> src_buf;
- src_buf.reserve(static_cast<std::vector<char>::size_type>(src_size));
+ src_buf.reserve(src_size);
src_buf.assign(std::istreambuf_iterator<char>(src_ifs),
std::istreambuf_iterator<char>());
aesni_expand_key_schedule128(key, &key_schedule);
aesni_invert_key_schedule128(&key_schedule, &inverted_schedule);
- auto dest_size = aesni_decrypt_buffer_ecb128(
- src_buf.data(), static_cast<std::size_t>(src_size), NULL, &inverted_schedule);
-
- std::vector<char> dest_buf(static_cast<std::vector<char>::size_type>(dest_size));
-
- dest_size = aesni_decrypt_buffer_ecb128(
- src_buf.data(), static_cast<std::size_t>(src_size), dest_buf.data(), &inverted_schedule);
+ std::size_t dest_size;
+
+ aesni_decrypt_buffer_ecb128(
+ src_buf.data(),
+ src_size,
+ NULL,
+ &dest_size,
+ &inverted_schedule,
+ aesni::ErrorDetailsThrowsInDestructor());
+
+ std::vector<char> dest_buf;
+ dest_buf.reserve(dest_size);
+
+ aesni_decrypt_buffer_ecb128(
+ src_buf.data(),
+ src_size,
+ dest_buf.data(),
+ &dest_size,
+ &inverted_schedule,
+ aesni::ErrorDetailsThrowsInDestructor());
std::ofstream dest_ofs;
dest_ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit);