Merge pull request #66 from tsloughter/master
Adding sha1sum method with r14/r15 support
This commit is contained in:
commit
c2d67e6f76
2 changed files with 17 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
%% Compiler Options ============================================================
|
%% Compiler Options ============================================================
|
||||||
{erl_opts,
|
{erl_opts,
|
||||||
[{platform_define, "^[0-9]+", namespaced_types},
|
[{platform_define, "^[0-9]+", namespaced_types},
|
||||||
|
{platform_define, "^R1[4|5]", deprecated_crypto},
|
||||||
debug_info,
|
debug_info,
|
||||||
warnings_as_errors]}.
|
warnings_as_errors]}.
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
remove/1,
|
remove/1,
|
||||||
remove/2,
|
remove/2,
|
||||||
md5sum/1,
|
md5sum/1,
|
||||||
|
sha1sum/1,
|
||||||
read/1,
|
read/1,
|
||||||
write/2,
|
write/2,
|
||||||
write_term/2
|
write_term/2
|
||||||
|
@ -90,6 +91,18 @@ copy(From, To) ->
|
||||||
-spec md5sum(string() | binary()) -> string().
|
-spec md5sum(string() | binary()) -> string().
|
||||||
md5sum(Value) ->
|
md5sum(Value) ->
|
||||||
hex(binary_to_list(erlang:md5(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.
|
%% @doc delete a file. Use the recursive option for directories.
|
||||||
%% <pre>
|
%% <pre>
|
||||||
|
@ -312,6 +325,9 @@ setup_test() ->
|
||||||
|
|
||||||
md5sum_test() ->
|
md5sum_test() ->
|
||||||
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
|
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
|
||||||
|
|
||||||
|
sha1sum_test() ->
|
||||||
|
?assertMatch("b6589fc6ab0dc82cf12099d1c2d40ab994e8410c", sha1sum("0")).
|
||||||
|
|
||||||
file_test() ->
|
file_test() ->
|
||||||
Dir = insecure_mkdtemp(),
|
Dir = insecure_mkdtemp(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue