summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2015-05-06 12:04:51 +0200
committerLinus Nordberg <linus@nordberg.se>2015-05-06 12:04:51 +0200
commit0e27a8f7b0fff609f463cca3b2bfb40a916fcc13 (patch)
treec83538159453a2f432b29781b95e7d84dda2a203 /src/v1.erl
parentca8cbe163492f7fcb321d22d7e3700d8f0646d99 (diff)
Dialyzer clean.
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/v1.erl b/src/v1.erl
index 29ccd41..2581804 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -126,11 +126,8 @@ add_chain(Input, Type) ->
case (catch mochijson2:decode(Input)) of
{error, E} ->
html("add-chain: bad input:", E);
- {struct, [{<<"chain">>, ChainBase64}]} ->
- case (catch [base64:decode(X) || X <- ChainBase64]) of
- {'EXIT', _} ->
- html("add-chain: invalid base64-encoded chain: ",
- [ChainBase64]);
+ {struct, [{<<"chain">>, ChainB64List}]} ->
+ case decode_chain(ChainB64List) of
[LeafCert | CertChain] ->
case x509:normalise_chain(catlfish:known_roots(),
[LeafCert|CertChain]) of
@@ -143,8 +140,15 @@ add_chain(Input, Type) ->
[x509:cert_string(LeafCert), Reason]),
html("add-chain: invalid chain", Reason)
end;
- Invalid ->
- html("add-chain: chain is not a list: ", [Invalid])
+ {invalid, ErrText} ->
+ html(io:format("add-chain: ~p", [ErrText]), [ChainB64List])
end;
_ -> html("add-chain: missing input: chain", Input)
end.
+
+-spec decode_chain(string()) -> {invalid, string()} | [binary()].
+decode_chain(B64List) ->
+ case (catch [base64:decode(X) || X <- B64List]) of
+ {'EXIT', _} -> {invalid, "invalid base64-encoded chain"};
+ L -> L
+ end.