def _generate_hashes(self):
if self._buffer is None:
raise Exception('No buffer provided, nothing to do')
algos = list(hashlib.algorithms)
for a in algorithm.__subclasses__():
algos.append(a.__name__)
for module in algos:
"""To support validation within each algorithm's
module, we wrap an existing implementation
and name it with the 'hashdd_' prefix to avoid conflicts.
We're not going to strip this prefix until the very last moment
as common hashes like md5 may be used in a variety of places
"""
if self._algorithms is not None and module not in self._algorithms:
# Skip modules that are not expressly enabled
continue
if module.startswith('hashdd_'):
m = getattr(hashlib, module)
if m.prefilter(self._buffer):
setattr(self, module[7:], m(self._buffer).hexdigest())
评论列表
文章目录