@@ -25,10 +25,12 @@ #import "OFArray.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFInflateStream.h" #import "OFInflate64Stream.h" + +#import "crc32.h" #import "OFChecksumFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" @@ -36,12 +38,10 @@ #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFUnsupportedVersionException.h" -#define CRC32_MAGIC 0xEDB88320 - /* * FIXME: Current limitations: * - Split archives are not supported. * - Write support is missing. * - The ZIP has to be a file on the local file system. @@ -114,23 +114,10 @@ *size -= 8; return field; } -static uint32_t -calculateCRC32(uint32_t crc, uint8_t *bytes, size_t length) -{ - for (size_t i = 0; i < length; i++) { - crc ^= bytes[i]; - - for (uint8_t j = 0; j < 8; j++) - crc = (crc >> 1) ^ (CRC32_MAGIC & (~(crc & 1) + 1)); - } - - return crc; -} - static void seekOrThrowInvalidFormat(OFSeekableStream *stream, of_offset_t offset, int whence) { @try { @@ -561,15 +548,15 @@ ret = [_decompressedStream readIntoBuffer: buffer length: min]; _size -= ret; } - _CRC32 = calculateCRC32(_CRC32, buffer, ret); + _CRC32 = of_crc32(_CRC32, buffer, ret); return ret; } - (void)close { _closed = true; } @end