multiformats.multihash._hashfuns.utils

Utilities for hash function implementation.

Hashfun

class Hashfun(*args, **kwargs)[source]

Bases: Protocol

Protocol for raw hash functions.

@runtime_checkable
class Hashfun(Protocol):
    def __call__(self, data: BytesLike, size: Optional[int] = None) -> bytes:
        ...

repeat_hashfun

repeat_hashfun(hashfun, repeat=1, truncate='end')[source]

Utility function for repeated hashing.

Parameters:
  • hashfun (Hashfun)

  • repeat (int; default = 1)

  • truncate (Literal['end', 'always']; default = 'end')

Return type:

Hashfun

validate_hashfun_args

validate_hashfun_args(data, size, max_digest_size, *, size_required=False, name='')[source]

Utility function to validate the arguments passed to hash functions.

Parameters:
Return type:

None