diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 03:25:03 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 03:25:03 +0300 |
commit | 35f3497d371a0a05098fcfdbe6e40d91095ef06c (patch) | |
tree | b9bbce2bf6c8b16b1ab837743425c29b4c4e2bf4 /utils/aes128ecb_encrypt_file.cpp | |
parent | add `assert`s (diff) | |
download | aes-tools-35f3497d371a0a05098fcfdbe6e40d91095ef06c.tar.gz aes-tools-35f3497d371a0a05098fcfdbe6e40d91095ef06c.zip |
add error codes & messages to the library
Diffstat (limited to '')
-rw-r--r-- | utils/aes128ecb_encrypt_file.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/utils/aes128ecb_encrypt_file.cpp b/utils/aes128ecb_encrypt_file.cpp index 07c3e91..42e297c 100644 --- a/utils/aes128ecb_encrypt_file.cpp +++ b/utils/aes128ecb_encrypt_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,37 +54,44 @@ 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); - const auto dest_size = aesni_encrypt_buffer_ecb128( + std::size_t dest_size; + + aesni_encrypt_buffer_ecb128( src_buf.data(), - static_cast<std::size_t>(src_size), + src_size, NULL, - &key_schedule); + &dest_size, + &key_schedule, + aesni::ErrorDetailsThrowsInDestructor()); - std::vector<char> dest_buf(static_cast<std::vector<char>::size_type>(dest_size)); + std::vector<char> dest_buf; + dest_buf.reserve(dest_size); aesni_encrypt_buffer_ecb128( src_buf.data(), - static_cast<std::size_t>(src_size), + src_size, dest_buf.data(), - &key_schedule); + &dest_size, + &key_schedule, + aesni::ErrorDetailsThrowsInDestructor()); std::ofstream dest_ofs; dest_ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit); dest_ofs.open(dest_path, std::ofstream::binary); - dest_ofs.write(dest_buf.data(), dest_buf.size()); + dest_ofs.write(dest_buf.data(), dest_size); } catch (const std::exception& e) { |