summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-09-19 18:18:40 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-19 18:18:40 +0200
commit4689835ddc5af349ee44d2a095dfab03bd3181a5 (patch)
treed6542dcb36270edfe0a571256dd08e46c7246a71 /src/v1.erl
parentb9dfa6adff4fbfd68b7a3d7477f0f410e8620e15 (diff)
Add get-entry-and-proof and adopt to new plop:inclusion/2 signature.
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/v1.erl b/src/v1.erl
index dca1402..d6b833b 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -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.