Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
frame.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <websocketpp/frame.hpp>
#include <websocketpp/utilities.hpp>
Include dependency graph for frame.cpp:

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   frame
 

Functions

 BOOST_AUTO_TEST_CASE (basic_bits)
 
 BOOST_AUTO_TEST_CASE (basic_constructors)
 
 BOOST_AUTO_TEST_CASE (basic_size)
 
 BOOST_AUTO_TEST_CASE (basic_header_length)
 
 BOOST_AUTO_TEST_CASE (basic_opcode)
 
 BOOST_AUTO_TEST_CASE (extended_header_basics)
 
 BOOST_AUTO_TEST_CASE (extended_header_extractors)
 
 BOOST_AUTO_TEST_CASE (header_preparation)
 
 BOOST_AUTO_TEST_CASE (prepare_masking_key)
 
 BOOST_AUTO_TEST_CASE (prepare_masking_key2)
 
 BOOST_AUTO_TEST_CASE (circshift)
 
 BOOST_AUTO_TEST_CASE (block_byte_mask)
 
 BOOST_AUTO_TEST_CASE (block_byte_mask_inplace)
 
 BOOST_AUTO_TEST_CASE (block_word_mask)
 
 BOOST_AUTO_TEST_CASE (block_word_mask_inplace)
 
 BOOST_AUTO_TEST_CASE (continuous_word_mask)
 
 BOOST_AUTO_TEST_CASE (continuous_byte_mask)
 
 BOOST_AUTO_TEST_CASE (continuous_word_mask_inplace)
 
 BOOST_AUTO_TEST_CASE (continuous_byte_mask_inplace)
 
 BOOST_AUTO_TEST_CASE (continuous_word_mask2)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   frame

Definition at line 28 of file frame.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/20]

BOOST_AUTO_TEST_CASE ( basic_bits )

Definition at line 39 of file frame.cpp.

39 {
40 frame::basic_header h1(0x00,0x00); // all false
41 frame::basic_header h2(0xF0,0x80); // all true
42
43 // Read Values
44 BOOST_CHECK( frame::get_fin(h1) == false );
45 BOOST_CHECK( frame::get_rsv1(h1) == false );
46 BOOST_CHECK( frame::get_rsv2(h1) == false );
47 BOOST_CHECK( frame::get_rsv3(h1) == false );
48 BOOST_CHECK( frame::get_masked(h1) == false );
49
50 BOOST_CHECK( frame::get_fin(h2) == true );
51 BOOST_CHECK( frame::get_rsv1(h2) == true );
52 BOOST_CHECK( frame::get_rsv2(h2) == true );
53 BOOST_CHECK( frame::get_rsv3(h2) == true );
54 BOOST_CHECK( frame::get_masked(h2) == true );
55
56 // Set Values
57 frame::set_fin(h1,true);
58 BOOST_CHECK( h1.b0 == 0x80 );
59
60 frame::set_rsv1(h1,true);
61 BOOST_CHECK( h1.b0 == 0xC0 );
62
63 frame::set_rsv2(h1,true);
64 BOOST_CHECK( h1.b0 == 0xE0 );
65
66 frame::set_rsv3(h1,true);
67 BOOST_CHECK( h1.b0 == 0xF0 );
68
69 frame::set_masked(h1,true);
70 BOOST_CHECK( h1.b1 == 0x80 );
71}
void set_rsv2(basic_header &h, bool value)
Set the frame's RSV2 bit.
Definition frame.hpp:366
void set_rsv3(basic_header &h, bool value)
Set the frame's RSV3 bit.
Definition frame.hpp:384
bool get_rsv3(basic_header const &h)
check whether the frame's RSV3 bit is set
Definition frame.hpp:375
bool get_masked(basic_header const &h)
check whether the frame is masked
Definition frame.hpp:402
bool get_rsv2(basic_header const &h)
check whether the frame's RSV2 bit is set
Definition frame.hpp:357
bool get_fin(basic_header const &h)
Check whether the frame's FIN bit is set.
Definition frame.hpp:321
bool get_rsv1(basic_header const &h)
check whether the frame's RSV1 bit is set
Definition frame.hpp:339
void set_masked(basic_header &h, bool value)
Set the frame's MASK bit.
Definition frame.hpp:411
void set_rsv1(basic_header &h, bool value)
Set the frame's RSV1 bit.
Definition frame.hpp:348
void set_fin(basic_header &h, bool value)
Set the frame's FIN bit.
Definition frame.hpp:330
The constant size component of a WebSocket frame header.
Definition frame.hpp:189
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/20]

