summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/catlfish.erl28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/catlfish.erl b/src/catlfish.erl
index d483249..ffa2ec5 100644
--- a/src/catlfish.erl
+++ b/src/catlfish.erl
@@ -215,6 +215,18 @@ deserialise_signed_precert_entry(Data) ->
tbs_certificate = TBSCertificate},
RestData2}.
+serialise_extra_data(Type, Cert, Chain) ->
+ EncodedChain = encode_tls_vector(
+ list_to_binary(
+ [encode_tls_vector(C, 3) || C <- Chain]), 3),
+ case Type of
+ normal ->
+ EncodedChain;
+ precert ->
+ list_to_binary(
+ [encode_tls_vector(Cert, 3) | EncodedChain])
+ end.
+
-spec entries(non_neg_integer(), non_neg_integer()) -> {[{entries, list()},...]}.
entries(Start, End) ->
{[{entries, x_entries(plop:get(Start, End))}]}.
@@ -224,7 +236,7 @@ entry_and_proof(Index, TreeSize) ->
case plop:inclusion_and_entry(Index, TreeSize) of
{ok, Entry, Path} ->
{Type, MTLText, Cert, Chain} = unpack_entry(Entry),
- ExtraData = extra_data(Type, Cert, Chain),
+ ExtraData = serialise_extra_data(Type, Cert, Chain),
{[{leaf_input, base64:encode(MTLText)},
{extra_data, base64:encode(ExtraData)},
{audit_path, [base64:encode(X) || X <- Path]}]};
@@ -311,25 +323,13 @@ unpack_certchain(Data) ->
{<<"X509">>, Unpacked, Rest} = tlv:decode(Data),
[Unpacked | unpack_certchain(Rest)].
-extra_data(Type, Cert, Chain) ->
- EncodedChain = encode_tls_vector(
- list_to_binary(
- [encode_tls_vector(C, 3) || C <- Chain]), 3),
- case Type of
- normal ->
- EncodedChain;
- precert ->
- list_to_binary(
- [encode_tls_vector(Cert, 3) | EncodedChain])
- end.
-
-spec x_entries([{non_neg_integer(), binary(), binary()}]) -> list().
x_entries([]) ->
[];
x_entries([H|T]) ->
{_Index, _Hash, Entry} = H,
{Type, MTL, Cert, Chain} = unpack_entry(Entry),
- ExtraData = extra_data(Type, Cert, Chain),
+ ExtraData = serialise_extra_data(Type, Cert, Chain),
[{[{leaf_input, base64:encode(MTL)},
{extra_data, base64:encode(ExtraData)}]} | x_entries(T)].