tree checksum vpatch file split hunks

all signers: diana_coman

antecedents: smg_comms_io_rsa_tests_only smg_comms_keymgm

press order:

smg_comms_genesisdiana_coman
smg_comms_raw_typesdiana_coman
smg_comms_packing_serpentdiana_coman
smg_comms_c_wrappersdiana_coman
smg_comms_rsa_oaepdiana_coman
smg_comms_packing_rsadiana_coman
smg_comms_80colsdiana_coman
smg_comms_skeys_smsgsdiana_coman
smg_comms_io_rsa_tests_onlydiana_coman
smg_comms_keymgmdiana_coman
smg_comms_filesdiana_coman

patch:

- 8C55EF6A254359BF52A32B6D58F2A954184505EE4294B2CD1F7F6DD29911B873ABA792EB6B88F9D62653CCB3D6D0FDDF88146635729154848FAC78BE60418BA2
+ 268276F725EBBBF0EB0E11ADCD2516571ACB8958068B17040E1FB841A2EDD44878D73C932982D70C4192B70C43F2CC9EDF699380AA98FE15A968D81BFC911B14
smg_comms/manifest
(8 . 3)(8 . 4)
5 549511 smg_comms_skeys_smsgs diana_coman Defines data structures and message types as well as methods for reading/writing Serpent keysets to/from Serpent messages.
6 549785 smg_comms_io_rsa_tests_only diana_coman Small refactoring of tests extracting the reading of RSA key into package of its own so it can be used throughout tests and thus get rid of the too long lines in test_packing.adb.
7 550310 smg_comms_keymgm diana_coman Adds read/write for Keys Management messages (both Serpent and RSA). Refactors the read/write of Serpent Keys messages so that the same core is called by RSA/Serpent specific-methods, adding also read/write of keys from/to RSA messages.
8 551086 smg_comms_files diana_coman Adds read/write for File Transfer (4.3) and File Request (4.4). Refactors the rest to have read/write of 16 bits values in one single place (i.e. separate method called from everywhere else) because of how common it is + sensitive to endianness.
- 30B66C681C3DE5AD3731A40C47760D77D58707D32B66D8A8BB987898067A631BF761ADEE878B08F77FE8D83DF097900F8990CA75E02CB0A2AEEC1A58A5209C4D
+ D472416A6FDBB7FD240664149E4A120F449AC15839D611E8A6987C145D3FE13C0A2227FE8C6BA3BC8F4ED2350973E7DFE6A074AB87CB02FBAF786396169FE5CF
smg_comms/src/data_structs.ads
(44 . 6)(44 . 30)
13 RZ at 12 range 0 .. 7;
14 end record;
15
16 -- length of a text field (i.e. 16 bits, strictly > 0)
17 subtype Text_Len is Positive range 1..2**16-1;
18
19 -- A set of file names glued into a single string
20 -- NB: there IS at least ONE filename and one character
21 -- Upper limit for Text_Len is due to protocol's spec of text basic type
22 type U16_Array is array (Text_Len range <> ) of Interfaces.Unsigned_16;
23 type Filenames( F_No: Text_Len := 1; Sz: Text_Len := 1 ) is
24 record
25 -- filenames glued together into 1 single string
26 S : String( 1 .. Sz ) := (others => '0');
27 -- indices in S, at which each filename starts
28 Starts: U16_Array( 1 .. F_No ) := (others => 1);
29 end record;
30
31 -- A chunk of a file (for file transfer)
32 type File_Chunk( Len : Text_Len := 1;
33 Count : Interfaces.Unsigned_16 := 1;
34 Name_Len: Text_len := 1) is
35 record
36 Filename: String(1..Name_Len);
37 Content : Raw_Types.Octets(1..Len);
38 end record;
39
40 -------------------------
41 -- A set of Serpent Keys
42 -- parametrized record for a Serpent Keyset
- 796122DCF307899111D2909509460B1DE5215EF1DFADB88AF3F3B2654754AA225ACF79FF0B50BE884F184966920BCD30E236585FA46846DC36B8F58F67C726D1
+ FD5121B49FCBCB70293B002298FC82272EF291E959FE63D17B5B22BA02B1ABB2B1D12A6D0D9541CAEBE43A300FE08CC329FBCACE81B8341A00296F66EB182A84
smg_comms/src/messages.adb
(4 . 6)(4 . 7)
47 with Interfaces; use Interfaces;
48 with Serpent;
49 with System; use System;
50 with Ada.Assertions; use Ada.Assertions;
51
52 package body Messages is
53
(55 . 6)(56 . 299)
55 end if;
56 end Read_KMgm_SMsg;
57
58 ------ File Transfer ------
59 procedure Write_File_Transfer( Chunk : in File_Chunk;
60 Msg : out Raw_Types.Serpent_Msg) is
61 Pos: Integer := Msg'First;
62 U16: Interfaces.Unsigned_16;
63 begin
64 -- write type ID
65 Msg(Pos) := File_Transfer_S_Type;
66 Pos := Pos + 1;
67
68 -- write filename as text field (size+2, text)
69 -- check against overflows
70 if Chunk.Name_Len > Text_Len'Last - 2 or
71 Pos + Integer(Chunk.Name_Len) + 2 > Msg'Last then
72 raise Invalid_Msg;
73 end if;
74
75 -- write total size: filename size + 2
76 U16 := Interfaces.Unsigned_16( Chunk.Name_Len + 2 );
77 Write_U16( Msg, Pos, U16 );
78
79 -- write filename
80 String_To_Octets( Chunk.Filename,
81 Msg(Pos..Pos+Integer(Chunk.Name_Len)-1) );
82 Pos := Pos + Integer(Chunk.Name_Len);
83
84 --write content
85 -- check against overflow, including the 2 octets for counter at the end
86 if Chunk.Len > Text_Len'Last - 2 or
87 Pos + Integer(Chunk.Len) + 4 > Msg'Last then
88 raise Invalid_Msg;
89 end if;
90
91 -- write total size for this text field
92 U16 := Interfaces.Unsigned_16( Chunk.Len + 2 );
93 Write_U16( Msg, Pos, U16 );
94
95 -- write actual content
96 Msg(Pos..Pos+Chunk.Content'Length-1) := Chunk.Content;
97 Pos := Pos + Chunk.Content'Length;
98
99 -- write counter
100 Write_U16( Msg, Pos, Chunk.Count );
101
102 -- write padding if needed
103 if Pos <= Msg'Last then
104 RNG.Get_Octets( Msg(Pos..Msg'Last) );
105 end if;
106
107 end Write_File_Transfer;
108
109 -- The opposite of Write_File_Transfer method above.
110 -- Counter will contain the message counter
111 -- Chunk will contain the chunk counter, filename and content
112 procedure Read_File_Transfer( Msg : in Raw_Types.Serpent_Msg;
113 Chunk : out File_Chunk) is
114 Pos: Integer := Msg'First;
115 U16: Interfaces.Unsigned_16;
116 S_Name, E_Name: Integer; --start/end for filename in Msg
117 S_Len: Text_Len; -- length of filename (needed as Text_Len anyway)
118 S_Content, E_Content: Integer; --start/end for content in Msg
119 Content_Len: text_Len; -- length of content (needed as Text_Len anyway)
120 begin
121 -- read and check type ID
122 if Msg(Pos) /= File_Transfer_S_Type then
123 raise Invalid_Msg;
124 end if;
125 Pos := Pos + 1;
126
127 -- read filename size
128 Read_U16( Msg, Pos, U16 );
129
130 -- check for overflow and underflow; filename size >= 1
131 if Pos + Integer(U16) - 2 > Msg'Last or
132 U16 < 3 then
133 raise Invalid_Msg;
134 end if;
135 U16 := U16 - 2;
136 S_Len := Text_Len(U16);
137
138 -- set start + end for reading filename later, when ready
139 S_Name := Pos;
140 E_Name := Pos + Integer(U16)-1;
141 Pos := Pos + S_Len;
142
143 -- read size of content
144 Read_U16( Msg, Pos, U16 );
145 -- check for overflow and underflow; content >=1; counter =2 octets
146 if Pos + Integer(U16) - 1 > Msg'Last or
147 U16 < 3 then
148 raise Invalid_msg;
149 end if;
150 U16 := U16 - 2;
151 Content_Len := Text_Len(U16);
152 -- set start and end for reading content later, when ready
153 S_Content := Pos;
154 E_Content := Pos + Integer(U16) - 1;
155 Pos := Pos + Content_Len;
156
157 -- read counter
158 Read_U16( Msg, Pos, U16 );
159 -- check chunking validity i.e. if counter>0 then no padding
160 if U16 /= 0 and Pos /= Msg'Last then
161 raise Invalid_Msg;
162 end if;
163
164 -- create File_Chunk structure and fill it with data from Msg
165 declare
166 FC : File_Chunk( Len => Content_Len,
167 Count => U16,
168 Name_Len => S_Len);
169 begin
170 -- read from Msg
171 FC.Content := Msg( S_Content..E_Content );
172 Octets_To_String( Msg( S_Name..E_Name ), FC.Filename);
173 -- copy to output var
174 Chunk := FC;
175 end;
176
177 end Read_File_Transfer;
178
179 ---- File Requests ----
180 procedure Write_File_Request( FR : in Filenames;
181 Counter : in Interfaces.Unsigned_16;
182 Msg : out Raw_Types.Serpent_Msg;
183 Written : out Natural) is
184 Pos : Integer := Msg'First;
185 Max_Pos: Integer := Msg'Last - 2; -- 2 octets at end for counter
186 Text_Sz: Integer;
187 Max_Sz : Integer;
188 begin
189 -- write ID for File Request type
190 Msg( Pos ) := File_Req_S_Type;
191 Pos := Pos + 1;
192
193 -- write Text size: filenames + separators
194 -- consider fewer filenames if they don't ALL fit
195 -- 2 octets are taken by size itself
196 Max_Sz := Max_Pos - Pos - 1;
197 Text_Sz := FR.Sz + FR.F_No - 1;
198 if Text_Sz > Max_Sz then
199 -- walk the array of filenames backwards and stop when they fit
200 Written := FR.F_No - 1;
201 -- calculate actual size written based on start of first discarded
202 -- filename and (Written -1) octets for needed separators
203 Text_Sz := Integer(FR.Starts(Written+1)) - FR.Starts'First +
204 (Written - 1);
205
206 -- loop until either fits or nothing left
207 while Written > 0 and Text_Sz > Max_Sz loop
208 Written := Written - 1;
209 Text_Sz := Integer(FR.Starts(Written+1))- FR.Starts'First +
210 (Written - 1);
211 end loop;
212 -- check that there is what to write, since nothing -> invalid message
213 if Written = 0 then
214 raise Invalid_Msg;
215 end if;
216
217 else --from if Text_Sz > Max_Sz
218 -- ALL are written
219 Written := FR.F_No;
220 end if;
221
222 -- write Text_Sz + 2 (i.e. TOTAL size)
223 if Text_Sz + 2 > Integer(Interfaces.Unsigned_16'Last) then
224 raise Invalid_Msg;
225 end if;
226
227 Write_U16( Msg, Pos, Interfaces.Unsigned_16(Text_Sz+2) );
228
229 -- write filenames separated by Sep
230 for I in 1..Written loop
231 declare
232 Start_Pos : Positive;
233 End_Pos : Positive;
234 Len : Positive;
235 begin
236 -- current start pos in FR.S
237 Start_Pos := Positive( FR.Starts( FR.Starts'First + I - 1));
238
239 -- calculate end based on start of next name or last
240 if I < FR.F_No then
241 End_Pos := Positive( FR.Starts( FR.Starts'First + I)) - 1;
242 else
243 End_Pos := FR.S'Last;
244 end if;
245
246 -- NB: this WILL fail if starting positions are not in order!
247 Len := End_Pos - Start_Pos + 1;
248 if Len <= 0 then
249 raise Invalid_Msg;
250 end if;
251
252 --write the actual filename
253 String_To_Octets( FR.S( Start_Pos..End_Pos ), Msg(Pos..Pos+Len-1) );
254 Pos := Pos + Len;
255
256 --if it's not the last one, write a separator
257 if I < Written then
258 Msg(Pos) := Sep;
259 Pos := Pos + 1;
260 end if;
261 end;
262 end loop;
263
264 -- write the message counter in little endian at all times
265 Write_U16( Msg, Pos, Counter );
266
267 -- write padding if needed
268 if Pos <= Msg'Last then
269 Rng.Get_Octets( Msg(Pos..Msg'Last) );
270 end if;
271 end Write_File_Request;
272
273 -- Reads a request for files; the opposite of Write_File_Request above
274 procedure Read_File_Request( Msg : in Raw_Types.Serpent_Msg;
275 Counter : out Interfaces.Unsigned_16;
276 FR : out Filenames) is
277 Pos : Integer := Msg'First;
278 Max_Pos : Integer := Msg'Last - 2; --at least 2 reserved for counter
279 Text_Sz : Integer;
280 Max_Sz : Integer := Max_Pos - Pos - 1; --text only i.e. w.o. size itself
281 F_No : Integer;
282 U16 : Interfaces.Unsigned_16;
283 begin
284 -- read type ID and check
285 if Msg(Pos) /= File_Req_S_Type then
286 raise Invalid_Msg;
287 end if;
288 Pos := Pos + 1;
289
290 -- read total size of filenames+separators
291 Read_U16( Msg, Pos, U16 );
292 Text_Sz := Integer(U16);
293 -- take away the 2 octets for size itself
294 Text_Sz := Text_Sz - 2;
295
296 -- check that Text_Sz is not overflowing/underflowing
297 if Text_Sz < 1 or Text_Sz > Max_Sz then
298 raise Invalid_Msg;
299 end if;
300
301 -- count first the separators to know how many filenames
302 -- NB: there is always at least 1 filename as Text_Sz > 0
303 F_No := 1;
304 for I in Pos .. Pos + Text_Sz - 1 loop
305 if Msg(I) = Sep then
306 F_No := F_No + 1;
307 end if;
308 end loop;
309
310 -- create the output structure and discard separators
311 -- text without separators should be Text_Sz - F_No + 1
312 -- (because ONLY one separator between 2 filenames allowed)
313 -- if it's not that => Invalid_Msg
314 -- F_No and Text_Sz are not overflow (earlier check + calc)
315 declare
316 F : Filenames(Text_Len(F_No), Text_Len(Text_Sz-F_No+1));
317 S_Pos : Positive;
318 Index : Positive;
319 begin
320 S_Pos := F.S'First;
321 Index := F.Starts'First;
322 F.Starts(Index) := Interfaces.Unsigned_16(S_Pos);
323
324 for I in Pos .. Pos + Text_Sz - 1 loop
325 -- copy over to F.S anything that is not separator
326 if Msg(I) /= Sep then
327 F.S( S_Pos ) := Character'Val(Msg(I));
328 S_Pos := S_Pos + 1;
329 else
330 -- if it's separator, check and if ok, add next as start
331 if I = Pos + Text_Sz or -- separator as last character is error
332 Msg(I+1) = Sep or -- 2 consecutive separators is error
333 Index >= F.Starts'Last then -- too many separators is error
334 raise Invalid_Msg;
335 else
336 Index := Index + 1;
337 F.Starts( Index ) := Interfaces.Unsigned_16(S_Pos);
338 end if;
339 end if;
340 end loop;
341
342 -- copy the whole structure to output variable
343 FR := F;
344 end;
345
346 -- read message counter now
347 Pos := Pos + Text_Sz;
348 Read_U16( Msg, Pos, Counter );
349
350 end Read_File_Request;
351
352 ------------------
353 -- RSA Messages --
(100 . 6)(394 . 27)
355 end if;
356 end Read_KMgm_RMsg;
357
358
359 ----------Utilities ----------
360 -- String to Octets conversion
361 procedure String_To_Octets(Str: in String; O: out Raw_Types.Octets) is
362 begin
363 Assert( Str'Length = O'Length );
364 for I in 1..Str'Length loop
365 O( O'First+I-1 ) := Character'Pos(Str(Str'First + I - 1 ));
366 end loop;
367 end String_To_Octets;
368
369 -- Octets to string conversion
370 -- NB: Str'Length has to be EQUAL to Octets'Length!
371 procedure Octets_To_String(O: in Raw_Types.Octets; Str: out String) is
372 begin
373 Assert( O'Length = Str'Length );
374 for I in 1..O'Length loop
375 Str( Str'First+I-1 ) := Character'Val(O(O'First + I - 1 ));
376 end loop;
377 end Octets_To_String;
378
379 ------------------
380 -- private part --
381 ------------------
(124 . 7)(439 . 6)
383 Msg : out Raw_Types.Octets) is
384 Pos : Integer := Msg'First;
385 Check : CRC32.CRC32;
386 PadLen: Integer;
387 K : Serpent.Key;
388 begin
389 -- write Type ID
(158 . 19)(472 . 11)
391 Pos := Pos + 1;
392
393 -- write message counter
394 Msg(Pos..Pos+1) := Raw_Types.Cast(Counter);
395 Cast_LE(Msg(Pos..Pos+1));
396 Pos := Pos + 2;
397 Write_U16( Msg, Pos, Counter );
398
399 -- write padding as needed; endianness is irrelevant here
400 PadLen := Msg'Last - Pos + 1;
401 if PadLen > 0 then
402 declare
403 Pad : Raw_Types.Octets(1..PadLen);
404 begin
405 RNG.Get_Octets( Pad );
406 Msg(Pos..Pos+PadLen-1) := Pad;
407 end;
408 if Pos <= Msg'Last then
409 RNG.Get_Octets( Msg(Pos..Msg'Last) );
410 end if;
411
412 end Write_SKeys;
(196 . 7)(502 . 6)
414 K : Serpent.Key;
415 Check : CRC32.CRC32;
416 O4 : Raw_Types.Octets_4;
417 O2 : Raw_Types.Octets_2;
418 begin
419 Pos := Pos + 1;
420 --read keys and check crc for each
(220 . 9)(525 . 7)
422 KS.Flag := Msg(Pos);
423 Pos := Pos + 1;
424 -- read and set message counter
425 O2 := Msg(Pos..Pos+1);
426 Cast_LE(O2);
427 Counter := Raw_Types.Cast(O2);
428 Read_U16( Msg, Pos, Counter );
429 -- rest of message is padding so it's ignored
430 -- copy keyset to output variable
431 Keyset := KS;
(266 . 12)(569 . 12)
433 end if;
434
435 -- write the message count
436 Msg(Pos..Pos+1) := Raw_Types.Cast( Counter );
437 Cast_LE( Msg(Pos..Pos+1) );
438 Pos := Pos + 2;
439 Write_U16( Msg, Pos, Counter );
440
441 -- pad with random octets until the end of Msg
442 RNG.Get_Octets( Msg(Pos..Msg'Last) );
443 if Pos <= Msg'Last then
444 RNG.Get_Octets( Msg(Pos..Msg'Last) );
445 end if;
446
447 end Write_KMgm;
448
(295 . 7)(598 . 6)
450 declare
451 N_Burnt : Counter_8bits := Counter_8bits(Msg(Burnt_Pos));
452 Mgm : Keys_Mgm(N_Burnt);
453 O2 : Raw_Types.Octets_2;
454 begin
455 -- read count of server keys requested
456 Mgm.N_Server := Msg(Pos);
(316 . 14)(618 . 33)
458 end if;
459
460 -- read and set message counter
461 O2 := Msg(Pos..Pos+1);
462 Cast_LE(O2);
463 Counter := Raw_Types.Cast(O2);
464 Read_U16( Msg, Pos, Counter );
465 -- rest of message is padding so it's ignored
466 -- copy the keys mgm structure to output param
467 KMgm := Mgm;
468 end;
469 end Read_KMgm;
470
471 -- Write a 16 bits value to Octets at Pos; Pos increases by 2.
472 procedure Write_U16( Msg: in out Raw_Types.Octets;
473 Pos: in out Natural;
474 U16: in Interfaces.Unsigned_16) is
475 begin
476 Msg(Pos..Pos+1) := Raw_Types.Cast(U16);
477 Cast_LE(Msg(Pos..Pos+1));
478 Pos := Pos + 2;
479 end Write_U16;
480
481 -- Read a 16-bits values from Octets from Pos; Pos increases by 2.
482 procedure Read_U16( Msg: in Raw_Types.Octets;
483 Pos: in out Natural;
484 U16: out Interfaces.Unsigned_16) is
485 O2 : Raw_Types.Octets_2;
486 begin
487 O2 := Msg(Pos..Pos+1);
488 Cast_LE(O2);
489 U16 := Raw_Types.Cast(O2);
490 Pos := Pos + 2;
491 end Read_U16;
492
493 end Messages;
- 32CD2279D2E7501F1C713A414424C1BB37D4C54FD279B14221ED6409431C47F469DCCFFE0B5ED303B1E3B2C77B2D7BB81E7902A4FACD4D96B8E28522A71BB69F
+ D6C3980DA332629A8C09CFBFB32E1962AD689C7ECBC4A8EE83B02F85C1AA1A3374C5371EEEE7F0CC49FE4C4D8E758F86FA5BA204C5900BD6F4F95CABB3A06EF6
smg_comms/src/messages.ads
(57 . 7)(57 . 34)
498 Counter : out Interfaces.Unsigned_16;
499 KMgm : out Keys_Mgm);
500
501 ----------------- File Transfer ----------------------
502
503 -- Writes the given File Chunk to a File Transfer type of message
504 -- Chunk - chunk of file to write; contains counter, filename, content
505 procedure Write_File_Transfer( Chunk : in File_Chunk;
506 Msg : out Raw_Types.Serpent_Msg);
507
508 -- The opposite of Write_File_Transfer method above.
509 -- Chunk will contain the counter, filename and content
510 procedure Read_File_Transfer( Msg : in Raw_Types.Serpent_Msg;
511 Chunk : out File_Chunk);
512
513 ----------------- File Request ----------------------
514 -- Writes a message to request the files specified through their names
515 -- Written parameter will hold the number of filenames actually written
516 -- NB: this can be less than the number of filenames provided!
517 -- When Written < FR.F_No, the FIRST Written filenames were written; the rest
518 -- did not fit into the message and it's up to caller to decide what to do.
519 procedure Write_File_Request( FR : in Filenames;
520 Counter : in Interfaces.Unsigned_16;
521 Msg : out Raw_Types.Serpent_Msg;
522 Written : out Natural);
523
524 -- Reads a request for files; the opposite of Write_File_Request above
525 -- Raises Invalid_Msg exception if the provided message fails checks.
526 procedure Read_File_Request( Msg : in Raw_Types.Serpent_Msg;
527 Counter : out Interfaces.Unsigned_16;
528 FR : out Filenames);
529
530 ------------------
531 -- RSA Messages --
(90 . 12)(117 . 20)
533
534 -- Reads a Key management structure from the given RSA Message
535 -- The opposite of Write_KMgm_SMsg above
536 -- Raises Invalid_Message exception if given message fails sanity checks
537 -- Raises Invalid_Msg exception if given message fails sanity checks
538 procedure Read_KMgm_RMsg( Msg : in Raw_Types.RSA_Msg;
539 Counter : out Interfaces.Unsigned_16;
540 KMgm : out Keys_Mgm);
541
542
543 -- String to Octets conversion
544 -- NB: Str'Length has to be EQUAL to Octets'Length!
545 procedure String_To_Octets(Str: in String; O: out Raw_Types.Octets);
546
547 -- Octets to string conversion
548 -- NB: Str'Length has to be EQUAL to Octets'Length!
549 procedure Octets_To_String(O: in Raw_Types.Octets; Str: out String);
550
551 private
552
553 -- if native is little endian, does nothing;
(103 . 6)(138 . 10)
555 -- (strictly for arrays of octets)
556 procedure Cast_LE( LE: in out Raw_Types.Octets );
557
558 -- separator used for list of filenames
559 F_Sep: constant String := ";"; --as string
560 Sep: constant Interfaces.Unsigned_8 := 16#3B#; -- ascii code
561
562 -- protocol message types IDs, fixed as per protocol specification
563 -- Serpent messages end in "S_Type"
564 -- RSA messages end in "R_Type"
(164 . 4)(203 . 24)
566 Counter : out Interfaces.Unsigned_16;
567 KMgm : out Keys_Mgm);
568
569 -- helper methods to read/write a value on 16 bits (using Cast_LE as needed)
570
571 -- Writing a 16-bits value to the given Octets at specified position.
572 -- NB: Caller has to make sure Pos <= Msg'Last -1 ; NO check here!
573 -- Msg - the array of octets into which the value is to be written
574 -- Pos - the position in Msg at which to write the value;
575 -- NB: Pos will be increased by 2 after the write!
576 -- U16 - the value to write
577 procedure Write_U16( Msg: in out Raw_Types.Octets;
578 Pos: in out Natural;
579 U16: in Interfaces.Unsigned_16);
580
581 -- Reading a 16-bits value from the given Octets at specified position.
582 -- NB: Caller has to make sure Pos <= Msg'Last -1 ; NO check here!
583 -- Pos - the position in Msg from which to read the value;
584 -- NB: Pos will be increased by 2 after the read!
585 -- The opposite of Write_U16 above.
586 procedure Read_U16( Msg: in Raw_Types.Octets;
587 Pos: in out Natural;
588 U16: out Interfaces.Unsigned_16);
589 end Messages;
- EAFEF048291AFF4715A31FE02B0BA62CAB5D4B2D5D1E904B4A25DBA9B08584B198C4BAB46CA115B4809DD8506875719D6F30C506797CD0B399A2077C22BA1882
+ A8A3F14CBACAEC0691D66C7058CD758C510E3ADDEC91D5529093F6259AD65D3353B714F316A32CDE7CC476CAC611B167250CE6615DB506CB7D62ED98CBCC8BDF
smg_comms/tests/test_packing.adb
(93 . 7)(93 . 7)
594 end if;
595
596 -- try to unpack a mangled package
597 Pkt(Pkt'First + 3) := Pkt(Pkt'First + 3) and 16#AB#;
598 Pkt(Pkt'First + 3) := Pkt(Pkt'First + 3) + 1;
599 Decr_Msg := (others => 0);
600 Decr_Msg := Packing.Unpack( Pkt, SKey, Success );
601 if Success then
- 108527AA9877FD1AA76FDF913C50760854260B8406DB12A4C7B1A1A052D593EACC2D59D8F36F7BF70BDC6AC21A3A28E80930C89A64020AE597B67976100F61E2
+ 60BA5DFFA63414F5B2D28611DA978EF0CDAACCAEEBA3383699E8EBFF223F608BED0F6752411067CF8A40BBB209040FCC621557BCF771F2459268ABE0EDCDC6A9
smg_comms/tests/test_serializing.adb
(130 . 5)(130 . 175)
606
607 end Serialize_Keys_Mgm;
608
609 procedure Serialize_File_Request( Reps: in Positive) is
610 MaxSz: Positive := 340;
611 O2 : Raw_Types.Octets_2;
612 U16 : Interfaces.Unsigned_16;
613 Counter : Interfaces.Unsigned_16;
614 ReadCounter: Interfaces.Unsigned_16;
615 Written: Natural;
616 Msg : Raw_Types.Serpent_Msg;
617 F_No, Sz: Text_Len;
618 begin
619 for I in 1 .. Reps loop
620 -- generate a random size
621 RNG.Get_Octets( O2 );
622 U16 := Raw_Types.Cast( O2 );
623 Sz := Text_Len( Positive(U16) mod MaxSz + 1);
624
625 -- generate a random number of files
626 RNG.Get_Octets( O2 );
627 U16 := Raw_Types.Cast( O2 );
628 F_No := Text_Len( Positive(U16) mod Sz );
629 if F_No = 0 then
630 F_No := 1;
631 end if;
632
633 declare
634 FR: Filenames(F_No, Sz);
635 ReadFR: Filenames;
636 O : Octets(1..Sz);
637 Len : Positive := Sz / F_No;
638 begin
639 Put_Line("Generating test for File Request with " &
640 Integer'Image(FR.F_No) & " filenames.");
641 -- generate a random counter
642 RNG.Get_Octets(O2);
643 Counter := Raw_Types.Cast(O2);
644
645 -- fill FR
646 RNG.Get_Octets( O );
647 -- replace separators if any
648 for I in O'Range loop
649 if O(I) = 59 then
650 O(I) := 69;
651 end if;
652 end loop;
653
654 Octets_To_String( O, FR.S );
655 for I in FR.Starts'Range loop
656 FR.Starts(I) := Interfaces.Unsigned_16( FR.Starts'First +
657 Len*(I-FR.Starts'First));
658 end loop;
659
660 -- write FR to message
661 Write_File_Request(FR, Counter, Msg, Written);
662
663 -- check how many filenames were written
664 if Written /= FR.F_No then
665 Put_Line("FAIL: only " & Natural'Image(Written) &
666 " filenames written out of " & Natural'Image(FR.F_No));
667 else
668 Put_Line("PASS: wrote " & Natural'Image(Written) & " filenames.");
669 end if;
670
671 -- read it from message and check result
672 Read_File_Request(Msg, ReadCounter, ReadFR);
673 if ReadCounter /= Counter then
674 Put_Line("FAIL: ReadCounter is " & Unsigned_16'Image(ReadCounter) &
675 " instead of expected " & Unsigned_16'Image(Counter) );
676 else
677 Put_Line("PASS: ReadCounter was read correctly as " &
678 Unsigned_16'Image(ReadCounter));
679 end if;
680 if ReadFr.Sz /= FR.Sz then
681 Put_Line("FAIL: Read FR.Sz = " & Text_Len'Image(ReadFr.Sz) &
682 " while expected sz is " & Text_Len'Image(FR.Sz));
683 else
684 Put_Line("PASS: Read FR.Sz as expected = " &
685 Text_Len'Image(ReadFr.Sz));
686 end if;
687 if ReadFr /= FR then
688 Put_Line("FAIL: ReadFr different from FR.");
689 else
690 Put_Line("PASS: ReadFr as expected, same as FR.");
691 end if;
692 end;
693 end loop;
694
695 -- test with more files than can fit
696 Put_Line("Test case for File Request with more files than fit.");
697 declare
698 F: Filenames(4, 16384);
699 ReadF: Filenames;
700 begin
701 F.Starts(1) := Interfaces.Unsigned_16(F.S'First);
702 F.Starts(2) := Interfaces.Unsigned_16(F.S'First + 342);
703 F.Starts(3) := 16370;
704 F.Starts(4) := 16380;
705 Write_File_Request(F, Counter, Msg, Written);
706 if Written /= 1 then
707 Put_Line("FAIL: Written is " & Natural'Image(Written) &
708 " instead of expected 1.");
709 else
710 Put_Line("PASS: Written is 1 out of 4, as expected.");
711 end if;
712 Read_File_Request(Msg, ReadCounter, ReadF);
713 if ReadF.F_No /= 1 or ReadF.Starts(1) /= 1 or ReadF.Sz /= 342 then
714 Put_Line("FAIL: F_No is " & Text_Len'Image(ReadF.F_No) &
715 " Sz is " & Text_Len'Image(ReadF.Sz));
716 else
717 Put_line("PASS: written 1 out of 4 correctly.");
718 end if;
719 end;
720 end Serialize_File_Request;
721
722 procedure Serialize_File_Chunk is
723 Filename : String := "afile.png";
724 FC : File_Chunk( Len => 945,
725 Count => 0,
726 Name_Len => Filename'Length);
727 ReadFC : File_Chunk;
728 Msg : Raw_Types.Serpent_Msg;
729 begin
730 -- fill FC with random content
731 FC.Filename := Filename;
732 RNG.Get_Octets(FC.Content);
733
734 -- write FC to message
735 Write_File_Transfer( FC, Msg );
736
737 -- read FC and check
738 Read_File_Transfer( Msg, ReadFC );
739
740 if FC /= ReadFC then
741 Put_Line("FAIL: read/write file chunk.");
742 else
743 Put_Line("PASS: read/write file chunk.");
744 end if;
745 end Serialize_File_Chunk;
746
747 procedure Converter_String_Octets is
748 Len: constant Natural := 234;
749 -- original values
750 S: String(1..Len);
751 O: Octets(1..Len);
752 -- converted values
753 CS: String(1..Len);
754 CO: Octets(1..Len);
755 begin
756 -- original octets
757 RNG.Get_Octets(O);
758 Octets_To_String(O, CS);
759 String_To_Octets(CS, CO);
760 if CO /= O then
761 Put_Line("FAIL: octets different after string/octets conversion.");
762 else
763 Put_Line("PASS: octets same after string/octets conversion.");
764 end if;
765
766 -- original string
767 for I in S'Range loop
768 S(I) := Character'Val(I mod 12);
769 end loop;
770 String_To_Octets(S, CO);
771 Octets_To_String(CO, CS);
772 if CS /= S then
773 Put_Line("FAIL: string different after string/octets conversion.");
774 else
775 Put_Line("PASS: string same after string/octets conversion.");
776 end if;
777 end Converter_String_Octets;
778
779 end Test_Serializing;
780
- E6F805434755B87ED7E265A405C3A505498AB7D154C47206DC3A7EC980EE58FD3DF2AF9DF762EA764F82DD59C7AC90F99F61E48B1B99A88D38762C497F816572
+ 77DFBF402E60B9CD4D8838421571BC7D018078B66C4B7D54C40BCAE20CD5554072704D6476659F19F8DD4BA82A3A006F1E0B5B2C2228AAA0ABAAA87C338C025A
smg_comms/tests/test_serializing.ads
(7 . 6)(7 . 10)
785
786 procedure Serialize_Keyset_SS;
787 procedure Serialize_Keys_Mgm;
788 procedure Serialize_File_Request( Reps: in Positive );
789 procedure Serialize_File_Chunk;
790
791 procedure Converter_String_Octets;
792
793 private
794
- 117663918D15B926ACF72A7AE5E3736AAB93B06A12148422D9A74DE147FB6E6F66961282CEC214A9F946E778DB1129BFDF14B184E63B84DF86E54A07312DF35A
+ 8CCD7A252824F3A0BA71E0B69FB36B7347146EA1B64AA0B297799717384C3FF1E954792EC2C4E1C762252A0C96AE46E438FE4CD541FA5A477C29B11C991B5775
smg_comms/tests/testall.adb
(16 . 4)(16 . 7)
799 Test_Packing.Test_Pack_Unpack_RSA;
800 Test_Serializing.Serialize_Keyset_SS;
801 Test_Serializing.Serialize_Keys_Mgm;
802 Test_Serializing.Serialize_File_Chunk;
803 Test_Serializing.Serialize_File_Request(5);
804 Test_Serializing.Converter_String_Octets;
805 end testall;