BOOST_AUTO_TEST_CASE ( basic_constructors )

Definition at line 73 of file frame.cpp.

73 {
74 // Read Values
76 BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::TEXT );
77 BOOST_CHECK( frame::get_basic_size(h1) == 12 );
78 BOOST_CHECK( frame::get_fin(h1) == true );
79 BOOST_CHECK( frame::get_rsv1(h1) == false );
80 BOOST_CHECK( frame::get_rsv2(h1) == false );
81 BOOST_CHECK( frame::get_rsv3(h1) == false );
82 BOOST_CHECK( frame::get_masked(h1) == false );
83
84 frame::basic_header h2(frame::opcode::BINARY,0,false,false,false,true);
85 BOOST_CHECK( frame::get_opcode(h2) == frame::opcode::BINARY );
86 BOOST_CHECK( frame::get_basic_size(h2) == 0 );
87 BOOST_CHECK( frame::get_fin(h2) == false );
88 BOOST_CHECK( frame::get_rsv1(h2) == false );
89 BOOST_CHECK( frame::get_rsv2(h2) == true );
90 BOOST_CHECK( frame::get_rsv3(h2) == false );
91 BOOST_CHECK( frame::get_masked(h2) == false );
92}
opcode::value get_opcode(basic_header const &h)
Extract opcode from basic header.
Definition frame.hpp:393
uint8_t get_basic_size(basic_header const &)
Extracts the raw payload length specified in the basic header.
Definition frame.hpp:431
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/20]

BOOST_AUTO_TEST_CASE ( basic_header_length )

Definition at line 125 of file frame.cpp.

125 {
126 frame::basic_header h1(0x82,0x00); // short binary frame, unmasked
127 frame::basic_header h2(0x82,0x80); // short binary frame, masked
128 frame::basic_header h3(0x82,0x7E); // medium binary frame, unmasked
129 frame::basic_header h4(0x82,0xFE); // medium binary frame, masked
130 frame::basic_header h5(0x82,0x7F); // jumbo binary frame, unmasked
131 frame::basic_header h6(0x82,0xFF); // jumbo binary frame, masked
132
133 BOOST_CHECK( frame::get_header_len(h1) == 2);
134 BOOST_CHECK( frame::get_header_len(h2) == 6);
135 BOOST_CHECK( frame::get_header_len(h3) == 4);
136 BOOST_CHECK( frame::get_header_len(h4) == 8);
137 BOOST_CHECK( frame::get_header_len(h5) == 10);
138 BOOST_CHECK( frame::get_header_len(h6) == 14);
139}
size_t get_header_len(basic_header const &)
Calculates the full length of the header based on the first bytes.
Definition frame.hpp:445
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/20]

BOOST_AUTO_TEST_CASE ( basic_opcode )

Definition at line 141 of file frame.cpp.

141 {
142 frame::basic_header h1(0x00,0x00);
143
144 BOOST_CHECK( is_control(frame::opcode::CONTINUATION) == false);
145 BOOST_CHECK( is_control(frame::opcode::TEXT) == false);
146 BOOST_CHECK( is_control(frame::opcode::BINARY) == false);
147 BOOST_CHECK( is_control(frame::opcode::CLOSE) == true);
148 BOOST_CHECK( is_control(frame::opcode::PING) == true);
149 BOOST_CHECK( is_control(frame::opcode::PONG) == true);
150
152}
bool is_control(value v)
Check if an opcode is for a control frame.
Definition frame.hpp:139
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/20]

