# HG changeset patch # User Franz Glasner # Date 1737564949 -3600 # Node ID 73d22943da5acb56e06cd2237a0ac4ad3104f18b # Parent 63088d3675bbefc60a7449335751b10e4ed4b826 FIX: CRC-32 validation on Python2.7: normalize to positive numbers diff -r 63088d3675bb -r 73d22943da5a cutils/treesum.py --- a/cutils/treesum.py Wed Jan 22 17:45:37 2025 +0100 +++ b/cutils/treesum.py Wed Jan 22 17:55:49 2025 +0100 @@ -999,7 +999,22 @@ self._crc32 = zlib.crc32(data, self._crc32) def _hex_crc(self): - return (hex(self._crc32)[2:]).upper() + return (hex(self._get_crc())[2:]).upper() + + def _get_crc(self): + """Get the current CRC always as positive number with the same bit# + pattern because Python2 yields negative numbers also. + + :return: The current CRC value as positive number on all Python + versions + :rtype: int + + """ + if util.PY2: + # Return the bitpattern as unsigned 32-bit number + return (~self._crc32 ^ 0xFFFFFFFF) + else: + return self._crc32 def _get_digest_size(self, algo_name): if self._current_algo_name == algo_name: