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 46f14e9..1885bde 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,18 @@ 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. +-ifdef(deprecated_crypto). +-spec sha1sum(string() | binary()) -> string(). +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. %%
@@ -312,6 +325,9 @@ setup_test() ->
 
 md5sum_test() ->
     ?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
+    
+sha1sum_test() ->
+    ?assertMatch("b6589fc6ab0dc82cf12099d1c2d40ab994e8410c", sha1sum("0")).
 
 file_test() ->
     Dir = insecure_mkdtemp(),