From bbdbbf313f120f5dee841d73b64c408c462cd3ef Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Wed, 20 Dec 2023 23:56:27 +0100 Subject: [PATCH 1/3] Typos, and replaced 'checksum' with 'digest': more consistent with Erlang documentation --- src/ec_file.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ec_file.erl b/src/ec_file.erl index e310336..d3498b8 100644 --- a/src/ec_file.erl +++ b/src/ec_file.erl @@ -139,14 +139,14 @@ 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))). -%% @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) -> From 6781f1ba6a5ba48dc07b4f727d1420199fecebd5 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Wed, 20 Dec 2023 23:58:44 +0100 Subject: [PATCH 2/3] Factorized digest-to-hex transform; used in three functions --- src/ec_file.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ec_file.erl b/src/ec_file.erl index d3498b8..c5bbb91 100644 --- a/src/ec_file.erl +++ b/src/ec_file.erl @@ -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. %%
 %% Example: remove("./tmp_dir", [recursive]).

From fc69b3630cc6a4af074039cf54f21eae4660f2ac Mon Sep 17 00:00:00 2001
From: Ariel Otilibili 
Date: Thu, 21 Dec 2023 08:43:36 +0100
Subject: [PATCH 3/3] turn_digest_into_hex/1 renamed as bin_to_hex/1

---
 src/ec_file.erl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ec_file.erl b/src/ec_file.erl
index c5bbb91..76e10fe 100644
--- a/src/ec_file.erl
+++ b/src/ec_file.erl
@@ -143,22 +143,22 @@ try_write_group(To, #file_info{gid=OwnerId}) ->
 %%      named after the UNIX utility.
 -spec md5sum(string() | binary()) -> string().
 md5sum(Value) ->
-    turn_digest_into_hex(erlang:md5(Value)).
+    bin_to_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) ->
-    turn_digest_into_hex(crypto:sha(Value)).
+    bin_to_hex(crypto:sha(Value)).
 -else.
 -spec sha1sum(string() | binary()) -> string().
 sha1sum(Value) ->
-    turn_digest_into_hex(crypto:hash(sha, Value)).
+    bin_to_hex(crypto:hash(sha, Value)).
 -endif.
 
-turn_digest_into_hex(Digest) ->
-    hex(binary_to_list(Digest)).
+bin_to_hex(Bin) ->
+    hex(binary_to_list(Bin)).
 
 %% @doc delete a file. Use the recursive option for directories.
 %%