%%%-------------------------------------------------------------------
%%% @doc Endpoint-local utility functions.
%%%-------------------------------------------------------------------
-module(endpoint_util).

-export([set_metadata/0, sha256/1]).

-spec set_metadata() -> ok.
set_metadata() ->
    logger:set_process_metadata(#{domain => [endpoint]}).

-spec sha256(string() | binary()) -> binary().
sha256(Str) when is_list(Str) ->
    sha256(unicode:characters_to_binary(Str));
sha256(Bin) when is_binary(Bin) ->
    HashBin = crypto:hash(sha256, Bin),
    HexStr = lists:flatten([io_lib:format("~2.16.0B", [B]) || B <- binary:bin_to_list(HashBin)]),
    list_to_binary(string:lowercase(HexStr)).
