Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 206:73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 22 Jan 2025 17:55:49 +0100 |
| parents | 63088d3675bb |
| children | 0e8c12ff0f41 |
comparison
equal
deleted
inserted
replaced
| 205:63088d3675bb | 206:73d22943da5a |
|---|---|
| 997 | 997 |
| 998 def _update_crc(self, data): | 998 def _update_crc(self, data): |
| 999 self._crc32 = zlib.crc32(data, self._crc32) | 999 self._crc32 = zlib.crc32(data, self._crc32) |
| 1000 | 1000 |
| 1001 def _hex_crc(self): | 1001 def _hex_crc(self): |
| 1002 return (hex(self._crc32)[2:]).upper() | 1002 return (hex(self._get_crc())[2:]).upper() |
| 1003 | |
| 1004 def _get_crc(self): | |
| 1005 """Get the current CRC always as positive number with the same bit# | |
| 1006 pattern because Python2 yields negative numbers also. | |
| 1007 | |
| 1008 :return: The current CRC value as positive number on all Python | |
| 1009 versions | |
| 1010 :rtype: int | |
| 1011 | |
| 1012 """ | |
| 1013 if util.PY2: | |
| 1014 # Return the bitpattern as unsigned 32-bit number | |
| 1015 return (~self._crc32 ^ 0xFFFFFFFF) | |
| 1016 else: | |
| 1017 return self._crc32 | |
| 1003 | 1018 |
| 1004 def _get_digest_size(self, algo_name): | 1019 def _get_digest_size(self, algo_name): |
| 1005 if self._current_algo_name == algo_name: | 1020 if self._current_algo_name == algo_name: |
| 1006 return self._current_algo_digest_size | 1021 return self._current_algo_digest_size |
| 1007 h = util.algotag2algotype(algo_name)() | 1022 h = util.algotag2algotype(algo_name)() |
