Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hashutil.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
""" | """ | ||||
import binascii | import binascii | ||||
import functools | import functools | ||||
import hashlib | import hashlib | ||||
import os | import os | ||||
from io import BytesIO | from io import BytesIO | ||||
from typing import Callable, Dict | |||||
ALGORITHMS = set(['sha1', 'sha256', 'sha1_git', 'blake2s256', 'blake2b512']) | ALGORITHMS = set(['sha1', 'sha256', 'sha1_git', 'blake2s256', 'blake2b512']) | ||||
"""Hashing algorithms supported by this module""" | """Hashing algorithms supported by this module""" | ||||
DEFAULT_ALGORITHMS = set(['sha1', 'sha256', 'sha1_git', 'blake2s256']) | DEFAULT_ALGORITHMS = set(['sha1', 'sha256', 'sha1_git', 'blake2s256']) | ||||
"""Algorithms computed by default when calling the functions from this module. | """Algorithms computed by default when calling the functions from this module. | ||||
Subset of :const:`ALGORITHMS`. | Subset of :const:`ALGORITHMS`. | ||||
""" | """ | ||||
HASH_BLOCK_SIZE = 32768 | HASH_BLOCK_SIZE = 32768 | ||||
"""Block size for streaming hash computations made in this module""" | """Block size for streaming hash computations made in this module""" | ||||
_blake2_hash_cache = {} | _blake2_hash_cache = {} # type: Dict[str, Callable] | ||||
vlorentz: `Dict[str, Callable[[], hashutil.hash]]` | |||||
Done Inline ActionsThere doesn't seem to be a proper public abstract type for the hashes returned by hashlib: they're _hashlib.HASH and I'd rather not use a private module in a type definition. zack: There doesn't seem to be a proper public abstract type for the hashes returned by hashlib… | |||||
class MultiHash: | class MultiHash: | ||||
"""Hashutil class to support multiple hashes computation. | """Hashutil class to support multiple hashes computation. | ||||
Args: | Args: | ||||
hash_names (set): Set of hash algorithms (+ optionally length) | hash_names (set): Set of hash algorithms (+ optionally length) | ||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |
Dict[str, Callable[[], hashutil.hash]]