From edba600ece2e0192e70a9cbe4861e9bcf10f3865 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 15 Sep 2014 14:23:09 +0200 Subject: Implement get-proof-by-hash. --- src/v1.erl | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/v1.erl') diff --git a/src/v1.erl b/src/v1.erl index c60df1d..2ca7726 100644 --- a/src/v1.erl +++ b/src/v1.erl @@ -50,15 +50,15 @@ deliver(SessionID, binary_to_list(jiffy:encode({R}))). 'get-sth-consistency'(SessionID, _Env, Input) -> - %% TODO: move argument parsing to a generic function R = case lists:sort(httpd:parse_query(Input)) of [{"first", FirstInput}, {"second", SecondInput}] -> {First, _} = string:to_integer(FirstInput), {Second, _} = string:to_integer(SecondInput), case lists:member(error, [First, Second]) of true -> - html("get-sth-consistency: bad input:", [First, Second]); - _ -> + html("get-sth-consistency: bad input:", + [FirstInput, SecondInput]); + false -> binary_to_list( jiffy:encode( [base64:encode(X) || @@ -67,21 +67,42 @@ _ -> html("get-sth-consistency: bad input:", Input) end, deliver(SessionID, R). -'get-proof-by-hash'(SessionID, _Env, _Input) -> - niy(SessionID). + +'get-proof-by-hash'(SessionID, _Env, Input) -> + R = case lists:sort(httpd:parse_query(Input)) of + [{"hash", HashInput}, {"tree_size", TreeSizeInput}] -> + Hash = case (catch base64:decode(HashInput)) of + {'EXIT', _} -> error; + H -> H + end, + {TreeSize, _} = string:to_integer(TreeSizeInput), + case lists:member(error, [Hash, TreeSize]) of + true -> + html("get-proof-by-hash: bad input:", + [HashInput, TreeSizeInput]); + false -> + binary_to_list( + jiffy:encode( + [base64:encode(X) || + X <- plop:inclusion(Hash, TreeSize)])) + end; + _ -> html("get-sth-proof-by-hash: bad input:", Input) + end, + deliver(SessionID, R). + 'get-entries'(SessionID, _Env, Input) -> - %% TODO: move argument parsing to a generic function R = case lists:sort(httpd:parse_query(Input)) of [{"end", EndInput}, {"start", StartInput}] -> {Start, _} = string:to_integer(StartInput), {End, _} = string:to_integer(EndInput), case lists:member(error, [Start, End]) of true -> html("get-entries: bad input:", [Start, End]); - _ -> encode_entries(plop:get(Start, End)) + false -> encode_entries(plop:get(Start, End)) end; _ -> html("get-entries: bad input:", Input) end, deliver(SessionID, R). + 'get-entry-and-proof'(SessionID, _Env, _Input) -> niy(SessionID). -- cgit v1.1