diff options
author | Linus Nordberg <linus@nordberg.se> | 2015-05-06 12:04:51 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2015-05-06 12:04:51 +0200 |
commit | 0e27a8f7b0fff609f463cca3b2bfb40a916fcc13 (patch) | |
tree | c83538159453a2f432b29781b95e7d84dda2a203 /src/v1.erl | |
parent | ca8cbe163492f7fcb321d22d7e3700d8f0646d99 (diff) |
Dialyzer clean.
Diffstat (limited to 'src/v1.erl')
-rw-r--r-- | src/v1.erl | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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. |