# `nupp.digest.spi`
Implementation interfaces for `nupp.digest` algorithm catalogs.
The facade chooses the unique highest priority during module initialization.
Importing this declaration does not load storage or algorithms.
A provider supplies an algorithms map keyed by canonical algorithm name. Each
descriptor's name agrees with its key, and each create returns independent owned
state. The chosen catalog replaces matching built-in algorithms and
may add names; other built-in algorithms remain available. Empty discovery uses
the built-in catalog. Discovery order never selects a provider.
The facade validates and retains descriptors while requiring the module. Lookup,
listing, and context creation then use cached descriptors without SPI resolution.
Provider state processes chunks incrementally and retains neither input nor
output spans. Cleanup consumes state without suspension. Reuse these canonical
State and Algorithm identities, including ownership and borrowing signatures.
Finalization writes exactly digestSize bytes into the caller's output span.
The facade closes state on successful or failed finalization. Standard digest
names retain their standard output sizes. MD5 and SHA-1 support interoperability;
applications requiring collision resistance must choose an appropriate digest.
## Types
### `Algorithm` _interface_
```nupp
interface Algorithm ...
```
Immutable algorithm identity, output metadata, and a factory for fresh state.
#### Members
| Name | Kind | Description |
| --- | --- | --- |
| [`name`](#nupp.digest.spi.Algorithm.name) | field | Canonical algorithm name, matching the catalog map key. |
| [`digestSize`](#nupp.digest.spi.Algorithm.digestSize) | field | Fixed output size in bytes. |
| [`create`](#nupp.digest.spi.Algorithm.create) | method | Creates independent owned state; self is the retained descriptor. |
#### `name` _field_
```nupp
name: string
```
`@readonly`
Canonical algorithm name, matching the catalog map key.
#### `digestSize` _field_
```nupp
digestSize: integer
```
`@readonly`
Fixed output size in bytes.
#### `create` _method_
```nupp
create: function(self: Algorithm): State
```
Creates independent owned state; self is the retained descriptor.
##### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `self` | `Algorithm` | |
##### Returns
| Type | Description |
| --- | --- |
| `State` | |
### `Provider` _interface_
```nupp
interface Provider ...
```
A selectable implementation catalog. Extra descriptor members are permitted.
#### Members
| Name | Kind | Description |
| --- | --- | --- |
| [`priority`](#nupp.digest.spi.Provider.priority) | field | |
| [`algorithms`](#nupp.digest.spi.Provider.algorithms) | field | Canonical names mapped to checked, independent-state factories. |
#### `priority` _field_
```nupp
priority: integer?
```
`@readonly`
#### `algorithms` _field_
```nupp
algorithms: {[string]: Algorithm}
```
`@readonly`
Canonical names mapped to checked, independent-state factories.
### `State` _interface_
```nupp
interface State is nupp.Closeable ...
```
Independent incremental state; close consumes its ownership without suspension.
#### Members
| Name | Kind | Description |
| --- | --- | --- |
| [`close`](#nupp.digest.spi.State.close) | method | Releases all state resources. |
| [`update`](#nupp.digest.spi.State.update) | method | Processes this borrowed chunk without retaining its bytes. |
| [`finish`](#nupp.digest.spi.State.finish) | method | Writes exactly the descriptor's digestSize bytes. |
#### `close` _method_
```nupp
close: @nosuspend function(takes self: State): nil
```
Releases all state resources.
##### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `takes self` | `State` | |
##### Returns
| Type | Description |
| --- | --- |
| `nil` | |
#### `update` _method_
```nupp
update: function(exclusive self: State, borrows bytes: ByteSpan): nil
```
Processes this borrowed chunk without retaining its bytes.
##### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `exclusive self` | `State` | |
| `borrows bytes` | `ByteSpan` | |
##### Returns
| Type | Description |
| --- | --- |
| `nil` | |
#### `finish` _method_
```nupp
finish: function(exclusive self: State, exclusive destination: ByteWriteSpan): nil
```
Writes exactly the descriptor's digestSize bytes. Does not close state;
the owning facade closes it on success and on failure.
##### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `exclusive self` | `State` | |
| `exclusive destination` | `ByteWriteSpan` | |
##### Returns
| Type | Description |
| --- | --- |
| `nil` | |