diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-09-15 14:23:09 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-09-15 14:23:09 +0200 |
commit | edba600ece2e0192e70a9cbe4861e9bcf10f3865 (patch) | |
tree | c01032b2db86f548531ec7c6ae91c7255cc2873a /src | |
parent | a94eff953af5e91a5bc1c3af5da6bfbea01873ca (diff) |
Implement get-proof-by-hash.
Diffstat (limited to 'src')
-rw-r--r-- | src/v1.erl | 35 |
1 files changed, 28 insertions, 7 deletions
@@ -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). |