ontocast.util.hash¶
render_bytes_hash(payload, digits=12)
¶
Generate a SHA-256 hash for raw bytes.
Binary inputs (PDFs, office documents) must be hashed directly rather than
decoded to text first: a lossy decode(errors="ignore") discards most of
a binary payload before hashing, so the resulting key rests on whichever
bytes happen to form valid UTF-8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
The bytes to hash. |
required |
digits
|
int | None
|
Number of hex digits to return (default: 12).
Pass |
12
|
Returns:
| Type | Description |
|---|---|
str
|
A hex string hash of the bytes. |
Source code in ontocast/util/hash.py
render_text_hash(text, digits=12)
¶
Generate a SHA-256 hash for the given text.
This is the single hashing entry point for the entire codebase.
All modules that need to derive a hash from text should use this function
instead of calling hashlib directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to hash. |
required |
digits
|
int | None
|
Number of hex digits to return (default: 12).
Pass |
12
|
Returns:
| Type | Description |
|---|---|
str
|
A hex string hash of the text. |