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.

Module contents

Types

TypeKindDescription
AlgorithmrecordImmutable algorithm metadata and a factory for independent digest contexts.
DigestinterfaceAn owned incremental digest, consumed by either finalization overload.

Functions

FunctionKindDescription
algorithmfunctionRequires an available algorithm descriptor.
algorithmsfunctionLists canonical available names in ascending order.
createfunctionCreates fresh incremental digest state.
digestfunctionComputes one raw digest.
hexDigestfunctionComputes one lowercase hexadecimal digest.
lookupfunctionLooks up an algorithm without constructing mutable provider state.

Types#

Algorithmrecord#

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#
create: function create(self): Digest

Creates independent owned state for this algorithm.

Arguments
NameTypeDescription
selfany
Returns
TypeDescription
Digest

the unfinished digest context

Fields

name#
name: string

Canonical service and algorithm name.

digestSize#
digestSize: integer

Number of output bytes, available before creating mutable state.

Digestinterface#

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#
close: nosuspend function(takes self: Digest): nil

Consumes an unfinished context and releases provider state without suspension.

Arguments
NameTypeDescription
takes selfDigest
Returns
TypeDescription
nil
algorithm#
algorithm: function(self: Digest): string

Returns the canonical algorithm name retained at creation.

Arguments
NameTypeDescription
selfDigest
Returns
TypeDescription
string
digestSize#
digestSize: function(self: Digest): integer

Returns the fixed output size in bytes.

Arguments
NameTypeDescription
selfDigest
Returns
TypeDescription
integer
update#
update: function(exclusive self: Digest, bytes: string): nil

Processes raw bytes without retaining a borrowed input.

Arguments
NameTypeDescription
exclusive selfDigest
bytesstring
Returns
TypeDescription
nil
updateSpan#
updateSpan: function(exclusive self: Digest, borrows bytes: span.ByteSpan): nil

Processes a borrowed byte view without retaining it.

Arguments
NameTypeDescription
exclusive selfDigest
borrows bytesspan.ByteSpan
Returns
TypeDescription
nil
digest#
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
NameTypeDescription
takes selfDigest
exclusive destinationspan.ByteWriteSpan
Returns
TypeDescription
integer
hexDigest#
hexDigest: function(takes self: Digest): string

Consumes this context and returns lowercase hexadecimal, always closing state.

Arguments
NameTypeDescription
takes selfDigest
Returns
TypeDescription
string

Functions#

algorithmfunction#

function algorithm(name: string): Algorithm

Requires an available algorithm descriptor.

Arguments

NameTypeDescription
namestring

the canonical algorithm name

Returns

TypeDescription
Algorithm

the selected descriptor

Raises

  • when the algorithm is unavailable or its provider is invalid

algorithmsfunction#

function algorithms(): {string}

Lists canonical available names in ascending order.

Returns

TypeDescription
{string}

the available canonical names

createfunction#

function create(name: string): Digest

Creates fresh incremental digest state.

Arguments

NameTypeDescription
namestring

the canonical algorithm name

Returns

TypeDescription
Digest

an owned unfinished digest

Raises

  • when the algorithm is unavailable or cannot be initialized

digestfunction#

function digest(name: string, bytes: string): string

Computes one raw digest.

Arguments

NameTypeDescription
namestring

the canonical algorithm name

bytesstring

the message bytes

Returns

TypeDescription
string

the raw fixed-size digest bytes

hexDigestfunction#

function hexDigest(name: string, bytes: string): string

Computes one lowercase hexadecimal digest.

Arguments

NameTypeDescription
namestring

the canonical algorithm name

bytesstring

the message bytes

Returns

TypeDescription
string

the lowercase hexadecimal digest

lookupfunction#

function lookup(name: string): Algorithm?

Looks up an algorithm without constructing mutable provider state.

Arguments

NameTypeDescription
namestring

the canonical algorithm name

Returns

TypeDescription
Algorithm?

the descriptor, or nil when unavailable