BOOST_AUTO_TEST_CASE ( basic_size )

Definition at line 94 of file frame.cpp.

94 {
95 frame::basic_header h1(0x00,0x00); // length 0
96 frame::basic_header h2(0x00,0x01); // length 1
97 frame::basic_header h3(0x00,0x7D); // length 125
98 frame::basic_header h4(0x00,0x7E); // length 126
99 frame::basic_header h5(0x00,0x7F); // length 127
100 frame::basic_header h6(0x00,0x80); // length 0, mask bit set
101
102 BOOST_CHECK( frame::get_basic_size(h1) == 0 );
103 BOOST_CHECK( frame::get_basic_size(h2) == 1 );
104 BOOST_CHECK( frame::get_basic_size(h3) == 125 );
105 BOOST_CHECK( frame::get_basic_size(h4) == 126 );
106 BOOST_CHECK( frame::get_basic_size(h5) == 127 );
107 BOOST_CHECK( frame::get_basic_size(h6) == 0 );
108
109 /*frame::set_basic_size(h1,1);
110 BOOST_CHECK( h1.b1 == 0x01 );
111
112 frame::set_basic_size(h1,125);
113 BOOST_CHECK( h1.b1 == 0x7D );
114
115 frame::set_basic_size(h1,126);
116 BOOST_CHECK( h1.b1 == 0x7E );
117
118 frame::set_basic_size(h1,127);
119 BOOST_CHECK( h1.b1 == 0x7F );
120
121 frame::set_basic_size(h1,0);
122 BOOST_CHECK( h1.b1 == 0x00 );*/
123}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/20]

BOOST_AUTO_TEST_CASE ( block_byte_mask )

Definition at line 284 of file frame.cpp.

284 {
285 uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00};
289
290 uint8_t output[15];
291
292 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
293 0x00, 0x01, 0x02, 0x03,
294 0x00, 0x01, 0x02, 0x03,
295 0x00, 0x01, 0x02};
296
298 key.c[0] = 0x00;
299 key.c[1] = 0x01;
300 key.c[2] = 0x02;
301 key.c[3] = 0x03;
302
303 byte_mask(input,input+15,output,key);
304
305 BOOST_CHECK( std::equal(output,output+15,masked) );
306}
void byte_mask(input_iter b, input_iter e, output_iter o, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask.
Definition frame.hpp:642
unsigned char uint8_t
Definition stdint.h:124
Four byte conversion union.
Definition frame.hpp:61
uint8_t key[16]
Definition yubico_otp.c:41

◆ BOOST_AUTO_TEST_CASE() [7/20]

BOOST_AUTO_TEST_CASE ( block_byte_mask_inplace )

Definition at line 308 of file frame.cpp.

308 {
309 uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00};
313
314 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
315 0x00, 0x01, 0x02, 0x03,
316 0x00, 0x01, 0x02, 0x03,
317 0x00, 0x01, 0x02};
318
320 key.c[0] = 0x00;
321 key.c[1] = 0x01;
322 key.c[2] = 0x02;
323 key.c[3] = 0x03;
324
325 byte_mask(buffer,buffer+15,key);
326
327 BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
328}

◆ BOOST_AUTO_TEST_CASE() [8/20]

BOOST_AUTO_TEST_CASE ( block_word_mask )

Definition at line 330 of file frame.cpp.

