anchor.diff:       fun generate_check_session_cookie/1}.
   
   server_key()->%setup function
  -    ["adfasdfasfs",timestamp_sec(now())].
  +    ["adfasdfasfs",30000].
   
   generate_check_session_cookie([ServerKey,TimeStamp]) ->
       [?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice"]},
  -		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice",fun(A)-> A end,ServerKey)
  -,
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice",fun(A)-> A end,ServerKey),
   					TimeStamp,fun(A)-> A end,ServerKey)),
        ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
   		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
   					TimeStamp,fun(A)-> A end,ServerKey)),
  +
  +
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  +		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  +					TimeStamp,fun(A)-> A end,ServerKey)),
  +
  +
  +
  +
  +
        ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and bob"]},
   		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and bob",fun(A)-> A end,ServerKey),
   					TimeStamp,fun(A)-> A end,ServerKey)),
  
positive.code: 
  -module(mochiweb_session).
  -export([generate_session_data/4,generate_session_cookie/4,check_session_cookie/4]).
  -export([cookie_encode/1,cookie_decode/1,timestamp_sec/1]).%Useful fuctions for more specific purposes
  
  %% @spec generate_session_data(ExpirationTime,Data :: string(),FSessionKey : function(A),ServerKey) -> string()
  %% @doc generates a secure encrypted string convining all the parameters.
  %%      The expiration time is considered in seconds
  generate_session_data(ExpirationTime,Data,FSessionKey,ServerKey) when is_integer(ExpirationTime),is_list(Data), is_function(FSessionKey)->
      BData=list_to_binary(Data),
      ExpTime=integer_to_list(ExpirationTime),
      BExpTime=list_to_binary(ExpTime),
      Key=gen_key(ExpTime,ServerKey),
      Hmac=gen_hmac(ExpTime,BData,FSessionKey(integer_to_list(ExpirationTime)),Key),
      EData=encrypt_data(BData,Key),
      bin_to_hexstr(<< BExpTime/binary,",", EData/binary,Hmac/binary>>).
  
  %% @spec generate_session_data(UserName,ExpirationTime,SessionExtraData,FSessionKey : function(A),ServerKey) -> mochiweb_cookie()
  %% @doc generates a secure encrypted cookie using the generate_session_data function.
  
negative.code: gen_hmac(ExpirationTime,Data,SessionKey,Key)->
      crypto:sha_mac(Key,[ExpirationTime,Data,SessionKey]).
  
  
  -ifdef(TEST).
  -include_lib("eunit/include/eunit.hrl").
  