From df6fca69a7d9bb11d7c6116a9cc4062a6e5e040d Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 2 May 2014 18:21:47 +0200 Subject: Sign using ECDSA and fix a couple bugs. Revive the plop_entry and hash over that instead of the full MTL, for the db hash. We don't want the timestamp in that hash! Use ECDSA instead of RSA for signing stuff. That's what Google does and we want to use their test suites. An annoyance with DSA is that the signature isn't deterministic. Testing just became less easy. Fix db:find() now that the hash is no longer the primary key. --- src/db.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/db.erl') diff --git a/src/db.erl b/src/db.erl index 857615c..3529080 100644 --- a/src/db.erl +++ b/src/db.erl @@ -51,8 +51,7 @@ dump_to_file(Filename) -> mnesia:dump_to_textfile(Filename). init(_Args) -> - {mnesia:wait_for_tables([plop], 5000), - []}. + {mnesia:wait_for_tables([plop], 5000), []}. start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). @@ -100,4 +99,14 @@ handle_call({dump, Table}, _From, State) -> Res = mnesia:transaction(F), {reply, Res, State}; handle_call({find, Hash}, _From, State) -> - {reply, mnesia:dirty_read({plop, Hash}), State}. + F = fun() -> + mnesia:select(plop, + [{#plop{hash = Hash, _='_'}, [], ['$_']}]) + end, + {atomic, Result} = mnesia:transaction(F), + Record = case length(Result) of + 0 -> []; + 1 -> hd(Result); + _ -> duplicate_hash_in_db % FIXME: log an error + end, + {reply, Record, State}. -- cgit v1.1