330 {
331 uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00,
333 0x00, 0x00, 0x00, 0x00,
334 0x00, 0x00, 0x00};
335
336 uint8_t output[15];
337
338 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
339 0x00, 0x01, 0x02, 0x03,
340 0x00, 0x01, 0x02, 0x03,
341 0x00, 0x01, 0x02};
342
344 key.c[0] = 0x00;
345 key.c[1] = 0x01;
346 key.c[2] = 0x02;
347 key.c[3] = 0x03;
348
349 word_mask_exact(input,output,15,key);
350
351 BOOST_CHECK( std::equal(output,output+15,masked) );
352}
void word_mask_exact(uint8_t *input, uint8_t *output, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask.
Definition frame.hpp:699

◆ BOOST_AUTO_TEST_CASE() [9/20]

BOOST_AUTO_TEST_CASE ( block_word_mask_inplace )

Definition at line 354 of file frame.cpp.

354 {
355 uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00,
358 0x00, 0x00, 0x00};
359
360 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
361 0x00, 0x01, 0x02, 0x03,
362 0x00, 0x01, 0x02, 0x03,
363 0x00, 0x01, 0x02};
364
366 key.c[0] = 0x00;
367 key.c[1] = 0x01;
368 key.c[2] = 0x02;
369 key.c[3] = 0x03;
370
371 word_mask_exact(buffer,15,key);
372
373 BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
374}

◆ BOOST_AUTO_TEST_CASE() [10/20]

BOOST_AUTO_TEST_CASE ( circshift )

Definition at line 266 of file frame.cpp.

266 {
267 /*if (sizeof(size_t) == 8) {
268 size_t test = 0x0123456789abcdef;
269
270 BOOST_CHECK( frame::circshift_prepared_key(test,0) == 0x0123456789abcdef);
271 BOOST_CHECK( frame::circshift_prepared_key(test,1) == 0xef0123456789abcd);
272 BOOST_CHECK( frame::circshift_prepared_key(test,2) == 0xcdef0123456789ab);
273 BOOST_CHECK( frame::circshift_prepared_key(test,3) == 0xabcdef0123456789);
274 } else {
275 size_t test = 0x01234567;
276
277 BOOST_CHECK( frame::circshift_prepared_key(test,0) == 0x01234567);
278 BOOST_CHECK( frame::circshift_prepared_key(test,1) == 0x67012345);
279 BOOST_CHECK( frame::circshift_prepared_key(test,2) == 0x45670123);
280 BOOST_CHECK( frame::circshift_prepared_key(test,3) == 0x23456701);
281 }*/
282}

◆ BOOST_AUTO_TEST_CASE() [11/20]

BOOST_AUTO_TEST_CASE ( continuous_byte_mask )

Definition at line 413 of file frame.cpp.

413 {
414 uint8_t input[16];
415 uint8_t output[16];
416
417 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
418 0x00, 0x01, 0x02, 0x03,
419 0x00, 0x01, 0x02, 0x03,
420 0x00, 0x01, 0x02, 0x00};
421
423 key.c[0] = 0x00;
424 key.c[1] = 0x01;
425 key.c[2] = 0x02;
426 key.c[3] = 0x03;
427
428 // One call
429 size_t pkey,pkey_temp;
430 pkey = frame::prepare_masking_key(key);
431 std::fill_n(input,16,0x00);
432 std::fill_n(output,16,0x00);
433 frame::byte_mask_circ(input,output,15,pkey);
434 BOOST_CHECK( std::equal(output,output+16,masked) );
435
436 // calls not split on word boundaries
437 pkey = frame::prepare_masking_key(key);
438 std::fill_n(input,16,0x00);
439 std::fill_n(output,16,0x00);
440
441 pkey_temp = frame::byte_mask_circ(input,output,7,pkey);
442 BOOST_CHECK( std::equal(output,output+7,masked) );
443 BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
444
445 pkey_temp = frame::byte_mask_circ(input+7,output+7,8,pkey_temp);
446 BOOST_CHECK( std::equal(output,output+16,masked) );
447 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
448}
size_t byte_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask.
Definition frame.hpp:827
size_t circshift_prepared_key(size_t prepared_key, size_t offset)
circularly shifts the supplied prepared masking key by offset bytes
Definition frame.hpp:612
size_t prepare_masking_key(masking_key_type const &key)
Extract a masking key into a value the size of a machine word.
Definition frame.hpp:595
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [12/20]

