Current section

Files

Jump to
touch_grass src touch_grass@cryptography@hash.erl
Raw

src/touch_grass@cryptography@hash.erl

-module(touch_grass@cryptography@hash).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/touch_grass/cryptography/hash.gleam").
-export([decode/1, encode/1]).
-export_type([algorithm/0, input/0]).
-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(" Computes a cryptographic digest of a binary.\n").
-type algorithm() :: sha256.
-type input() :: {input, algorithm(), bitstring()}.
-file("src/touch_grass/cryptography/hash.gleam", 21).
-spec decode_algorithm(eyg@interpreter@value:value(PRC, PRD)) -> {ok,
algorithm()} |
{error, eyg@interpreter@break:reason(PRC, PRD)}.
decode_algorithm(Value) ->
eyg@interpreter@cast:as_varient(
Value,
[{<<"SHA256"/utf8>>,
fun(_capture) ->
eyg@interpreter@cast:as_unit(_capture, sha256)
end}]
).
-file("src/touch_grass/cryptography/hash.gleam", 15).
-spec decode(eyg@interpreter@value:value(PRL, PRM)) -> {ok, input()} |
{error, eyg@interpreter@break:reason(PRL, PRM)}.
decode(Lift) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"algorithm"/utf8>>,
fun decode_algorithm/1,
Lift
),
fun(Algorithm) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"bytes"/utf8>>,
fun eyg@interpreter@cast:as_binary/1,
Lift
),
fun(Bytes) -> {ok, {input, Algorithm, Bytes}} end
)
end
).
-file("src/touch_grass/cryptography/hash.gleam", 25).
-spec encode(bitstring()) -> eyg@interpreter@value:value(any(), any()).
encode(Digest) ->
{binary, Digest}.