%%% Copyright (c) 2014-2015, NORDUnet A/S. %%% See LICENSE for licensing information. %%% @doc Signing node API -module(signing). %% API (URL) -export([request/3]). request(post, "plop/v1/signing/sct", Input) -> case (catch mochijson2:decode(Input)) of {error, E} -> html("sendentry: bad input:", E); {struct, PropList} -> Data = base64:decode(proplists:get_value(<<"data">>, PropList)), Result = sign:sign_sct(Data), success({[{result, base64:encode(Result)}]}) end; request(post, "plop/v1/signing/sth", Input) -> case (catch mochijson2:decode(Input)) of {error, E} -> html("sendentry: bad input:", E); {struct, PropList} -> Data = base64:decode(proplists:get_value(<<"data">>, PropList)), Result = sign:sign_sth(Data), success({[{result, base64:encode(Result)}]}) end. %% Private functions. html(Text, Input) -> {400, [{"Content-Type", "text/html"}], io_lib:format( "

~n" ++ "~s~n" ++ "~p~n" ++ "~n", [Text, Input])}. success(Data) -> lager:debug("returning ~p", [Data]), {200, [{"Content-Type", "text/json"}], mochijson2:encode(Data)}.