BOOST_AUTO_TEST_CASE ( continuous_byte_mask_inplace )

Definition at line 484 of file frame.cpp.

484 {
485 uint8_t buffer[16];
486
487 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
488 0x00, 0x01, 0x02, 0x03,
489 0x00, 0x01, 0x02, 0x03,
490 0x00, 0x01, 0x02, 0x00};
491
493 key.c[0] = 0x00;
494 key.c[1] = 0x01;
495 key.c[2] = 0x02;
496 key.c[3] = 0x03;
497
498 // One call
499 size_t pkey,pkey_temp;
500 pkey = frame::prepare_masking_key(key);
501 std::fill_n(buffer,16,0x00);
502 frame::byte_mask_circ(buffer,15,pkey);
503 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
504
505 // calls not split on word boundaries
506 pkey = frame::prepare_masking_key(key);
507 std::fill_n(buffer,16,0x00);
508
509 pkey_temp = frame::byte_mask_circ(buffer,7,pkey);
510 BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
511 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
512
513 pkey_temp = frame::byte_mask_circ(buffer+7,8,pkey_temp);
514 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
515 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
516}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [13/20]

BOOST_AUTO_TEST_CASE ( continuous_word_mask )

Definition at line 376 of file frame.cpp.

376 {
377 uint8_t input[16];
378 uint8_t output[16];
379
380 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
381 0x00, 0x01, 0x02, 0x03,
382 0x00, 0x01, 0x02, 0x03,
383 0x00, 0x01, 0x02, 0x00};
384
386 key.c[0] = 0x00;
387 key.c[1] = 0x01;
388 key.c[2] = 0x02;
389 key.c[3] = 0x03;
390
391 // One call
392 size_t pkey,pkey_temp;
393 pkey = frame::prepare_masking_key(key);
394 std::fill_n(input,16,0x00);
395 std::fill_n(output,16,0x00);
396 frame::word_mask_circ(input,output,15,pkey);
397 BOOST_CHECK( std::equal(output,output+16,masked) );
398
399 // calls not split on word boundaries
400 pkey = frame::prepare_masking_key(key);
401 std::fill_n(input,16,0x00);
402 std::fill_n(output,16,0x00);
403
404 pkey_temp = frame::word_mask_circ(input,output,7,pkey);
405 BOOST_CHECK( std::equal(output,output+7,masked) );
406 BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
407
408 pkey_temp = frame::word_mask_circ(input+7,output+7,8,pkey_temp);
409 BOOST_CHECK( std::equal(output,output+16,masked) );
410 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
411}
size_t word_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular word aligned mask/unmask.
Definition frame.hpp:765
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [14/20]

BOOST_AUTO_TEST_CASE ( continuous_word_mask2 )

Definition at line 518 of file frame.cpp.

518 {
519 uint8_t buffer[12] = {0xA6, 0x15, 0x97, 0xB9,
520 0x81, 0x50, 0xAC, 0xBA,
521 0x9C, 0x1C, 0x9F, 0xF4};
522
523 uint8_t unmasked[12] = {0x48, 0x65, 0x6C, 0x6C,
524 0x6F, 0x20, 0x57, 0x6F,
525 0x72, 0x6C, 0x64, 0x21};
526
528 key.c[0] = 0xEE;
529 key.c[1] = 0x70;
530 key.c[2] = 0xFB;
531 key.c[3] = 0xD5;
532
533 // One call
534 size_t pkey;
535 pkey = frame::prepare_masking_key(key);
536 frame::word_mask_circ(buffer,12,pkey);
537 BOOST_CHECK( std::equal(buffer,buffer+12,unmasked) );
538}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [15/20]

BOOST_AUTO_TEST_CASE ( continuous_word_mask_inplace )

Definition at line 450 of file frame.cpp.

