nupp.mac
Keyed message authentication. Keys are raw bytes. HMAC-SHA256 is built in; setup selects a typed catalog through nupp.runtime.services.mac before this module loads. Algorithm lookup and state creation use retained descriptors.
Module contents
Types
| Type | Kind | Description |
|---|---|---|
Algorithm | record | Immutable MAC metadata and a keyed context factory. |
Mac | interface | An owned keyed context with consuming digest finalization. |
Functions
| Function | Kind | Description |
|---|---|---|
algorithm | function | Requires an available MAC descriptor. |
algorithms | function | Lists available canonical MAC names in ascending order. |
create | function | Creates independent owned state initialized with a key. |
digest | function | Computes a raw message authentication code. |
hexDigest | function | Computes a lowercase hexadecimal message authentication code. |
lookup | function | Looks up MAC metadata before initializing a keyed context. |
Types#
Algorithmrecord#
record Algorithm
readonly name: string
readonly digestSize: integer
function create(self, key: string): Mac end
endImmutable MAC metadata and a keyed context factory.
Methods
create#
Creates independent owned state initialized with the raw-byte key.
Arguments
| Name | Type | Description |
|---|---|---|
self | any | |
key | string |
Returns
| Type | Description |
|---|---|
Mac |
Fields
Macinterface#
affine interface Mac is nupp.Closeable
terminal close: 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
endAn owned keyed context with consuming digest finalization.
Methods
close#
Consumes an unfinished context and releases provider state without suspension.
Arguments
| Name | Type | Description |
|---|---|---|
takes self | Digest |
Returns
| Type | Description |
|---|---|
nil |
algorithm#
Returns the canonical algorithm name retained at creation.
Arguments
| Name | Type | Description |
|---|---|---|
self | Digest |
Returns
| Type | Description |
|---|---|
string |
digestSize#
digestSize: function(self: Digest): integerReturns the fixed output size in bytes.
Arguments
| Name | Type | Description |
|---|---|---|
self | Digest |
Returns
| Type | Description |
|---|---|
integer |
update#
Processes raw bytes without retaining a borrowed input.
Arguments
| Name | Type | Description |
|---|---|---|
exclusive self | Digest | |
bytes | string |
Returns
| Type | Description |
|---|---|
nil |
updateSpan#
Processes a borrowed byte view without retaining it.
Arguments
| Name | Type | Description |
|---|---|---|
exclusive self | Digest | |
borrows bytes | span.ByteSpan |
Returns
| Type | Description |
|---|---|
nil |
digest#
digest: function(takes self: Digest): string
& function(takes self: Digest, exclusive destination: span.ByteWriteSpan): integerConsumes 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 |
Functions#
algorithmfunction#
Requires an available MAC descriptor.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical MAC algorithm name |
Returns
| Type | Description |
|---|---|
Algorithm | the selected descriptor |
Raises
when the algorithm is unavailable
algorithmsfunction#
function algorithms(): {string}Lists available canonical MAC names in ascending order.
Returns
| Type | Description |
|---|---|
{string} | the available names |
createfunction#
Creates independent owned state initialized with a key.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical MAC algorithm name |
key | string | the raw-byte secret key |
Returns
| Type | Description |
|---|---|
Mac | an unfinished keyed context |
digestfunction#
Computes a raw message authentication code.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical MAC algorithm name |
key | string | the raw-byte secret key |
bytes | string | the message bytes |
Returns
| Type | Description |
|---|---|
string | the raw fixed-size authentication code |
hexDigestfunction#
Computes a lowercase hexadecimal message authentication code.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical MAC algorithm name |
key | string | the raw-byte secret key |
bytes | string | the message bytes |
Returns
| Type | Description |
|---|---|
string | the lowercase hexadecimal authentication code |
lookupfunction#
Looks up MAC metadata before initializing a keyed context.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | the canonical MAC algorithm name |
Returns
| Type | Description |
|---|---|
Algorithm? | the descriptor, or nil when unavailable |