From 4ac4412534ca9cb1ec77bfdcd37055fc6c88ca83 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sun, 17 Jun 2012 00:01:34 +0400
Subject: [PATCH 2/2] Rewrote Erlang NIF API routines under MIT license
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
src/skerl.erl | 58 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/src/skerl.erl b/src/skerl.erl
index 1b0d639..ea1572a 100644
--- a/src/skerl.erl
+++ b/src/skerl.erl
@@ -1,18 +1,38 @@
+%% -------------------------------------------------------------------
+%%
+%% Copyright (c) 2012 Peter Lemenkov.
+%%
+%% The MIT License
+%%
+%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%% of this software and associated documentation files (the "Software"), to deal
+%% in the Software without restriction, including without limitation the rights
+%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%% copies of the Software, and to permit persons to whom the Software is
+%% furnished to do so, subject to the following conditions:
+%%
+%% The above copyright notice and this permission notice shall be included in
+%% all copies or substantial portions of the Software.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+%% THE SOFTWARE.
+%%
+%% -------------------------------------------------------------------
+
-module(skerl).
--author('b@fastip.com').
--export([init/0,
- init/1,
- update/2,
- final/1,
- hash/2,
- hexhash/2]).
+% Erlang NIF API
+-export([init/0]).
--on_load(init/0).
+% Skein hash API
+-export([final/1, hash/2, hexhash/2, init/1, update/2]).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
+-on_load(init/0).
init() ->
case code:priv_dir(skerl) of
@@ -24,23 +44,17 @@ init() ->
erlang:load_nif(SoName, 0).
init(_Bits) ->
- "NIF library not loaded".
+ exit("NIF library not loaded").
update(_State, _Data) ->
- "NIF library not loaded".
+ exit("NIF library not loaded").
final(_State) ->
- "NIF library not loaded".
-
+ exit("NIF library not loaded").
+
hexhash(Bits, Data) ->
{ok, Hash} = hash(Bits, Data),
list_to_binary(hex:bin_to_hexstr(Hash)).
--spec hash(non_neg_integer(), binary()) -> {ok, binary()} | {error, atom()}.
hash(_Bits, _Data) ->
- case random:uniform(999999999999) of
- 666 -> {error, fail};
- 667 -> {error, bad_hashlen};
- 668 -> {ok, <<4242/integer>>};
- _ -> exit("NIF library not loaded")
- end.
+ exit("NIF library not loaded").
--
1.7.10.2