Packages

BLAKE3 bindings for gleam targeting both erlang and javascript.

Current section

Files

Jump to
gblake3 src gblake3.erl
Raw

src/gblake3.erl

-module(gblake3).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gblake3.gleam").
-export([hash/1, hash_to_length/2, hash_string/1, hash_string_to_length/2, keyed_hash/2, keyed_hash_to_length/3, derive_key/2, derive_key_from_strings/2, derive_key_with_length/3]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/gblake3.gleam", 6).
?DOC(" Hashes the given message to a 32 byte array\n").
-spec hash(bitstring()) -> bitstring().
hash(B) ->
'Elixir.B3':hash(B).
-file("src/gblake3.gleam", 11).
?DOC(" Hashes the given message to the provided number of bytes\n").
-spec hash_to_length(bitstring(), integer()) -> bitstring().
hash_to_length(B, L) ->
'Elixir.Gblake3':hash_len(B, L).
-file("src/gblake3.gleam", 17).
?DOC(" Hashes the provided message to a 32 bytes array\n").
-spec hash_string(binary()) -> bitstring().
hash_string(S) ->
_pipe = S,
_pipe@1 = gleam_stdlib:identity(_pipe),
'Elixir.B3':hash(_pipe@1).
-file("src/gblake3.gleam", 22).
?DOC(" Hashes the provided message to the provided number of bytes\n").
-spec hash_string_to_length(binary(), integer()) -> bitstring().
hash_string_to_length(S, L) ->
_pipe = S,
_pipe@1 = gleam_stdlib:identity(_pipe),
'Elixir.Gblake3':hash_len(_pipe@1, L).
-file("src/gblake3.gleam", 32).
?DOC(
" Derives a message hash using the given key as an IV.\n"
" \n"
" Errors if key is not exactly 32 bytes long\n"
).
-spec keyed_hash(bitstring(), bitstring()) -> {ok, bitstring()} | {error, nil}.
keyed_hash(B, K) ->
case begin
_pipe = K,
erlang:byte_size(_pipe)
end of
32 ->
{ok, 'Elixir.B3':keyed_hash(B, K)};
_ ->
{error, nil}
end.
-file("src/gblake3.gleam", 39).
-spec keyed_hash_to_length(bitstring(), bitstring(), integer()) -> {ok,
bitstring()} |
{error, nil}.
keyed_hash_to_length(B, K, L) ->
case begin
_pipe = K,
erlang:byte_size(_pipe)
end of
32 ->
{ok, 'Elixir.Gblake3':keyed_hash_to_length(B, K, L)};
_ ->
{error, nil}
end.
-file("src/gblake3.gleam", 69).
?DOC(
" Derives a 32 byte key from the given key material and context string.\n"
" \n"
" The context string should be globally unique and application specific\n"
" \n"
" Should not be used for passwords since BLAKE3 is not a password hash\n"
).
-spec derive_key(bitstring(), binary()) -> bitstring().
derive_key(Km, Context) ->
'Elixir.B3':derive_key(Km, Context).
-file("src/gblake3.gleam", 79).
?DOC(
" Derives a 32 byte key from the given key material and context string.\n"
" \n"
" The context string should be globally unique and application specific\n"
" \n"
" Should not be used for passwords since BLAKE3 is not a password hash\n"
).
-spec derive_key_from_strings(binary(), binary()) -> bitstring().
derive_key_from_strings(Km, Context) ->
_pipe = Km,
_pipe@1 = gleam_stdlib:identity(_pipe),
'Elixir.B3':derive_key(_pipe@1, Context).
-file("src/gblake3.gleam", 93).
?DOC(
" Derives a key of the provided length from the given key material and context string.\n"
" \n"
" The context string should be globally unique and application specific\n"
" \n"
" Should not be used for passwords since BLAKE3 is not a password hash\n"
).
-spec derive_key_with_length(bitstring(), binary(), integer()) -> bitstring().
derive_key_with_length(Km, Context, L) ->
'Elixir.Gblake3':derive_key_len(Km, Context, L).