diff cutils/treesum.py @ 307:64df94bf4659

treesum: Build a little static database of digest sizes. So older Python versions can read and use treesum files produced by newer Python versions and digest algorithms.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 07 Mar 2025 14:22:22 +0100
parents ebddfdbc3f7a
children 652870b20f9e
line wrap: on
line diff
--- a/cutils/treesum.py	Wed Mar 05 14:05:38 2025 +0100
+++ b/cutils/treesum.py	Fri Mar 07 14:22:22 2025 +0100
@@ -1510,11 +1510,18 @@
         return self._crc32.hexdigest()
 
     def _get_digest_size(self, algo_name):
+        """Get the `digest_size` from algorithm specifier `algo_name`.
+
+        Cache this on the assumption, that algorithms do not change very
+        often. Do this because the `digest_size` can only be given by a
+        digest instance.
+
+        """
         if self._current_algo_name == algo_name:
             return self._current_algo_digest_size
-        h = util.algotag2algotype(algo_name)()
+        sz = util.algotag2digest_size(algo_name)
         self._current_algo_name = algo_name
-        self._current_algo_digest_size = h.digest_size
+        self._current_algo_digest_size = sz
         return self._current_algo_digest_size