diff --git a/patch.c b/patch.c index cadfecd94a..e5bfd0db3f 100644 --- a/patch.c +++ b/patch.c @@ -29,9 +29,7 @@ #include #include -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include #include "msg_hash.h" #include "patch.h" @@ -88,12 +86,8 @@ typedef enum patch_error (*patch_func_t)(const uint8_t*, size_t, static uint8_t bps_read(struct bps_data *bps) { uint8_t data = bps->modify_data[bps->modify_offset++]; -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); - bps->modify_checksum = ~stream_backend->stream_crc_calculate( - ~bps->modify_checksum, &data, 1); -#endif + bps->modify_checksum = ~(encoding_crc32( + ~bps->modify_checksum, &data, 1)); return data; } @@ -116,17 +110,11 @@ static uint64_t bps_decode(struct bps_data *bps) static void bps_write(struct bps_data *bps, uint8_t data) { -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); -#endif if (!bps) return; bps->target_data[bps->output_offset++] = data; -#ifdef HAVE_ZLIB - bps->target_checksum = ~stream_backend->stream_crc_calculate(~bps->target_checksum, &data, 1); -#endif + bps->target_checksum = ~(encoding_crc32(~bps->target_checksum, &data, 1)); } static enum patch_error bps_apply_patch( @@ -140,10 +128,6 @@ static enum patch_error bps_apply_patch( struct bps_data bps = {0}; uint32_t modify_source_checksum = 0, modify_target_checksum = 0, modify_modify_checksum = 0, checksum; -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); -#endif if (modify_length < 19) return PATCH_PATCH_TOO_SMALL; @@ -229,13 +213,8 @@ static enum patch_error bps_apply_patch( for (i = 0; i < 32; i += 8) modify_modify_checksum |= bps_read(&bps) << i; -#ifdef HAVE_ZLIB - bps.source_checksum = stream_backend->stream_crc_calculate(0, + bps.source_checksum = encoding_crc32(0, bps.source_data, bps.source_length); -#else - return PATCH_PATCH_CHECKSUM_INVALID; -#endif - bps.target_checksum = ~bps.target_checksum; if (bps.source_checksum != modify_source_checksum) @@ -252,18 +231,11 @@ static enum patch_error bps_apply_patch( static uint8_t ups_patch_read(struct ups_data *data) { -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); -#endif - if (data && data->patch_offset < data->patch_length) { uint8_t n = data->patch_data[data->patch_offset++]; -#ifdef HAVE_ZLIB data->patch_checksum = - ~stream_backend->stream_crc_calculate(~data->patch_checksum, &n, 1); -#endif + ~(encoding_crc32(~data->patch_checksum, &n, 1)); return n; } return 0x00; @@ -271,18 +243,11 @@ static uint8_t ups_patch_read(struct ups_data *data) static uint8_t ups_source_read(struct ups_data *data) { -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); -#endif - if (data && data->source_offset < data->source_length) { uint8_t n = data->source_data[data->source_offset++]; -#ifdef HAVE_ZLIB - data->source_checksum = - ~stream_backend->stream_crc_calculate(~data->source_checksum, &n, 1); -#endif + data->source_checksum = + ~(encoding_crc32(~data->source_checksum, &n, 1)); return n; } return 0x00; @@ -290,18 +255,12 @@ static uint8_t ups_source_read(struct ups_data *data) static void ups_target_write(struct ups_data *data, uint8_t n) { -#ifdef HAVE_ZLIB - const struct file_archive_file_backend *stream_backend = - file_archive_get_zlib_file_backend(); -#endif if (data && data->target_offset < data->target_length) { data->target_data[data->target_offset] = n; -#ifdef HAVE_ZLIB data->target_checksum = - ~stream_backend->stream_crc_calculate(~data->target_checksum, &n, 1); -#endif + ~(encoding_crc32(~data->target_checksum, &n, 1)); } if (data)