From 6c8799f118e3f4eec444a7087c29f8e506e7aa75 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 5 May 2014 00:17:55 +0200 Subject: Rename #sth -> #sth_signed and make it private. --- include/plop.hrl | 12 ------------ src/plop.erl | 24 ++++++++++++++++-------- test/plop_test.erl | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/include/plop.hrl b/include/plop.hrl index 17d81c8..62793fa 100644 --- a/include/plop.hrl +++ b/include/plop.hrl @@ -51,16 +51,4 @@ }). -type plop_entry() :: #plop_entry{}. -%% @doc The parts of an STH which is to be signed. Used as the -%% interface to plop:sth/1, for testing. Should probably be internal -%% to plop, if that can be arranged wrt testing. --record(sth, { - version = 1 :: pos_integer(), - signature_type :: signature_type(), - timestamp = now :: 'now' | integer(), - tree_size :: integer(), - root_hash :: binary() % SHA-256 - }). --type sth() :: #sth{}. - -export_type([timestamped_entry/0, mtl/0, entry_type/0]). diff --git a/src/plop.erl b/src/plop.erl index 05b8a92..0fb8f7e 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -16,7 +16,6 @@ -export([get_logid/0, serialise/1]). -export([add/1, sth/0]). %% API for tests. --export([sth/1]). -export([read_keyfile_rsa/2, read_keyfiles_ec/2]). -export([testing_get_pubkey/0]). %% gen_server callbacks. @@ -37,6 +36,17 @@ logid :: binary(), hashtree :: ht:head()}). +%% @doc The parts of an STH which is to be signed. Used as the +%% interface to plop:sth/1, for testing. +-record(sth_signed, { + version = 1 :: pos_integer(), + signature_type :: signature_type(), + timestamp = now :: 'now' | integer(), + tree_size :: integer(), + root_hash :: binary() % SHA-256 + }). +-type sth_signed() :: #sth_signed{}. + start_link(Keyfile, Passphrase) -> gen_server:start_link({local, ?MODULE}, ?MODULE, [Keyfile, Passphrase], []). @@ -78,8 +88,6 @@ add(Data) when is_record(Data, timestamped_entry) -> sth() -> gen_server:call(?MODULE, {sth, []}). -sth(Data) -> - gen_server:call(?MODULE, {sth, Data}). get_logid() -> gen_server:call(?MODULE, {get, logid}). @@ -175,13 +183,13 @@ spt(LogID, PrivKey, #timestamped_entry{ %% @doc Signed Tree Head as specified in RFC6962 section 3.2. sth(PrivKey, Tree, []) -> - sth(PrivKey, Tree, #sth{timestamp = now}); -sth(PrivKey, Tree, #sth{version = Version, timestamp = Timestamp_in}) -> + sth(PrivKey, Tree, #sth_signed{timestamp = now}); +sth(PrivKey, Tree, #sth_signed{version = Version, timestamp = Timestamp_in}) -> Timestamp = timestamp(Timestamp_in), Treesize = ht:size(Tree), Roothash = ht:tree_hash(Tree), BinToSign = - list_to_binary(serialise(#sth{version = Version, + list_to_binary(serialise(#sth_signed{version = Version, signature_type = tree_hash, timestamp = Timestamp, tree_size = Treesize, @@ -285,7 +293,7 @@ timestamp(Timestamp) -> _ -> Timestamp end. --spec serialise(plop_entry() | timestamped_entry() | spt() | spt_signed() | mtl() | sth()) -> iolist(). +-spec serialise(plop_entry() | timestamped_entry() | spt() | spt_signed() | mtl() | sth_signed()) -> iolist(). serialise(#plop_entry{ type = TypeAtom, data = Data @@ -332,7 +340,7 @@ serialise(#mtl{ % Merkle Tree Leaf. [<>, serialise(TimestampedEntry)]; -serialise(#sth{ % Signed Tree Head. +serialise(#sth_signed{ % Signed Tree Head. version = Version, signature_type = SigtypeAtom, timestamp = Timestamp, diff --git a/test/plop_test.erl b/test/plop_test.erl index cbbc85c..cf5a9a7 100644 --- a/test/plop_test.erl +++ b/test/plop_test.erl @@ -63,7 +63,7 @@ add(1, Pubkey) -> %% ?assertEqual(fixme, fixme). sth(0, Pubkey) -> - STH = plop:sth(#sth{}), + STH = plop:sth(), %%io:format(element(2, file:open("testdata", write)), "~p", [STH]), <