# `nupp.checksum`
Incremental numeric checksums for accidental corruption detection.
The canonical CRC variants are crc32-ieee, crc32c and crc64-ecma (ECMA-182,
non-reflected, zero initialization and zero final xor). Adler-32 is adler32.
value() is a non-consuming snapshot; protocol code chooses byte order when
serializing the number. These algorithms provide no authentication.
Setup selects a typed catalog through nupp.runtime.services.checksum before this
module loads. Initialization validates and retains algorithm descriptors. An
explicit selection overrides matching built-ins and may add names; unselected
built-ins remain available. Lookup and context operations use the retained catalog
without SPI resolution. Provider names identify implementations, independently
of the algorithm names in their catalogs.
## Types
### `Algorithm` _record_
```nupp
record Algorithm
readonly name: string
readonly width: integer
function create(self): Checksum end
end
```
Checksum metadata and a factory for independent state.
#### Methods
##### `create`
```nupp
create: function create(self): Checksum
```
Creates independent owned state for incremental updates and snapshots.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `self` | `any` | |
###### Returns
| Type | Description |
| --- | --- |
| `Checksum` | |
#### Fields
##### `name`
```nupp
name: string
```
Canonical algorithm name.
##### `width`
```nupp
width: integer
```
Number of meaningful checksum bits, from one through 64.
### `Checksum` _interface_
```nupp
affine interface Checksum is nupp.Closeable
terminal close: nosuspend function(takes self: Checksum): nil
algorithm: function(self: Checksum): string
width: function(self: Checksum): integer
update: function(exclusive self: Checksum, bytes: string): nil
updateSpan: function(exclusive self: Checksum, borrows bytes: span.ByteSpan): nil
value: function(self: Checksum): uint64
end
```
Owned incremental checksum state with non-consuming numeric reads.
#### Methods
##### `close`
```nupp
close: nosuspend function(takes self: Checksum): nil
```
Consumes this context and releases its provider state without suspension.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `takes self` | `Checksum` | |
###### Returns
| Type | Description |
| --- | --- |
| `nil` | |
##### `algorithm`
```nupp
algorithm: function(self: Checksum): string
```
Returns the canonical algorithm name.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `self` | `Checksum` | |
###### Returns
| Type | Description |
| --- | --- |
| `string` | |
##### `width`
```nupp
width: function(self: Checksum): integer
```
Returns the number of meaningful bits in each snapshot.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `self` | `Checksum` | |
###### Returns
| Type | Description |
| --- | --- |
| `integer` | |
##### `update`
```nupp
update: function(exclusive self: Checksum, bytes: string): nil
```
Processes raw bytes while retaining no input views.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `exclusive self` | `Checksum` | |
| `bytes` | `string` | |
###### Returns
| Type | Description |
| --- | --- |
| `nil` | |
##### `updateSpan`
```nupp
updateSpan: function(exclusive self: Checksum, borrows bytes: span.ByteSpan): nil
```
Processes a borrowed byte view without retaining it.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `exclusive self` | `Checksum` | |
| `borrows bytes` | `span.ByteSpan` | |
###### Returns
| Type | Description |
| --- | --- |
| `nil` | |
##### `value`
```nupp
value: function(self: Checksum): uint64
```
Returns an unsigned snapshot without consuming this context.
###### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `self` | `Checksum` | |
###### Returns
| Type | Description |
| --- | --- |
| `uint64` | |
## Functions
### `algorithm` _function_
```nupp
function algorithm(name: string): Algorithm
```
Requires a checksum algorithm descriptor.
#### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | the canonical checksum algorithm name |
#### Returns
| Type | Description |
| --- | --- |
| `Algorithm` | the selected descriptor |
#### Raises
- when the algorithm is unavailable
### `algorithms` _function_
```nupp
function algorithms(): {string}
```
Lists available canonical checksum names in ascending order.
#### Returns
| Type | Description |
| --- | --- |
| `{string}` | the available names |
### `create` _function_
```nupp
function create(name: string): Checksum
```
Creates independent owned checksum state.
#### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | the canonical checksum algorithm name |
#### Returns
| Type | Description |
| --- | --- |
| `Checksum` | an unfinished checksum context |
### `lookup` _function_
```nupp
function lookup(name: string): Algorithm?
```
Finds a checksum algorithm without creating incremental state.
#### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | the canonical checksum algorithm name |
#### Returns
| Type | Description |
| --- | --- |
| `Algorithm?` | the descriptor, or nil when unavailable |
### `value` _function_
```nupp
function value(name: string, bytes: string): uint64
```
Computes a checksum; its bit width belongs to the algorithm descriptor.
#### Arguments
| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | the canonical checksum algorithm name |
| `bytes` | `string` | the message bytes |
#### Returns
| Type | Description |
| --- | --- |
| `uint64` | the unsigned checksum value |