From b42c52475d6e86f6ae0ed01f502bd0b611974578 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 17 Oct 2016 10:42:02 +0300 Subject: utils: code dedupe --- utils/decrypt_bmp.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'utils/decrypt_bmp.cpp') diff --git a/utils/decrypt_bmp.cpp b/utils/decrypt_bmp.cpp index 4842fbd..1d287d2 100644 --- a/utils/decrypt_bmp.cpp +++ b/utils/decrypt_bmp.cpp @@ -4,6 +4,7 @@ // Distributed under the MIT License. #include "file_cmd_parser.hpp" +#include "helpers/bmp.hpp" #include "helpers/file.hpp" #include @@ -12,12 +13,9 @@ #include -#include - #include #include #include -#include namespace { @@ -26,22 +24,11 @@ namespace const std::string& ciphertext_path, const std::string& plaintext_path) { - const auto ciphertext_buf = file::read_file(ciphertext_path); - - const auto bmp_header = reinterpret_cast(ciphertext_buf.data()); - - const auto header_size = bmp_header->bfOffBits; - const auto cipherpixels = ciphertext_buf.data() + header_size; - const auto cipherpixels_size = ciphertext_buf.size() - header_size; - - const auto pixels = box.decrypt_buffer( - cipherpixels, cipherpixels_size); - - std::vector plaintext_buf(header_size + pixels.size()); - std::memcpy(plaintext_buf.data(), bmp_header, header_size); - std::memcpy(plaintext_buf.data() + header_size, pixels.data(), pixels.size()); - - file::write_file(plaintext_path, plaintext_buf); + bmp::BmpFile bmp{file::read_file(ciphertext_path)}; + bmp.replace_pixels(box.decrypt_buffer( + bmp.get_pixels(), + bmp.get_pixels_size())); + file::write_file(plaintext_path, bmp.get_buffer(), bmp.get_size()); } void decrypt_bmp(const Settings& settings) -- cgit v1.2.3