Current section

Files

Jump to
sprocket src sprocket@internal@csrf.erl
Raw

src/sprocket@internal@csrf.erl

-module(sprocket@internal@csrf).
-compile([no_auto_import, nowarn_unused_vars]).
-export([validate/2, generate/0]).
-spec validate(binary(), binary()) -> {ok, nil} | {error, binary()}.
validate(Token1, Token2) ->
case Token1 =:= Token2 of
true ->
{ok, nil};
false ->
{error, <<"Invalid CSRF token"/utf8>>}
end.
-spec process_bytes_r(bitstring()) -> binary().
process_bytes_r(B) ->
case B of
<<>> ->
<<""/utf8>>;
<<A:8, Rest/bitstring>> ->
<<(begin
_pipe = gleam@int:to_base16(A),
gleam@string:lowercase(_pipe)
end)/binary,
(process_bytes_r(Rest))/binary>>
end.
-spec generate() -> binary().
generate() ->
_pipe = gleam@crypto:strong_random_bytes(26),
process_bytes_r(_pipe).