diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-09-19 18:18:40 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-09-19 18:18:40 +0200 |
commit | 4689835ddc5af349ee44d2a095dfab03bd3181a5 (patch) | |
tree | d6542dcb36270edfe0a571256dd08e46c7246a71 | |
parent | b9dfa6adff4fbfd68b7a3d7477f0f410e8620e15 (diff) |
Add get-entry-and-proof and adopt to new plop:inclusion/2 signature.
-rw-r--r-- | src/v1.erl | 44 |
1 files changed, 38 insertions, 6 deletions
@@ -82,17 +82,26 @@ html("get-proof-by-hash: bad input:", [HashInput, TreeSizeInput]); false -> - {Index, Path} = plop:inclusion(Hash, TreeSize), binary_to_list( jiffy:encode( - {[{leaf_index, Index}, - {audit_path, [base64:encode(X) || X <- Path]}]})) + case plop:inclusion(Hash, TreeSize) of + {ok, Index, Path} -> + {[{leaf_index, Index}, + {audit_path, + [base64:encode(X) || X <- Path]}]}; + {notfound, Msg} -> + %% FIXME: http status 400 + {[{success, false}, + {error_message, list_to_binary(Msg)}]} + end)) end; - _ -> html("get-sth-proof-by-hash: bad input:", Input) + _ -> html("get-proof-by-hash: bad input:", Input) end, deliver(SessionID, R). 'get-entries'(SessionID, _Env, Input) -> + %% TODO: Limit the number of returned entreis (i.e. start-end) to + %% something reasonable. R = case lists:sort(httpd:parse_query(Input)) of [{"end", EndInput}, {"start", StartInput}] -> {Start, _} = string:to_integer(StartInput), @@ -105,8 +114,31 @@ end, deliver(SessionID, R). -'get-entry-and-proof'(SessionID, _Env, _Input) -> - niy(SessionID). +'get-entry-and-proof'(SessionID, _Env, Input) -> + R = case lists:sort(httpd:parse_query(Input)) of + [{"leaf_index", IndexInput}, {"tree_size", TreeSizeInput}] -> + {Index, _} = string:to_integer(IndexInput), + {TreeSize, _} = string:to_integer(TreeSizeInput), + case lists:member(error, [Index, TreeSize]) of + true -> html("get-entry-and-proof: bad input:", [fixme]); + false -> + binary_to_list( + jiffy:encode( + case plop:inclusion_and_leaf(Index, TreeSize) of + {ok, Data, Path} -> + {[{leaf_input, + base64:encode(plop:serialise(Data))}, + {extra_data, base64:encode([])}, + {audit_path, + [base64:encode(X) || X <- Path]}]}; + {notfound, Msg} -> + {[{success, false}, + {error_message, list_to_binary(Msg)}]} + end)) + end; + _ -> html("get-entry-and-proof: bad input:", Input) + end, + deliver(SessionID, R). 'get-roots'(SessionID, _Env, _Input) -> R = [{certificates, []}], % NIY. |