# `nupp.digest` Provider-selected fixed-output message digests. `create("sha256")` uses the descriptor retained when this module loads. Setup selects a typed provider catalog before requiring this facade. Its entries override matching built-ins; other built-ins remain available. Descriptor names and sizes must agree with the algorithm. No context operation resolves services. `digest()` returns raw bytes, `digest(destination)` writes into an existing writable byte span, and `hexDigest()` returns lowercase hexadecimal. Each final operation consumes the digest. Dropping an unfinished digest closes its provider context. MD5 and SHA-1 are for legacy interoperability only. ## Types ### `Algorithm` _record_ ```nupp record Algorithm readonly name: string readonly digestSize: integer function create(self): Digest end end ``` Immutable algorithm metadata and a factory for independent digest contexts. #### Methods ##### `create` ```nupp create: function create(self): Digest ``` Creates independent owned state for this algorithm. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `any` | | ###### Returns | Type | Description | | --- | --- | | `Digest` | the unfinished digest context | #### Fields ##### `name` ```nupp name: string ``` Canonical service and algorithm name. ##### `digestSize` ```nupp digestSize: integer ``` Number of output bytes, available before creating mutable state. ### `Digest` _interface_ ```nupp affine interface Digest is nupp.Closeable terminal close: nosuspend function(takes self: Digest): nil algorithm: function(self: Digest): string digestSize: function(self: Digest): integer update: function(exclusive self: Digest, bytes: string): nil updateSpan: function(exclusive self: Digest, borrows bytes: span.ByteSpan): nil digest: function(takes self: Digest): string & function(takes self: Digest, exclusive destination: span.ByteWriteSpan): integer hexDigest: function(takes self: Digest): string end ``` An owned incremental digest, consumed by either finalization overload. #### Methods ##### `close` ```nupp close: nosuspend function(takes self: Digest): nil ``` Consumes an unfinished context and releases provider state without suspension. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `takes self` | `Digest` | | ###### Returns | Type | Description | | --- | --- | | `nil` | | ##### `algorithm` ```nupp algorithm: function(self: Digest): string ``` Returns the canonical algorithm name retained at creation. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `Digest` | | ###### Returns | Type | Description | | --- | --- | | `string` | | ##### `digestSize` ```nupp digestSize: function(self: Digest): integer ``` Returns the fixed output size in bytes. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `Digest` | | ###### Returns | Type | Description | | --- | --- | | `integer` | | ##### `update` ```nupp update: function(exclusive self: Digest, bytes: string): nil ``` Processes raw bytes without retaining a borrowed input. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `exclusive self` | `Digest` | | | `bytes` | `string` | | ###### Returns | Type | Description | | --- | --- | | `nil` | | ##### `updateSpan` ```nupp updateSpan: function(exclusive self: Digest, borrows bytes: span.ByteSpan): nil ``` Processes a borrowed byte view without retaining it. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `exclusive self` | `Digest` | | | `borrows bytes` | `span.ByteSpan` | | ###### Returns | Type | Description | | --- | --- | | `nil` | | ##### `digest` ```nupp digest: function(takes self: Digest): string & function(takes self: Digest, exclusive destination: span.ByteWriteSpan): integer ``` Consumes this context and returns raw bytes, or writes the fixed-size prefix of destination and returns its byte count. Always closes state. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `takes self` | `Digest` | | | `exclusive destination` | `span.ByteWriteSpan` | | ###### Returns | Type | Description | | --- | --- | | `integer` | | ##### `hexDigest` ```nupp hexDigest: function(takes self: Digest): string ``` Consumes this context and returns lowercase hexadecimal, always closing state. ###### Arguments | Name | Type | Description | | --- | --- | --- | | `takes self` | `Digest` | | ###### Returns | Type | Description | | --- | --- | | `string` | | ## Functions ### `algorithm` _function_ ```nupp function algorithm(name: string): Algorithm ``` Requires an available algorithm descriptor. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | the canonical algorithm name | #### Returns | Type | Description | | --- | --- | | `Algorithm` | the selected descriptor | #### Raises - when the algorithm is unavailable or its provider is invalid ### `algorithms` _function_ ```nupp function algorithms(): {string} ``` Lists canonical available names in ascending order. #### Returns | Type | Description | | --- | --- | | `{string}` | the available canonical names | ### `create` _function_ ```nupp function create(name: string): Digest ``` Creates fresh incremental digest state. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | the canonical algorithm name | #### Returns | Type | Description | | --- | --- | | `Digest` | an owned unfinished digest | #### Raises - when the algorithm is unavailable or cannot be initialized ### `digest` _function_ ```nupp function digest(name: string, bytes: string): string ``` Computes one raw digest. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | the canonical algorithm name | | `bytes` | `string` | the message bytes | #### Returns | Type | Description | | --- | --- | | `string` | the raw fixed-size digest bytes | ### `hexDigest` _function_ ```nupp function hexDigest(name: string, bytes: string): string ``` Computes one lowercase hexadecimal digest. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | the canonical algorithm name | | `bytes` | `string` | the message bytes | #### Returns | Type | Description | | --- | --- | | `string` | the lowercase hexadecimal digest | ### `lookup` _function_ ```nupp function lookup(name: string): Algorithm? ``` Looks up an algorithm without constructing mutable provider state. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | the canonical algorithm name | #### Returns | Type | Description | | --- | --- | | `Algorithm?` | the descriptor, or nil when unavailable |