text
stringlengths
0
234
procedure Test_Cookie (Name : in String; Value : in String) is
C : Cookie := Create (Name, Value);
begin
Test_Cookie (C);
for I in 1 .. 24 loop
Set_Max_Age (C, I * 3600 + I);
Test_Cookie (C);
end loop;
Set_Secure (C, True);
Test_Cookie (C);
Set_Http_Only (C, True);
Test_Cookie (C);
Set_Domain (C, "world.com");
Test_Cookie (C);
Set_Path (C, "/some-path");
Test_Cookie (C);
end Test_Cookie;
begin
Test_Cookie ("a", "b");
Test_Cookie ("session_id", "79e2317bcabe731e2f681f5725bbc621-&v=1");
Test_Cookie ("p_41_zy", "");
Test_Cookie ("p_34", """quoted\t""");
Test_Cookie ("d", "s");
declare
C : Cookie := Create ("cookie-name", "79e2317bcabe731e2f681f5725bbc621");
Start : Util.Measures.Stamp;
begin
Set_Path (C, "/home");
Set_Domain (C, ".mydomain.example.com");
Set_Max_Age (C, 1000);
Set_Http_Only (C, True);
Set_Secure (C, True);
Set_Comment (C, "some comment");
for I in 1 .. 1000 loop
declare
S : constant String := To_Http_Header (C);
begin
if S'Length < 10 then
T.Assert (S'Length > 10, "Invalid cookie generation");
end if;
Function Definition: procedure Free is new Unchecked_Deallocation (Vector, Access_Vector);
Function Body: -----------------------------------------------------------------------------
--| By calling the following Reset functions, it is user's responsibility |--
--| to keep track of dynamically allocated Access_Vector to prevent |--
--| dangling memory space. |--
-----------------------------------------------------------------------------
--| Reset with new seed and new keys |--
--| Gen.Keys = null to remove Keys |--
procedure Reset (G : in Generator;
New_Seed : in Seed_Type;
New_Keys : in Access_Vector)
is
Gen : Access_Generator := G'Unrestricted_Access;
begin
Gen.Seed := New_Seed;
Free (Gen.Keys);
Gen.Keys := New_Keys;
Init_By_Keys (G);
end Reset;
-----------------------------------------------------------------------------
--| Reset with new keys |--
--| Gen.Keys = null to remove Keys |--
procedure Reset (G : in Generator;
New_Keys : in Access_Vector)
is
Gen : Access_Generator := G'Unrestricted_Access;
begin
Free (Gen.Keys);
Gen.Keys := New_Keys;
Init_By_Keys (G);
end Reset;
-----------------------------------------------------------------------------
--| Reset with saved Generator in string buffer |--
procedure Reset (G : in Generator;
G_String : in String)
is
Gen : Access_Generator := G'Unrestricted_Access;
State_Length : Positive := G.State'Size / Standard.Character'Size;
State_Buffer : String (1 .. State_Length);
for State_Buffer use at G.State'Address;
Seed_Length : Positive := G.Seed'Size / Standard.Character'Size;
Seed_Buffer : String (1 .. Seed_Length);
for Seed_Buffer use at G.Seed'Address;
Keys_Length : Integer := 0;
Start, Stop : Integer;
begin
--| Sanity check if G_String is saved state of generator |--
if G_String (G_String'First .. G_String'First + Gen_Tag'Length - 1)
/= Gen_Tag then
raise Constraint_Error;
end if;
--| Get the number of keys saved, 0 if no keys |--
--| Skip the tag and "<": |--