Current section
Files
Jump to
Current section
Files
src/apiculture@default_key.erl
-module(apiculture@default_key).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/apiculture/default_key.gleam").
-export([generate/0, prefixed/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Default structured-secret format implementation.\n"
"\n"
" The v0.3.0 default is `sk_<content>_crc32_<checksum>`: 16 bytes of\n"
" cryptographically secure random content, Base62 encoding, an `sk` prefix,\n"
" `_` separators, and four CRC32 checksum bytes. The checksum detects\n"
" accidental corruption; it is not cryptographic authentication.\n"
).
-file("src/apiculture/default_key.gleam", 14).
?DOC(
" Generate a default format key.\n"
"\n"
" This produces a key in the format: `sk_<base62-random>_crc32_<checksum>`.\n"
).
-spec generate() -> {ok, apiculture@key:key()} |
{error, apiculture@error:error()}.
generate() ->
apiculture@key:new_default().
-file("src/apiculture/default_key.gleam", 24).
?DOC(
" Generate a default format key with the given prefix.\n"
"\n"
" This produces a key in the format:\n"
" `<prefix>_<base62-random>_crc32_<checksum>`.\n"
"\n"
" The prefix should be a short semantic identifier (e.g., \"sk\", \"token\", \"key\").\n"
).
-spec prefixed(binary()) -> {ok, apiculture@key:key()} |
{error, apiculture@error:error()}.
prefixed(Prefix) ->
_pipe = apiculture@key:new_as_config(),
_pipe@1 = apiculture@key:with_prefix(_pipe, Prefix),
apiculture@key:generate(_pipe@1).