Utils
provide.foundation.crypto.utils
¶
TODO: Add module docstring.
Functions¶
compare_hash
¶
format_hash
¶
Format a hash value for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hash_value
|
str
|
Hash value to format |
required |
group_size
|
int
|
Number of characters per group |
8
|
groups
|
int
|
Number of groups to show (0 for all) |
0
|
separator
|
str
|
Separator between groups |
' '
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted hash string |
Examples:
>>> format_hash("abc123def456", group_size=4, separator="-")
"abc1-23de-f456"
>>> format_hash("abc123def456", group_size=4, groups=2)
"abc1 23de"
Source code in provide/foundation/crypto/utils.py
hash_name
¶
Generate a 64-bit hash of a string for fast lookup.
This is useful for creating numeric identifiers from strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
String to hash |
required |
Returns:
| Type | Description |
|---|---|
int
|
64-bit integer hash |
Source code in provide/foundation/crypto/utils.py
hash_to_int
¶
int_to_hash
¶
Convert an integer to a hex hash string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Integer value |
required |
length
|
int | None
|
Desired length (will pad with zeros) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Hex string representation |
Source code in provide/foundation/crypto/utils.py
is_valid_hash
¶
Check if a string is a valid hash value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hash_value
|
str
|
String to check |
required |
algorithm
|
str | None
|
Optional algorithm to validate length against |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if string appears to be a valid hash |
Source code in provide/foundation/crypto/utils.py
quick_hash
¶
Generate a quick non-cryptographic hash for lookups.
This uses Python's built-in hash function which is fast but not cryptographically secure. Use only for hash tables and caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Data to hash |
required |
Returns:
| Type | Description |
|---|---|
int
|
32-bit hash value |
Source code in provide/foundation/crypto/utils.py
truncate_hash
¶
Truncate a hash for display purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hash_value
|
str
|
Hash value to truncate |
required |
length
|
int
|
Number of characters to keep |
16
|
suffix
|
str
|
Suffix to append |
'...'
|
Returns:
| Type | Description |
|---|---|
str
|
Truncated hash string |
Examples: