summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/v1.erl34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/v1.erl b/src/v1.erl
index 2581804..ad312e7 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -30,15 +30,15 @@ request(get, "ct/v1/get-sth-consistency", Query) ->
{Second, _} = string:to_integer(SecondInput),
case lists:member(error, [First, Second]) of
true ->
- html("get-sth-consistency: bad input:",
- [FirstInput, SecondInput]);
+ err400("get-sth-consistency: bad input:",
+ [FirstInput, SecondInput]);
false ->
success(
{[{consistency,
[base64:encode(X) ||
X <- plop:consistency(First, Second)]}]})
end;
- _ -> html("get-sth-consistency: bad input:", Query)
+ _ -> err400("get-sth-consistency: bad input:", Query)
end;
request(get, "ct/v1/get-proof-by-hash", Query) ->
@@ -51,8 +51,8 @@ request(get, "ct/v1/get-proof-by-hash", Query) ->
{TreeSize, _} = string:to_integer(TreeSizeInput),
case lists:member(error, [Hash, TreeSize]) of
true ->
- html("get-proof-by-hash: bad input:",
- [HashInput, TreeSizeInput]);
+ err400("get-proof-by-hash: bad input:",
+ [HashInput, TreeSizeInput]);
false ->
case plop:inclusion(Hash, TreeSize) of
{ok, Index, Path} ->
@@ -60,10 +60,10 @@ request(get, "ct/v1/get-proof-by-hash", Query) ->
{audit_path,
[base64:encode(X) || X <- Path]}]});
{notfound, Msg} ->
- html("get-proof-by-hash: hash not found", Msg)
+ err400("get-proof-by-hash: hash not found", Msg)
end
end;
- _ -> html("get-proof-by-hash: bad input:", Query)
+ _ -> err400("get-proof-by-hash: bad input:", Query)
end;
request(get, "ct/v1/get-entries", Query) ->
@@ -72,11 +72,11 @@ request(get, "ct/v1/get-entries", Query) ->
{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]);
+ true -> err400("get-entries: bad input:", [Start, End]);
false -> success(
catlfish:entries(Start, min(End, Start + 999)))
end;
- _ -> html("get-entries: bad input:", Query)
+ _ -> err400("get-entries: bad input:", Query)
end;
request(get, "ct/v1/get-entry-and-proof", Query) ->
@@ -86,11 +86,11 @@ request(get, "ct/v1/get-entry-and-proof", Query) ->
{TreeSize, _} = string:to_integer(TreeSizeInput),
case lists:member(error, [Index, TreeSize]) of
true ->
- html("get-entry-and-proof: not integers: ",
- [IndexInput, TreeSizeInput]);
+ err400("get-entry-and-proof: not integers: ",
+ [IndexInput, TreeSizeInput]);
false -> success(catlfish:entry_and_proof(Index, TreeSize))
end;
- _ -> html("get-entry-and-proof: bad input:", Query)
+ _ -> err400("get-entry-and-proof: bad input:", Query)
end;
request(get, "ct/v1/get-roots", _Query) ->
@@ -103,7 +103,7 @@ request(_Method, _Path, _) ->
none.
%% Private functions.
-html(Text, Input) ->
+err400(Text, Input) ->
{400, [{"Content-Type", "text/html"}],
io_lib:format(
"<html><body><p>~n" ++
@@ -125,7 +125,7 @@ internalerror(Text) ->
add_chain(Input, Type) ->
case (catch mochijson2:decode(Input)) of
{error, E} ->
- html("add-chain: bad input:", E);
+ err400("add-chain: bad input:", E);
{struct, [{<<"chain">>, ChainB64List}]} ->
case decode_chain(ChainB64List) of
[LeafCert | CertChain] ->
@@ -138,12 +138,12 @@ add_chain(Input, Type) ->
{error, Reason} ->
lager:info("rejecting ~p: ~p",
[x509:cert_string(LeafCert), Reason]),
- html("add-chain: invalid chain", Reason)
+ err400("add-chain: invalid chain", Reason)
end;
{invalid, ErrText} ->
- html(io:format("add-chain: ~p", [ErrText]), [ChainB64List])
+ err400(io:format("add-chain: ~p", [ErrText]), [ChainB64List])
end;
- _ -> html("add-chain: missing input: chain", Input)
+ _ -> err400("add-chain: missing input: chain", Input)
end.
-spec decode_chain(string()) -> {invalid, string()} | [binary()].