Generating v0.1.0

Source
Generating an identifier into a buffer of your own, from any alphabet and entropy source.

GenerateNanoId

pub func GenerateNanoId(into: var char8[..]) -> ! EntropyError

pub func GenerateNanoId(
    into: var char8[..],
    alphabet: char8[..]
) -> ! NanoIdError

Fills the whole of into with an identifier from the default alphabet, using the operating system's generator. The identifier is as long as into; NanoIdLength characters is the standard length. Each character is one random byte, so a twenty-one-character identifier costs twenty-one bytes of entropy. Reports what the system reported when it could not supply random bytes, leaving into zeroized. An empty into succeeds and requests nothing.

OverloadSummary
pub func GenerateNanoId(into: var char8[..]) -> ! EntropyErrorFills the whole of into with an identifier from the default alphabet, using the operating system's generator.
pub func GenerateNanoId(into: var char8[..], alphabet: char8[..]) -> ! NanoIdErrorFills the whole of into with an identifier drawn from alphabet, using the operating system's generator.

Source

Parameters

NameTypeDescription
intovar char8[..]the destination, filled completely
alphabetchar8[..]between two and 256 distinct ASCII characters

Returns: success when every character was written

GenerateNanoIdFrom

pub func GenerateNanoIdFrom(
    source: &var EntropySource,
    into: var char8[..],
    alphabet: char8[..]
) -> ! NanoIdError

Fills the whole of into with an identifier drawn from alphabet, using random bytes from source. The seam for a test, or for a caller with its own generator: the identifier is exactly as unpredictable as the bytes source supplies, so a deterministic source gives deterministic identifiers. Reports an alphabet failure from ValidateAlphabet before using source, leaving into untouched, and Entropy with what source reported, leaving into zeroized.

Source

Parameters

NameTypeDescription
source&var EntropySourcewhere the random bytes come from
intovar char8[..]the destination, filled completely
alphabetchar8[..]between two and 256 distinct ASCII characters

Returns: success when every character was written