From 05401ea36bbd7926fbdc0f792542135f551d3c0b Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 5 May 2014 12:02:55 +0200 Subject: Define #sth{} and have sth() return those. --- include/plop.hrl | 8 ++++++++ src/plop.erl | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/plop.hrl b/include/plop.hrl index e8247d8..0f687d0 100644 --- a/include/plop.hrl +++ b/include/plop.hrl @@ -40,4 +40,12 @@ }). -type plop_entry() :: #plop_entry{}. +-record(sth, { + treesize :: integer(), + timestamp :: integer(), + roothash :: binary(), + signature :: binary() + }). +-type sth() :: #sth{}. + -export_type([timestamped_entry/0, mtl/0, entry_type/0]). diff --git a/src/plop.erl b/src/plop.erl index b8e8055..4b9d321 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -200,16 +200,18 @@ sth(PrivKey, Tree, #sth_signed{version = Version, timestamp = Timestamp_in}) -> Treesize = ht:size(Tree), Roothash = ht:tree_hash(Tree), BinToSign = - list_to_binary(serialise(#sth_signed{version = Version, - signature_type = tree_hash, - timestamp = Timestamp, - tree_size = Treesize, - root_hash = Roothash})), + list_to_binary(serialise(#sth_signed{ + version = Version, + signature_type = tree_hash, + timestamp = Timestamp, + tree_size = Treesize, + root_hash = Roothash})), Signature = signhash(BinToSign, PrivKey), - STH = <>, + STH = #sth{ + treesize = Treesize, + timestamp = Timestamp, + roothash = Roothash, + signature = Signature}, io:format("STH: ~p~nBinToSign: ~p~nSignature: ~p~nTimestamp: ~p~n", [STH, BinToSign, Signature, Timestamp]), STH. @@ -304,7 +306,8 @@ timestamp(Timestamp) -> _ -> Timestamp end. --spec serialise(plop_entry() | timestamped_entry() | spt() | spt_signed() | mtl() | sth_signed()) -> iolist(). +-spec serialise(plop_entry() | timestamped_entry() | mtl() | + spt() | spt_signed() | sth() | sth_signed()) -> iolist(). serialise(#plop_entry{ type = TypeAtom, data = Data @@ -365,7 +368,6 @@ serialise(#sth_signed{ % Signed Tree Head. Treesize:64, Roothash/binary>>]. - %%%%%%%%%%%%%%%%%%%% %% Tests. serialise_test_() -> -- cgit v1.1