aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/check/check.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
commit7d17818cec8597f847b0a2537fde991bbc3d9e96 (patch)
tree9c41502e3eb96f103fe98e13456b382fbba7a292 /src/liblzma/check/check.c
parentUpdate the file format specification draft. The new one is (diff)
downloadxz-7d17818cec8597f847b0a2537fde991bbc3d9e96.tar.xz
Update the code to mostly match the new simpler file format
specification. Simplify things by removing most of the support for known uncompressed size in most places. There are some miscellaneous changes here and there too. The API of liblzma has got many changes and still some more will be done soon. While most of the code has been updated, some things are not fixed (the command line tool will choke with invalid filter chain, if nothing else). Subblock filter is somewhat broken for now. It will be updated once the encoded format of the Subblock filter has been decided.
Diffstat (limited to '')
-rw-r--r--src/liblzma/check/check.c55
1 files changed, 44 insertions, 11 deletions
diff --git a/src/liblzma/check/check.c b/src/liblzma/check/check.c
index ba59af2e..388b57e8 100644
--- a/src/liblzma/check/check.c
+++ b/src/liblzma/check/check.c
@@ -13,8 +13,15 @@
#include "check.h"
-// See the .lzma header format specification section 2.2.2.
-LZMA_API const uint32_t lzma_check_sizes[8] = { 0, 4, 4, 8, 16, 32, 32, 64 };
+// See the .lzma header format specification section 2.1.1.2.
+LZMA_API const uint32_t lzma_check_sizes[LZMA_CHECK_ID_MAX + 1] = {
+ 0,
+ 4, 4, 4,
+ 8, 8, 8,
+ 16, 16, 16,
+ 32, 32, 32,
+ 64, 64, 64
+};
LZMA_API const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1] = {
@@ -27,6 +34,7 @@ LZMA_API const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1] = {
#endif
false, // Reserved
+ false, // Reserved
#ifdef HAVE_CHECK_CRC64
true,
@@ -35,6 +43,10 @@ LZMA_API const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1] = {
#endif
false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
#ifdef HAVE_CHECK_SHA256
true,
@@ -44,6 +56,9 @@ LZMA_API const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1] = {
false, // Reserved
false, // Reserved
+ false, // Reserved
+ false, // Reserved
+ false, // Reserved
};
@@ -58,24 +73,24 @@ lzma_check_init(lzma_check *check, lzma_check_type type)
#ifdef HAVE_CHECK_CRC32
case LZMA_CHECK_CRC32:
- check->crc32 = 0;
+ check->state.crc32 = 0;
break;
#endif
#ifdef HAVE_CHECK_CRC64
case LZMA_CHECK_CRC64:
- check->crc64 = 0;
+ check->state.crc64 = 0;
break;
#endif
#ifdef HAVE_CHECK_SHA256
case LZMA_CHECK_SHA256:
- lzma_sha256_init(&check->sha256);
+ lzma_sha256_init(check);
break;
#endif
default:
- if (type <= LZMA_CHECK_ID_MAX)
+ if ((unsigned)(type) <= LZMA_CHECK_ID_MAX)
ret = LZMA_UNSUPPORTED_CHECK;
else
ret = LZMA_PROG_ERROR;
@@ -93,19 +108,19 @@ lzma_check_update(lzma_check *check, lzma_check_type type,
switch (type) {
#ifdef HAVE_CHECK_CRC32
case LZMA_CHECK_CRC32:
- check->crc32 = lzma_crc32(buf, size, check->crc32);
+ check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
break;
#endif
#ifdef HAVE_CHECK_CRC64
case LZMA_CHECK_CRC64:
- check->crc64 = lzma_crc64(buf, size, check->crc64);
+ check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
break;
#endif
#ifdef HAVE_CHECK_SHA256
case LZMA_CHECK_SHA256:
- lzma_sha256_update(buf, size, &check->sha256);
+ lzma_sha256_update(buf, size, check);
break;
#endif
@@ -120,11 +135,29 @@ lzma_check_update(lzma_check *check, lzma_check_type type,
extern void
lzma_check_finish(lzma_check *check, lzma_check_type type)
{
+ switch (type) {
+#ifdef HAVE_CHECK_CRC32
+ case LZMA_CHECK_CRC32:
+ *(uint32_t *)(check->buffer) = check->state.crc32;
+ break;
+#endif
+
+#ifdef HAVE_CHECK_CRC64
+ case LZMA_CHECK_CRC64:
+ *(uint64_t *)(check->buffer) = check->state.crc64;
+ break;
+#endif
+
#ifdef HAVE_CHECK_SHA256
- if (type == LZMA_CHECK_SHA256)
- lzma_sha256_finish(&check->sha256);
+ case LZMA_CHECK_SHA256:
+ lzma_sha256_finish(check);
+ break;
#endif
+ default:
+ break;
+ }
+
return;
}