diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plop.erl | 24 |
1 files changed, 16 insertions, 8 deletions
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. [<<Version:8, LeafType:8>>, serialise(TimestampedEntry)]; -serialise(#sth{ % Signed Tree Head. +serialise(#sth_signed{ % Signed Tree Head. version = Version, signature_type = SigtypeAtom, timestamp = Timestamp, |