hashes#

Made hashlib more user friendly.

Usage:

>>> from fixa.hashes import hashes
>>> print(hashes.of_bytes(b"hello"))
b1fec41621e338896e2d26f232a6b006

>>> print(hashes.of_str("world"))
78e731027d8fd50ed642340b7c9a63b3

>>> print(hashes.of_file("hashes.py"))
4cddcb5562cbff652b0e4c8a0300337a

Ref:

class aws_ops_alpha.vendor.hashes.HashAlgoEnum(value)[source]#

An enumeration.

class aws_ops_alpha.vendor.hashes.Hashes(algo: HashAlgoEnum = HashAlgoEnum.md5, hexdigest: bool = True)[source]#

A hashlib wrapper class allow you to use one line to do hash as you wish.

use_md5() Hashes[source]#

Use md5 hash algorithm.

use_sha1() Hashes[source]#

Use sha1 hash algorithm.

use_sha224() Hashes[source]#

Use sha224 hash algorithm.

use_sha256() Hashes[source]#

Use sha256 hash algorithm.

use_sha384() Hashes[source]#

Use sha384 hash algorithm.

use_sha512() Hashes[source]#

Use sha512 hash algorithm.

use_hexdigesst() Hashes[source]#

Return hash in hex string.

use_bytesdigest() Hashes[source]#

Return hash in bytes.

of_str(s: str, algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) Union[str, bytes][source]#

Return hash value of a string.

of_bytes(b: bytes, algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) Union[str, bytes][source]#

Return hash value of a bytes.

of_str_or_bytes(s_or_b: Union[bytes, str], algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) Union[str, bytes][source]#

Return hash value of a bytes or string.

of_file(abspath: Union[str, Path, Any], nbytes: int = 0, chunk_size: int = 1024, algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) Union[str, bytes][source]#

Return hash value of a file, or only a piece of a file

of_folder(abspath: Union[str, Path, Any], algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) str[source]#

Return hash value of a folder. It is based on the concatenation of the hash values of all files in the folder. The order of the files are sorted by their paths.

of_paths(paths: List[Union[str, Path, Any]], algo: Optional[HashAlgoEnum] = None, hexdigest: Optional[bool] = None) str[source]#

Return hash value of a list of paths. It is based on the concatenation of the hash values of all files and folders.