livery.strongroom._digest¶
livery.strongroom._digest ¶
Digest strings: the name of every object.
A name is <algorithm>:<encoded> in the OCI digest grammar, and the
registry says which algorithms may name bytes. sha256 is required and
is the only entry; the registry exists so a successor is an entry and
never a migration. One address space uses one algorithm, recorded in
its root manifest.
Reach for livery.strongroom.Digest to parse a name and livery.strongroom.digest_of to name bytes.
Classes:
| Name | Description |
|---|---|
Hasher |
What a registry entry's constructor returns: hashlib's shape. |
HashConstructor |
A hashlib-style constructor: optional initial bytes, a hasher back. |
Algorithm |
One registry entry: how an algorithm names bytes. |
Digest |
A parsed digest string. |
Functions:
| Name | Description |
|---|---|
digest_of |
Name data under algorithm. |
digest_stream |
Name the bytes read from stream to its end, without holding them. |
registered |
The registry entry for algorithm, or a refusal naming the registry. |
Attributes:
| Name | Type | Description |
|---|---|---|
SHA256 |
Final
|
The required algorithm, and the only one in the registry. |
ALGORITHMS |
Final[dict[str, Algorithm]]
|
The registry. Only cryptographic, full-length digests may name bytes. |
SHA256
module-attribute
¶
The required algorithm, and the only one in the registry.
ALGORITHMS
module-attribute
¶
The registry. Only cryptographic, full-length digests may name bytes.
Hasher ¶
HashConstructor ¶
Algorithm
dataclass
¶
Algorithm(name: str, encoded: Pattern[str], constructor: HashConstructor)
One registry entry: how an algorithm names bytes.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the algorithm's spelling in a digest string. |
encoded |
Pattern[str]
|
the pattern the encoded part must match in full. |
constructor |
HashConstructor
|
the hashlib constructor that computes it. |
Digest
dataclass
¶
A parsed digest string.
Attributes:
| Name | Type | Description |
|---|---|---|
algorithm |
str
|
the registry entry's name, |
encoded |
str
|
the lowercase hex of the digest. |
Methods:
| Name | Description |
|---|---|
__str__ |
|
parse |
Parse a digest string, refusing anything the registry lacks. |
path_parts
property
¶
The object's path under objects/: algorithm, fan-out, rest.
parse
classmethod
¶
Parse a digest string, refusing anything the registry lacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the |
required |
Returns:
| Type | Description |
|---|---|
Digest
|
The digest. |
Raises:
| Type | Description |
|---|---|
FormatError
|
when the text is not in the OCI grammar, the algorithm is not registered, or the encoded part is not the full lowercase form the algorithm requires. A truncated or uppercase digest is refused so one object has one name. |
Source code in packages/strongroom/src/livery/strongroom/_digest.py
digest_of ¶
Name data under algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
the bytes to name. |
required |
algorithm
|
str
|
a registry entry's name; |
name
|
Returns:
| Type | Description |
|---|---|
Digest
|
The digest. |
Raises:
| Type | Description |
|---|---|
FormatError
|
when the algorithm is not registered. |
Source code in packages/strongroom/src/livery/strongroom/_digest.py
digest_stream ¶
Name the bytes read from stream to its end, without holding them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
IO[bytes]
|
an open binary stream, read in chunks until empty. |
required |
algorithm
|
str
|
a registry entry's name; |
name
|
Returns:
| Type | Description |
|---|---|
Digest
|
The digest. |
Raises:
| Type | Description |
|---|---|
FormatError
|
when the algorithm is not registered. |
Source code in packages/strongroom/src/livery/strongroom/_digest.py
registered ¶
The registry entry for algorithm, or a refusal naming the registry.