From 8b0b0f1f02f7990177e0da89eb471da2ced13f4c Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 19 Apr 2018 21:02:13 -0700 Subject: applypatch: Drop the SHA_CTX parameter in Apply{BSDiff,Image}Patch. As they're accepting the SinkFn callback, it makes more sense to leave the work to their callers. Test: mmma -j bootable/recovery Test: Run recovery_component_test on marlin. Test: No other active user of the two functions. Change-Id: I8d67b38ce037925442296f136b483e0c71983777 --- applypatch/imgpatch.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'applypatch/imgpatch.cpp') diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index 3682d6115..2e4faaadf 100644 --- a/applypatch/imgpatch.cpp +++ b/applypatch/imgpatch.cpp @@ -51,7 +51,7 @@ static inline int32_t Read4(const void *address) { // patched data and stream the deflated data to output. static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_len, const Value& patch, size_t patch_offset, - const char* deflate_header, SinkFn sink, SHA_CTX* ctx) { + const char* deflate_header, SinkFn sink) { size_t expected_target_length = static_cast(Read8(deflate_header + 32)); int level = Read4(deflate_header + 40); int method = Read4(deflate_header + 44); @@ -77,7 +77,7 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ size_t total_written = 0; static constexpr size_t buffer_size = 32768; auto compression_sink = [&strm, &actual_target_length, &expected_target_length, &total_written, - &ret, &ctx, &sink](const uint8_t* data, size_t len) -> size_t { + &ret, &sink](const uint8_t* data, size_t len) -> size_t { // The input patch length for an update never exceeds INT_MAX. strm.avail_in = len; strm.next_in = data; @@ -102,15 +102,13 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ LOG(ERROR) << "Failed to write " << have << " compressed bytes to output."; return 0; } - if (ctx) SHA1_Update(ctx, buffer.data(), have); } while ((strm.avail_in != 0 || strm.avail_out == 0) && ret != Z_STREAM_END); actual_target_length += len; return len; }; - int bspatch_result = - ApplyBSDiffPatch(src_data, src_len, patch, patch_offset, compression_sink, nullptr); + int bspatch_result = ApplyBSDiffPatch(src_data, src_len, patch, patch_offset, compression_sink); deflateEnd(&strm); if (bspatch_result != 0) { @@ -135,11 +133,11 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const unsigned char* patch_data, size_t patch_size, SinkFn sink) { Value patch(VAL_BLOB, std::string(reinterpret_cast(patch_data), patch_size)); - return ApplyImagePatch(old_data, old_size, patch, sink, nullptr, nullptr); + return ApplyImagePatch(old_data, old_size, patch, sink, nullptr); } int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& patch, SinkFn sink, - SHA_CTX* ctx, const Value* bonus_data) { + const Value* bonus_data) { if (patch.data.size() < 12) { printf("patch too short to contain header\n"); return -1; @@ -180,7 +178,7 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& printf("source data too short\n"); return -1; } - if (ApplyBSDiffPatch(old_data + src_start, src_len, patch, patch_offset, sink, ctx) != 0) { + if (ApplyBSDiffPatch(old_data + src_start, src_len, patch, patch_offset, sink) != 0) { printf("Failed to apply bsdiff patch.\n"); return -1; } @@ -198,9 +196,6 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& printf("failed to read chunk %d raw data\n", i); return -1; } - if (ctx) { - SHA1_Update(ctx, patch_header + pos, data_len); - } if (sink(reinterpret_cast(patch_header + pos), data_len) != data_len) { printf("failed to write chunk %d raw data\n", i); return -1; @@ -276,7 +271,7 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& } if (!ApplyBSDiffPatchAndStreamOutput(expanded_source.data(), expanded_len, patch, - patch_offset, deflate_header, sink, ctx)) { + patch_offset, deflate_header, sink)) { LOG(ERROR) << "Fail to apply streaming bspatch."; return -1; } -- cgit v1.2.3