Skip to content

Commit

Permalink
Factorized digest-to-hex transform; used in three functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ariel-anieli committed Dec 20, 2023
1 parent bbdbbf3 commit 6781f1b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ec_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,23 @@ try_write_group(To, #file_info{gid=OwnerId}) ->
%% named after the UNIX utility.
-spec md5sum(string() | binary()) -> string().
md5sum(Value) ->
hex(binary_to_list(erlang:md5(Value))).
turn_digest_into_hex(erlang:md5(Value)).

%% @doc return the SHA-1 digest of a string or a binary,
%% named after the UNIX utility.
-ifdef(deprecated_crypto).
-spec sha1sum(string() | binary()) -> string().
sha1sum(Value) ->
hex(binary_to_list(crypto:sha(Value))).
turn_digest_into_hex(crypto:sha(Value)).
-else.
-spec sha1sum(string() | binary()) -> string().
sha1sum(Value) ->
hex(binary_to_list(crypto:hash(sha, Value))).
turn_digest_into_hex(crypto:hash(sha, Value)).
-endif.

turn_digest_into_hex(Digest) ->
hex(binary_to_list(Digest)).

%% @doc delete a file. Use the recursive option for directories.
%% <pre>
%% Example: remove("./tmp_dir", [recursive]).
Expand Down

0 comments on commit 6781f1b

Please sign in to comment.