Metadata-Version: 2.4
Name: cs-hashutils
Version: 20250414
Summary: Convenience hashing facilities.
Keywords: python3
Author-email: Cameron Simpson <cs@cskk.id.au>
Description-Content-Type: text/markdown
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Requires-Dist: cs.buffer>=20250111
Requires-Dist: cs.deco>=20250306
Requires-Dist: cs.lex>=20250414
Project-URL: MonoRepo Commits, https://bitbucket.org/cameron_simpson/css/commits/branch/main
Project-URL: Monorepo Git Mirror, https://github.com/cameron-simpson/css
Project-URL: Monorepo Hg/Mercurial Mirror, https://hg.sr.ht/~cameron-simpson/css
Project-URL: Source, https://github.com/cameron-simpson/css/blob/main/lib/python/cs/hashutils.py

Convenience hashing facilities.

*Latest release 20250414*:
Define BLAKE3 if we can import blake3.

Module contents:
- <a name="BaseHashCode"></a>`Class `BaseHashCode(builtins.bytes)`: Base class for hashcodes, subclassed by `SHA1`, `SHA256` et al.

  You can obtain the class for a particular hasher by name, example:

      SHA256 = BaseHashCode.hashclass('sha256')

*`BaseHashCode.__str__(self)`*:
Return `f'{self.hashname}:{self.hex()}'`.

*`BaseHashCode.from_buffer(bfr: cs.buffer.CornuCopyBuffer)`*:
Compute hashcode from the contents of the `CornuCopyBuffer` `bfr`.

*`BaseHashCode.from_data(bs)`*:
Compute hashcode from the data `bs`.

*`BaseHashCode.from_fspath(fspath, **kw)`*:
Compute hashcode from the contents of the file `fspath`.

*`BaseHashCode.from_hashbytes(hashbytes)`*:
Factory function returning a `BaseHashCode` object from the hash bytes.

*`BaseHashCode.from_hashbytes_hex(hashhex: str)`*:
Factory function returning a `BaseHashCode` object
from the hash bytes hex text.

*`BaseHashCode.from_named_hashbytes_hex(hashname, hashhex)`*:
Factory function to return a `BaseHashCode` object
from the hash type name and the hash bytes hex text.

*`BaseHashCode.from_prefixed_hashbytes_hex(hashtext: str)`*:
Factory function returning a `BaseHashCode` object
from the hash bytes hex text prefixed by the hashname.
This is the reverse of `__str__`.

*`BaseHashCode.get_hashfunc(hashname: str)`*:
Fetch the hash function implied by `hashname`.

*`BaseHashCode.hashclass(hashname: str, hashfunc=None, **kw)`*:
Return the class for the hash function named `hashname`.

Parameters:
* `hashname`: the name of the hash function
* `hashfunc`: optional hash function for the class

*`BaseHashCode.hashname`*:
The hash code type name, derived from the class name.

*`BaseHashCode.hex(self) -> str`*:
Return the hashcode bytes transcribes as a hexadecimal ASCII `str`.

*`BaseHashCode.promote(obj)`*:
Promote to a `BaseHashCode` instance.
- <a name="BLAKE3"></a>`Class `BLAKE3(BaseHashCode)`: Hash class for the 'blake3' algorithm.

*`BLAKE3.hashfunc`*
- <a name="MD5"></a>`Class `MD5(BaseHashCode)`: Hash class for the 'md5' algorithm.

*`MD5.hashfunc`*
- <a name="SHA1"></a>`Class `SHA1(BaseHashCode)`: Hash class for the 'sha1' algorithm.

*`SHA1.hashfunc`*
- <a name="SHA224"></a>`Class `SHA224(BaseHashCode)`: Hash class for the 'sha224' algorithm.

*`SHA224.hashfunc`*
- <a name="SHA256"></a>`Class `SHA256(BaseHashCode)`: Hash class for the 'sha256' algorithm.

*`SHA256.hashfunc`*
- <a name="SHA384"></a>`Class `SHA384(BaseHashCode)`: Hash class for the 'sha384' algorithm.

*`SHA384.hashfunc`*
- <a name="SHA512"></a>`Class `SHA512(BaseHashCode)`: Hash class for the 'sha512' algorithm.

*`SHA512.hashfunc`*

# Release Log



*Release 20250414*:
Define BLAKE3 if we can import blake3.

*Release 20241207*:
BaseHashCode.hashclass: raise ValueError from unknown hash function name with greater detail on the underlying failure.

*Release 20240412*:
* BaseHashCode.hashclass(hashname): fall back to looking for blake3 from the blake3 module.
* BaseHashCode: new get_hashfunc(hashname) static method.

*Release 20240316*:
Fixed release upload artifacts.

*Release 20240211*:
Initial PyPI release: BaseHashCode(bytes) and subclasses for various hash algorithms.
