summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
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.