anchor.diff:  	    if Hmac2==BHmac -> {true,[ExpirationTime1,binary_to_list(Data)]};
   	       true  -> {false,[ExpirationTime1,binary_to_list(Data)]}
   	    end
  -    end;
  -check_session_cookie(_,_,_,_,_,_) ->
  -    {false,[]}.
  -
  +    end.
  +%% check_session_cookie(ExpirationTime1, EData, BHmac,ExpirationTime,FSessionKey,ServerKey) 
  +%%   when is_integer(ExpirationTime) , is_list(ServerKey), is_list(ExpirationTime1)->
  +%%     ExpTime=list_to_integer(ExpirationTime1),
  +%%     Key=gen_key(ExpirationTime1,ServerKey),
  +%%     Data=decrypt_data(EData,Key),
  +%%     Hmac2=gen_hmac(ExpirationTime1,Data,FSessionKey(ExpirationTime1),Key),
  +%%     if ExpTime<ExpirationTime -> {false,[ExpirationTime1,binary_to_list(Data)]};
  +%%        true -> 
  +%% 	    if Hmac2==BHmac -> {true,[ExpirationTime1,binary_to_list(Data)]};
  +%% 	       true  -> {false,[ExpirationTime1,binary_to_list(Data)]}
  +%% 	    end
  +%%     end;
  +%% check_session_cookie(_,_,_,_,_,_) ->
  +%%     {false,[]}.
  +
  +ensure_binary(B) when is_binary(B) ->
  +    B;
  +ensure_binary(L) when is_list(L) ->
  +    iolist_to_binary(L).  %note, iolist_to_binary is better, since we might use something like mochijson2 here
   
   encrypt_data(Data,Key) ->
       IV = crypto:rand_bytes(16),
  
positive.code:      fun generate_check_session_cookie/1}.
  
  server_key()->%setup function
      ["adfasdfasfs",timestamp_sec(now())].
  
  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)
  ,
  					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)),
  
negative.code: 
  -module(mochiweb_session).
  -export([generate_session_data/4,generate_session_cookie/4,check_session_cookie/4]).
  
  
  %% @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=ensure_binary(Data),
      ExpTime=integer_to_list(ExpirationTime),
      BExpTime=ensure_binary(ExpTime),
      Key=gen_key(ExpTime,ServerKey),
      Hmac=gen_hmac(ExpTime,BData,FSessionKey(integer_to_list(ExpirationTime)),Key),
      EData=encrypt_data(BData,Key),
      io:format("data:~p length:~p~n",[<<ExpirationTime:32>>,length(integer_to_list(binary:decode_unsigned(<<ExpirationTime:32>>)))]),
      base64:encode(<< BExpTime:32,Hmac/binary, EData/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.
  