From 4515b324035c1b3969973ebeeeaf96223fe53aa1 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 15 Sep 2014 14:08:50 +0200 Subject: Add inclusion/2. --- src/plop.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plop.erl b/src/plop.erl index f99d45d..bbfb687 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]). +-export([add/1, sth/0, get/2, consistency/2, inclusion/2]). %% API for tests. -export([read_keyfile_rsa/2, read_keyfiles_ec/2]). -export([testing_get_pubkey/0]). @@ -112,6 +112,8 @@ get(Start, End) -> gen_server:call(?MODULE, {get, {Start, End}}). consistency(TreeSizeFirst, TreeSizeSecond) -> gen_server:call(?MODULE, {consistency, {TreeSizeFirst, TreeSizeSecond}}). +inclusion(Hash, TreeSize) -> + gen_server:call(?MODULE, {inclusion, {Hash, TreeSize}}). get_logid() -> gen_server:call(?MODULE, {get, logid}). testing_get_pubkey() -> @@ -148,6 +150,14 @@ handle_call({get, logid}, _From, handle_call({consistency, {First, Second}}, _From, Plop) -> {reply, ht:consistency(First - 1, Second - 1), Plop}; +handle_call({inclusion, {Hash, TreeSize}}, _From, Plop) -> + Proof = case db:find(Hash) of + [] -> []; + {plop, Index, _Hash, _MTL, _SPT} -> + ht:path(Index, TreeSize - 1) + end, + {reply, Proof, Plop}; + handle_call({test, pubkey}, _From, Plop = #state{pubkey = PK}) -> {reply, PK, Plop}. -- cgit v1.1