diff options
author | Magnus Ahltorp <map@kth.se> | 2015-03-26 23:59:30 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-03-27 00:00:14 +0100 |
commit | db1c5cf0eeba9b47a3f89bebc1abd9985ee9fef7 (patch) | |
tree | 13bb97720c65e0ff0c0a518c480410f94f5a40e6 /src/catlfish.erl | |
parent | f38b28bfe90ac9c35c8b2edcf296720e189f7083 (diff) |
Provide function for calculating entryhash from entryentryhash-merge
Diffstat (limited to 'src/catlfish.erl')
-rw-r--r-- | src/catlfish.erl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/catlfish.erl b/src/catlfish.erl index 2e5ffd4..ed75495 100644 --- a/src/catlfish.erl +++ b/src/catlfish.erl @@ -5,6 +5,7 @@ -export([add_chain/3, entries/2, entry_and_proof/2]). -export([known_roots/0, update_known_roots/0]). -export([init_cache_table/0]). +-export([entryhash_from_entry/1]). -include_lib("eunit/include/eunit.hrl"). -define(PROTOCOL_VERSION, 0). @@ -243,6 +244,30 @@ init_cache_table() -> end, ets:new(?CACHE_TABLE, [set, public, named_table]). +deserialise_extra_data(ExtraData) -> + case decode_tls_vector(ExtraData, 3) of + {E, <<>>} -> + [E]; + {E, Rest} -> + [E | deserialise_extra_data(Rest)] + end. + +entryhash_from_entry(Entry) -> + {MTLText, ExtraDataPacked} = unpack_entry(Entry), + {ExtraData, <<>>} = decode_tls_vector(ExtraDataPacked, 3), + MTL = deserialise_mtl(MTLText), + TimestampedEntry = MTL#mtl.entry, + Chain = deserialise_extra_data(ExtraData), + Data = + case TimestampedEntry#timestamped_entry.entry_type of + x509_entry -> + SignedEntry = TimestampedEntry#timestamped_entry.signed_entry, + [SignedEntry#signed_x509_entry.asn1_cert | Chain]; + precert_entry -> + Chain + end, + crypto:hash(sha256, Data). + %% Private functions. -spec unpack_entry(binary()) -> {binary(), binary()}. unpack_entry(Entry) -> |