450 {
451 uint8_t buffer[16];
452
453 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
454 0x00, 0x01, 0x02, 0x03,
455 0x00, 0x01, 0x02, 0x03,
456 0x00, 0x01, 0x02, 0x00};
457
459 key.c[0] = 0x00;
460 key.c[1] = 0x01;
461 key.c[2] = 0x02;
462 key.c[3] = 0x03;
463
464 // One call
465 size_t pkey,pkey_temp;
466 pkey = frame::prepare_masking_key(key);
467 std::fill_n(buffer,16,0x00);
468 frame::word_mask_circ(buffer,15,pkey);
469 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
470
471 // calls not split on word boundaries
472 pkey = frame::prepare_masking_key(key);
473 std::fill_n(buffer,16,0x00);
474
475 pkey_temp = frame::word_mask_circ(buffer,7,pkey);
476 BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
477 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
478
479 pkey_temp = frame::word_mask_circ(buffer+7,8,pkey_temp);
480 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
481 BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
482}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [16/20]

BOOST_AUTO_TEST_CASE ( extended_header_basics )

Definition at line 154 of file frame.cpp.

154 {
156 uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
158
160 uint8_t h2_solution[12] = {0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
162
163 frame::extended_header h3(uint16_t(256),htonl(0x8040201));
164 uint8_t h3_solution[12] = {0x01, 0x00, 0x08, 0x04, 0x02, 0x01,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
166
167 frame::extended_header h4(uint64_t(0x0807060504030201LL));
168 uint8_t h4_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
169 0x02, 0x01, 0x00, 0x00, 0x00, 0x00};
170
171 frame::extended_header h5(uint64_t(0x0807060504030201LL),htonl(0x8040201));
172 uint8_t h5_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
173 0x02, 0x01, 0x08, 0x04, 0x02, 0x01};
174
175 BOOST_CHECK( std::equal(h1_solution,h1_solution+12,h1.bytes) );
176 BOOST_CHECK( std::equal(h2_solution,h2_solution+12,h2.bytes) );
177 BOOST_CHECK( std::equal(h3_solution,h3_solution+12,h3.bytes) );
178 BOOST_CHECK( std::equal(h4_solution,h4_solution+12,h4.bytes) );
179 BOOST_CHECK( std::equal(h5_solution,h5_solution+12,h5.bytes) );
180}
unsigned short uint16_t
Definition stdint.h:125
unsigned __int64 uint64_t
Definition stdint.h:136
The variable size component of a WebSocket frame header.
Definition frame.hpp:235
uint8_t bytes[MAX_EXTENDED_HEADER_LENGTH]
Definition frame.hpp:258

◆ BOOST_AUTO_TEST_CASE() [17/20]

BOOST_AUTO_TEST_CASE ( extended_header_extractors )

Definition at line 182 of file frame.cpp.

