hash

Hash computation utilities (MD5, SHA1, SHA256, SHA512).

Module Contents

Functions

__compute_hash(→ str)

Compute hash of a file.

md5(→ str)

Compute md5 hexadecimal digest of a file.

sha1(→ str)

Compute sha1 hexadecimal digest of a file.

sha256(→ str)

Compute sha256 hexadecimal digest of a file.

sha512(→ str)

Compute sha512 hexadecimal digest of a file.

exception hash.HashError(message: str | list[str], origin: str | None = None)

Bases: e3.error.E3Error

Exception raised for hash computation errors.

hash.__compute_hash(path: os.PathLike[str] | str, kind: Literal[md5, sha1, sha256, sha512]) str

Compute hash of a file.

Parameters:
  • path – path to a file

  • kind – hash algorithm to use

hash.md5(path: os.PathLike[str] | str) str

Compute md5 hexadecimal digest of a file.

Parameters:

path – path to a file

Returns:

the hash of the file content

Raises:

HashError – in case of error

hash.sha1(path: os.PathLike[str] | str) str

Compute sha1 hexadecimal digest of a file.

Parameters:

path (str) – path to a file

Returns:

the hash of the file content

Raises:

HashError – in case of error

hash.sha256(path: os.PathLike[str] | str) str

Compute sha256 hexadecimal digest of a file.

Parameters:

path (str) – path to a file

Returns:

the hash of the file content

Raises:

HashError – in case of error

hash.sha512(path: os.PathLike[str] | str) str

Compute sha512 hexadecimal digest of a file.

Parameters:

path (str) – path to a file

Returns:

the hash of the file content

Raises:

HashError – in case of error