Add hexhash/2

This commit is contained in:
Paul Oliver
2016-08-06 19:33:06 +12:00
parent c67eb9fae6
commit e963bef653
5 changed files with 30 additions and 2 deletions
+2 -1
View File
@@ -5,7 +5,8 @@
{registered, []},
{applications, [
kernel,
stdlib
stdlib,
hex2bin
]},
{modules, [sha3]},
{env, []}
+8
View File
@@ -2,6 +2,8 @@
-export([hash_init/1, hash_update/2, hash_final/1, hash/2]).
-export([hexhash/2]).
-on_load(init/0).
-type bitlen() :: 224 | 256 | 384 | 512.
@@ -11,6 +13,8 @@
-type digest() :: <<_:224>> | <<_:256>> | <<_:384>> | <<_:512>>.
-export_type([bitlen/0, context/0, digest/0]).
-define(nif_stub, nif_stub_error(?LINE)).
nif_stub_error(Line) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
@@ -55,3 +59,7 @@ hash_final(_Context) ->
hash(_BitLen, _Binary) ->
?nif_stub.
-spec hexhash(bitlen(), binary()) -> binary().
hexhash(Bitlen, Binary) ->
Hash = hash(Bitlen, Binary),
list_to_binary(hex2bin:bin_to_hexstr(Hash)).