-
+ 0B7D9C9BA8094D32022CAFC676276DDF492FC26965DDAE35CB67DDDFC906B95B5D9025896BAE70ED46A1C6FFD8999D87C707A1EDB5577E5751FC48272108C8DD
smg_comms/tests/test_serializing.adb
(0 . 0)(1 . 59)
512 -- Tests for the serialization of data structures in SMG Protocol
513 -- S.MG, 2018
514
515 with RNG;
516 with Data_Structs; use Data_Structs;
517 with Messages; use Messages;
518 with Interfaces; use Interfaces;
519 with System;
520 with System.Storage_Elements; use System.Storage_Elements;
521 with Ada.Text_IO; use Ada.Text_IO;
522
523 package body Test_Serializing is
524
525 procedure Serialize_Keyset_SS is
526 Msg : Serpent_Msg;
527 KSet : Serpent_Keyset(5);
528 LSB : Interfaces.Unsigned_8 := 16#01#;
529 MSB : Interfaces.Unsigned_8 := 16#80#;
530 LMSB: Interfaces.Unsigned_8 := 16#81#;
531 Counter : Interfaces.Unsigned_16 := 101;
532 NewSet: Serpent_Keyset;
533 NewCounter: Interfaces.Unsigned_16:=0;
534 begin
535 Put_Line("Generating the Serpent Keys...");
536 -- fill a set of Serpent Keys
537 for I in 1..KSet.N loop
538 RNG.Get_Octets(KSet.Keys(Interfaces.Unsigned_8(I)));
539 end loop;
540 KSet.Flag := LSB;
541
542 Put_Line("Writing the keys to message...");
543 -- write keyset to serpent message
544 Write_SKeys_SMsg( KSet, Counter, Msg );
545
546 Put_Line("Reading keys back from message...");
547 -- read keyset from message
548 Read_SKeys_SMsg( Msg, Counter, NewSet );
549
550 Put_Line("Comparing the keysets...");
551 -- compare the two keysets
552 if NewSet /= KSet then
553 Put_Line("FAIL: keysets are different!");
554 else
555 Put_Line("PASS: keysets are the same!");
556 end if;
557
558 Put_Line("Attempting to read from mangled message");
559 begin
560 Msg(Msg'First) := Msg(Msg'First)+25;
561 Read_SKeys_SMsg( Msg, Counter, NewSet);
562 Put_Line("FAIL: read failed to raise invalid message exception!");
563 exception
564 when Invalid_Msg =>
565 Put_Line("PASS: exception correctly raised for invalid message");
566 end;
567 end Serialize_Keyset_SS;
568
569 end Test_Serializing;
570