smg_comms_skeys_s... 1
smg_comms_skeys_s... 2
smg_comms_skeys_s... 3
smg_comms_skeys_s... 4 with RNG;
smg_comms_skeys_s... 5 with Data_Structs; use Data_Structs;
smg_comms_skeys_s... 6 with Messages; use Messages;
smg_comms_skeys_s... 7 with Interfaces; use Interfaces;
smg_comms_skeys_s... 8 with System;
smg_comms_skeys_s... 9 with System.Storage_Elements; use System.Storage_Elements;
smg_comms_skeys_s... 10 with Ada.Text_IO; use Ada.Text_IO;
smg_comms_skeys_s... 11
smg_comms_skeys_s... 12 package body Test_Serializing is
smg_comms_skeys_s... 13
smg_comms_skeys_s... 14 procedure Serialize_Keyset_SS is
smg_comms_skeys_s... 15 Msg : Serpent_Msg;
smg_comms_skeys_s... 16 KSet : Serpent_Keyset(5);
smg_comms_skeys_s... 17 LSB : Interfaces.Unsigned_8 := 16#01#;
smg_comms_skeys_s... 18 MSB : Interfaces.Unsigned_8 := 16#80#;
smg_comms_skeys_s... 19 LMSB: Interfaces.Unsigned_8 := 16#81#;
smg_comms_skeys_s... 20 Counter : Interfaces.Unsigned_16 := 101;
smg_comms_skeys_s... 21 NewSet: Serpent_Keyset;
smg_comms_skeys_s... 22 NewCounter: Interfaces.Unsigned_16:=0;
smg_comms_skeys_s... 23 begin
smg_comms_skeys_s... 24 Put_Line("Generating the Serpent Keys...");
smg_comms_skeys_s... 25
smg_comms_skeys_s... 26 for I in 1..KSet.N loop
smg_comms_skeys_s... 27 RNG.Get_Octets(KSet.Keys(Interfaces.Unsigned_8(I)));
smg_comms_skeys_s... 28 end loop;
smg_comms_skeys_s... 29 KSet.Flag := LSB;
smg_comms_skeys_s... 30
smg_comms_skeys_s... 31 Put_Line("Writing the keys to message...");
smg_comms_skeys_s... 32
smg_comms_skeys_s... 33 Write_SKeys_SMsg( KSet, Counter, Msg );
smg_comms_skeys_s... 34
smg_comms_skeys_s... 35 Put_Line("Reading keys back from message...");
smg_comms_skeys_s... 36
smg_comms_skeys_s... 37 Read_SKeys_SMsg( Msg, Counter, NewSet );
smg_comms_skeys_s... 38
smg_comms_skeys_s... 39 Put_Line("Comparing the keysets...");
smg_comms_skeys_s... 40
smg_comms_skeys_s... 41 if NewSet /= KSet then
smg_comms_skeys_s... 42 Put_Line("FAIL: keysets are different!");
smg_comms_skeys_s... 43 else
smg_comms_skeys_s... 44 Put_Line("PASS: keysets are the same!");
smg_comms_skeys_s... 45 end if;
smg_comms_skeys_s... 46
smg_comms_skeys_s... 47 Put_Line("Attempting to read from mangled message");
smg_comms_skeys_s... 48 begin
smg_comms_skeys_s... 49 Msg(Msg'First) := Msg(Msg'First)+25;
smg_comms_skeys_s... 50 Read_SKeys_SMsg( Msg, Counter, NewSet);
smg_comms_skeys_s... 51 Put_Line("FAIL: read failed to raise invalid message exception!");
smg_comms_skeys_s... 52 exception
smg_comms_skeys_s... 53 when Invalid_Msg =>
smg_comms_skeys_s... 54 Put_Line("PASS: exception correctly raised for invalid message");
smg_comms_skeys_s... 55 end;
smg_comms_skeys_s... 56 end Serialize_Keyset_SS;
smg_comms_skeys_s... 57
smg_comms_skeys_s... 58 end Test_Serializing;
smg_comms_skeys_s... 59