From 73f21ee770457f93cc9cc7897664721bfe0b8654 Mon Sep 17 00:00:00 2001 From: Low Kian Seong Date: Fri, 16 May 2014 10:38:13 +0800 Subject: [PATCH 1/2] Adding sha1sum method --- src/ec_file.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ec_file.erl b/src/ec_file.erl index 46f14e9..3fe8a93 100644 --- a/src/ec_file.erl +++ b/src/ec_file.erl @@ -21,6 +21,7 @@ remove/1, remove/2, md5sum/1, + sha1sum/1, read/1, write/2, write_term/2 @@ -90,6 +91,12 @@ copy(From, To) -> -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. +-spec sha1sum(string() | binary()) -> string(). +sha1sum(Value) -> + hex(binary_to_list(crypto:hash(sha, Value))). %% @doc delete a file. Use the recursive option for directories. %%
@@ -312,6 +319,9 @@ setup_test() ->
 
 md5sum_test() ->
     ?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
+    
+sha1sum_test() ->
+    ?assertMatch("b6589fc6ab0dc82cf12099d1c2d40ab994e8410c", sha1sum("0")).
 
 file_test() ->
     Dir = insecure_mkdtemp(),

From 3121c892b4fdeec4f6ccc38c764f80d27591ee4b Mon Sep 17 00:00:00 2001
From: Tristan Sloughter 
Date: Sat, 24 May 2014 09:42:57 -0500
Subject: [PATCH 2/2] support r14/15 crypto

---
 rebar.config    | 1 +
 src/ec_file.erl | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/rebar.config b/rebar.config
index 07a123c..3cd89c7 100644
--- a/rebar.config
+++ b/rebar.config
@@ -10,6 +10,7 @@
 %% Compiler Options ============================================================
 {erl_opts,
  [{platform_define, "^[0-9]+", namespaced_types},
+  {platform_define, "^R1[4|5]", deprecated_crypto},
   debug_info,
   warnings_as_errors]}.
 
diff --git a/src/ec_file.erl b/src/ec_file.erl
index 3fe8a93..1885bde 100644
--- a/src/ec_file.erl
+++ b/src/ec_file.erl
@@ -94,9 +94,15 @@ md5sum(Value) ->
     
 %% @doc return an sha1sum checksum string or a binary. Same as unix utility of
 %%      same name.
+-ifdef(deprecated_crypto).
 -spec sha1sum(string() | binary()) -> string().
-sha1sum(Value) ->
+sha1sum(Value) ->  
+    hex(binary_to_list(crypto:sha(Value))).
+-else.
+-spec sha1sum(string() | binary()) -> string().
+sha1sum(Value) ->  
     hex(binary_to_list(crypto:hash(sha, Value))).
+-endif.
 
 %% @doc delete a file. Use the recursive option for directories.
 %%