182 {
183 frame::basic_header h1(0x00,0x7E);
185 BOOST_CHECK( get_extended_size(e1) == 255 );
186 BOOST_CHECK( get_payload_size(h1,e1) == 255 );
187 BOOST_CHECK( get_masking_key_offset(h1) == 2 );
188 BOOST_CHECK( get_masking_key(h1,e1).i == 0 );
189
190 frame::basic_header h2(0x00,0x7F);
191 frame::extended_header e2(uint64_t(0x0807060504030201LL));
192 BOOST_CHECK( get_jumbo_size(e2) == 0x0807060504030201LL );
193 BOOST_CHECK( get_payload_size(h2,e2) == 0x0807060504030201LL );
194 BOOST_CHECK( get_masking_key_offset(h2) == 8 );
195 BOOST_CHECK( get_masking_key(h2,e2).i == 0 );
196
197 frame::basic_header h3(0x00,0xFE);
198 frame::extended_header e3(uint16_t(255),0x08040201);
199 BOOST_CHECK( get_extended_size(e3) == 255 );
200 BOOST_CHECK( get_payload_size(h3,e3) == 255 );
201 BOOST_CHECK( get_masking_key_offset(h3) == 2 );
202 BOOST_CHECK( get_masking_key(h3,e3).i == 0x08040201 );
203
204 frame::basic_header h4(0x00,0xFF);
205 frame::extended_header e4(uint64_t(0x0807060504030201LL),0x08040201);
206 BOOST_CHECK( get_jumbo_size(e4) == 0x0807060504030201LL );
207 BOOST_CHECK( get_payload_size(h4,e4) == 0x0807060504030201LL );
208 BOOST_CHECK( get_masking_key_offset(h4) == 8 );
209 BOOST_CHECK( get_masking_key(h4,e4).i == 0x08040201 );
210
211 frame::basic_header h5(0x00,0x7D);
213 BOOST_CHECK( get_payload_size(h5,e5) == 125 );
214}
unsigned int get_masking_key_offset(basic_header const &)
Calculate the offset location of the masking key within the extended header.
Definition frame.hpp:469
uint64_t get_payload_size(basic_header const &, extended_header const &)
Extract the full payload size field from a WebSocket header.
Definition frame.hpp:573
uint16_t get_extended_size(extended_header const &)
Extract the extended size field from an extended header.
Definition frame.hpp:540
uint64_t get_jumbo_size(extended_header const &)
Extract the jumbo size field from an extended header.
Definition frame.hpp:555
masking_key_type get_masking_key(basic_header const &, extended_header const &)
Extract the masking key from a frame header.
Definition frame.hpp:516

◆ BOOST_AUTO_TEST_CASE() [18/20]

BOOST_AUTO_TEST_CASE ( header_preparation )

Definition at line 216 of file frame.cpp.

216 {
217 frame::basic_header h1(0x81,0xFF); //
218 frame::extended_header e1(uint64_t(0xFFFFFLL),htonl(0xD5FB70EE));
219 std::string p1 = prepare_header(h1, e1);
220 uint8_t s1[14] = {0x81, 0xFF,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
222 0xD5, 0xFB, 0x70, 0xEE};
223
224 BOOST_CHECK( p1.size() == 14);
225 BOOST_CHECK( std::equal(p1.begin(),p1.end(),reinterpret_cast<char*>(s1)) );
226
227 frame::basic_header h2(0x81,0x7E); //
229 std::string p2 = prepare_header(h2, e2);
230 uint8_t s2[4] = {0x81, 0x7E, 0x00, 0xFF};
231
232 BOOST_CHECK( p2.size() == 4);
233 BOOST_CHECK( std::equal(p2.begin(),p2.end(),reinterpret_cast<char*>(s2)) );
234}
std::string prepare_header(const basic_header &h, const extended_header &e)
Generate a properly sized contiguous string that encodes a full frame header.
Definition frame.hpp:489

◆ BOOST_AUTO_TEST_CASE() [19/20]

BOOST_AUTO_TEST_CASE ( prepare_masking_key )

Definition at line 236 of file frame.cpp.

236 {
238
239 key.i = htonl(0x12345678);
240
241 if (sizeof(size_t) == 8) {
242 BOOST_CHECK(
243 frame::prepare_masking_key(key) == lib::net::_htonll(0x1234567812345678LL)
244 );
245 } else {
246 BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0x12345678) );
247 }
248}
uint64_t _htonll(uint64_t src)
Convert 64 bit value to network byte order.
Definition network.hpp:66
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [20/20]

BOOST_AUTO_TEST_CASE ( prepare_masking_key2 )

Definition at line 250 of file frame.cpp.

250 {
252
253 key.i = htonl(0xD5FB70EE);
254
255 // One call
256 if (sizeof(size_t) == 8) {
257 BOOST_CHECK(
258 frame::prepare_masking_key(key) == lib::net::_htonll(0xD5FB70EED5FB70EELL)
259 );
260 } else {
261 BOOST_CHECK( frame::prepare_masking_key(key) == htonl(0xD5FB70EE) );
262 }
263}
Here is the call graph for this function: