diff options
-rw-r--r-- | src/frontend.erl | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/frontend.erl b/src/frontend.erl index 172cc23..27b3c6c 100644 --- a/src/frontend.erl +++ b/src/frontend.erl @@ -121,15 +121,33 @@ check_entries(Entries, Start, End) -> end end, [], lists:zip(Entries, lists:seq(Start, End))). +entryhash_from_entry(Entry) -> + {ok, {Module, Function}} = application:get_env(plop, entryhash_from_entry), + Module:Function(Entry). + +verify_entry(Entry) -> + {ok, {Module, Function}} = application:get_env(plop, verify_entry), + Module:Function(Entry). + check_entry(LeafHash, Index) -> case db:get_by_leaf_hash(LeafHash) of notfound -> {notfound, Index}; {Index, LeafHash, Entry} -> - {ok, {Module, Function}} = application:get_env(plop, entryhash_from_entry), - EntryHash = Module:Function(Entry), - db:add_entryhash(LeafHash, EntryHash), - ok + case verify_entry(Entry) of + {ok, LeafHash} -> + EntryHash = entryhash_from_entry(Entry), + db:add_entryhash(LeafHash, EntryHash), + ok; + {ok, DifferentLeafHash} -> + lager:error("leaf hash not correct: filename is ~p " ++ + "and contents are ~p", + [hex:bin_to_hexstr(LeafHash), + hex:bin_to_hexstr(DifferentLeafHash)]), + {error, differentleafhash}; + {error, Reason} -> + lager:error("verification failed: ~p", [Reason]) + end end. -spec fetchmissingentries(non_neg_integer()) -> [binary() | noentry]. |