Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[src/ec_file.erl] Factorization & typos, in sha1sum/1 & md5sum/1 #166

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ec_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,27 @@ try_write_owner(To, #file_info{uid=OwnerId}) ->
try_write_group(To, #file_info{gid=OwnerId}) ->
file:write_file_info(To, #file_info{gid=OwnerId}).

%% @doc return an md5 checksum string or a binary. Same as unix utility of
%% same name.
%% @doc return the MD5 digest of a string or a binary,
%% 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 an sha1sum checksum string or a binary. Same as unix utility of
%% same name.
%% @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) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend naming this something like bin_to_hex for a more idiomatic name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, @ferd; this name is neater.

hex(binary_to_list(Digest)).

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