-- Tests for the serialization of data structures in SMG Protocol -- S.MG, 2018 with RNG; with Data_Structs; use Data_Structs; with Messages; use Messages; with Interfaces; use Interfaces; with System; with System.Storage_Elements; use System.Storage_Elements; with Ada.Text_IO; use Ada.Text_IO; package body Test_Serializing is procedure Serialize_Keyset_SS is Msg : Serpent_Msg; KSet : Serpent_Keyset(5); LSB : Interfaces.Unsigned_8 := 16#01#; MSB : Interfaces.Unsigned_8 := 16#80#; LMSB: Interfaces.Unsigned_8 := 16#81#; Counter : Interfaces.Unsigned_16 := 101; NewSet: Serpent_Keyset; NewCounter: Interfaces.Unsigned_16:=0; begin Put_Line("Generating the Serpent Keys..."); -- fill a set of Serpent Keys for I in 1..KSet.N loop RNG.Get_Octets(KSet.Keys(Interfaces.Unsigned_8(I))); end loop; KSet.Flag := LSB; Put_Line("Writing the keys to message..."); -- write keyset to serpent message Write_SKeys_SMsg( KSet, Counter, Msg ); Put_Line("Reading keys back from message..."); -- read keyset from message Read_SKeys_SMsg( Msg, Counter, NewSet ); Put_Line("Comparing the keysets..."); -- compare the two keysets if NewSet /= KSet then Put_Line("FAIL: keysets are different!"); else Put_Line("PASS: keysets are the same!"); end if; Put_Line("Attempting to read from mangled message"); begin Msg(Msg'First) := Msg(Msg'First)+25; Read_SKeys_SMsg( Msg, Counter, NewSet); Put_Line("FAIL: read failed to raise invalid message exception!"); exception when Invalid_Msg => Put_Line("PASS: exception correctly raised for invalid message"); end; end Serialize_Keyset_SS; end Test_Serializing;