Merge pull request #66 from tsloughter/master

Adding sha1sum method with r14/r15 support
This commit is contained in:
Jordan Wilberding 2014-05-24 17:00:06 +02:00
commit c2d67e6f76
2 changed files with 17 additions and 0 deletions

View file

@ -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]}.

View file

@ -21,6 +21,7 @@
remove/1,
remove/2,
md5sum/1,
sha1sum/1,
read/1,
write/2,
write_term/2
@ -91,6 +92,18 @@ copy(From, To) ->
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.
%% <pre>
%% Example: remove("./tmp_dir", [recursive]).
@ -313,6 +326,9 @@ setup_test() ->
md5sum_test() ->
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
sha1sum_test() ->
?assertMatch("b6589fc6ab0dc82cf12099d1c2d40ab994e8410c", sha1sum("0")).
file_test() ->
Dir = insecure_mkdtemp(),
TermFile = filename:join(Dir, "ec_file/dir/file.term"),