summaryrefslogtreecommitdiff
path: root/src/plop.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-09-19 18:11:37 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-19 18:11:37 +0200
commit209fc7ed4d44f0d613aabdb9b1c59b8621dc1339 (patch)
treebf97a5a7336e7139a3157d7aab7b14ede4a80049 /src/plop.erl
parentc2d7fcc2e1274c148f0ac94436c138022390ffc4 (diff)
Fix crash in inclusion() and add inclusion-and-leaf().
Diffstat (limited to 'src/plop.erl')
-rw-r--r--src/plop.erl28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/plop.erl b/src/plop.erl
index 8277175..abd7d87 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -26,7 +26,7 @@
%% API.
-export([start_link/2, stop/0]).
-export([get_logid/0, serialise/1]).
--export([add/1, sth/0, get/2, consistency/2, inclusion/2]).
+-export([add/1, sth/0, get/2, consistency/2, inclusion/2, inclusion_and_leaf/2]).
%% API for tests.
-export([read_keyfile_rsa/2, read_keyfiles_ec/2]).
-export([testing_get_pubkey/0]).
@@ -113,8 +113,14 @@ get(Start, End) ->
gen_server:call(?MODULE, {get, {Start, End}}).
consistency(TreeSizeFirst, TreeSizeSecond) ->
gen_server:call(?MODULE, {consistency, {TreeSizeFirst, TreeSizeSecond}}).
+-spec inclusion(binary(), non_neg_integer()) ->
+ {ok|notfound, plop_entry() | string()}.
inclusion(Hash, TreeSize) ->
gen_server:call(?MODULE, {inclusion, {Hash, TreeSize}}).
+-spec inclusion_and_leaf(non_neg_integer(), non_neg_integer()) ->
+ {ok|notfound, plop_entry() | string()}.
+inclusion_and_leaf(Index, TreeSize) ->
+ gen_server:call(?MODULE, {inclusion_and_leaf, {Index, TreeSize}}).
get_logid() ->
gen_server:call(?MODULE, {get, logid}).
testing_get_pubkey() ->
@@ -152,12 +158,22 @@ handle_call({consistency, {First, Second}}, _From, Plop) ->
{reply, ht:consistency(First - 1, Second - 1), Plop};
handle_call({inclusion, {Hash, TreeSize}}, _From, Plop) ->
- {Index, Proof} = case db:find(mtlhash, Hash) of
- [] -> [];
- {plop, I, _EntryHash, _MTLHash, _MTL, _SPT} ->
- {I, ht:path(I, TreeSize - 1)}
+ R = case db:find(mtlhash, Hash) of
+ [] ->
+ {notfound, "Unknown hash"}; % FIXME: include Hash
+ {plop, I, _EntryHash, _MTLHash, _MTL, _SPT} ->
+ {ok, I, ht:path(I, TreeSize - 1)}
end,
- {reply, {Index, Proof}, Plop};
+ {reply, R, Plop};
+
+handle_call({inclusion_and_leaf, {Index, TreeSize}}, _From, Plop) ->
+ R = case db:find(index, Index) of
+ [] ->
+ {notfound, "Unknown index"}; % FIXME: include Index
+ {plop, I, _EntryHash, _MTLHash, MTL, _SPT} ->
+ {ok, MTL, ht:path(I, TreeSize - 1)}
+ end,
+ {reply, R, Plop};
handle_call({test, pubkey}, _From,
Plop = #state{pubkey = PK}) ->