def test_adler32(): """ When called with a string, zlib.crc32 should compute its adler 32 checksum and return it as an unsigned 32 bit integer. """ assert rzlib.adler32('') == r_uint(1) assert rzlib.adler32('\0') == r_uint(65537) assert rzlib.adler32('hello, world.') == r_uint(571147447) assert rzlib.adler32('x' * 23) == r_uint(2172062409)
def adler32(space, string, start=rzlib.ADLER32_DEFAULT_START): """ adler32(string[, start]) -- Compute an Adler-32 checksum of string. An optional starting value can be specified. The returned checksum is an integer. """ ustart = r_uint(r_uint32(start)) checksum = rzlib.adler32(string, ustart) return space.newint(checksum)
def adler32(space, string, start=rzlib.ADLER32_DEFAULT_START): """ adler32(string[, start]) -- Compute an Adler-32 checksum of string. An optional starting value can be specified. The returned checksum is an integer. """ ustart = r_uint(start) checksum = rzlib.adler32(string, ustart) # See comments in crc32() for the following line checksum = unsigned_to_signed_32bit(checksum) return space.wrap(checksum)
def adler32(space, string, start=rzlib.ADLER32_DEFAULT_START): """ adler32(string[, start]) -- Compute an Adler-32 checksum of string. An optional starting value can be specified. The returned checksum is an integer. """ ustart = r_uint(start) checksum = rzlib.adler32(string, ustart) # See comments in crc32() for the following line checksum = unsigned_to_signed_32bit(checksum) return space.newint(checksum)
def f(i, check): bytes = "s" * i if check == 1: for j in range(3): stream = rzlib.deflateInit() bytes = rzlib.compress(stream, bytes, rzlib.Z_FINISH) rzlib.deflateEnd(stream) return bytes if check == 2: return str(rzlib.adler32(bytes)) if check == 3: return str(rzlib.crc32(bytes)) return '?'
def test_adler32_start_value(): """ When called with a string and an integer, zlib.adler32 should compute the adler 32 checksum of the string using the integer as the starting value. """ assert rzlib.adler32('', 42) == r_uint(42) assert rzlib.adler32('\0', 42) == r_uint(2752554) assert rzlib.adler32('hello, world.', 42) == r_uint(606078176) assert rzlib.adler32('x' * 23, 42) == r_uint(2233862898) hello = 'hello, ' hellosum = rzlib.adler32(hello) world = 'world.' helloworldsum = rzlib.adler32(world, hellosum) assert helloworldsum == rzlib.adler32(hello + world)
def adler32(array, start): start = rzlib.ADLER32_DEFAULT_START if start is None else start.value string = array.to_str() checksum = rzlib.adler32(string, rffi.r_uint(start)) return Integer(rffi.r_long(checksum))