NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
frame.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Peter Thorson. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the WebSocket++ Project nor the
12  * names of its contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 //#define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_MODULE frame
29 #include <boost/test/unit_test.hpp>
30 
31 #include <iostream>
32 #include <string>
33 
34 #include <websocketpp/frame.hpp>
36 
37 using namespace websocketpp;
38 
39 BOOST_AUTO_TEST_CASE( basic_bits ) {
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 }
72 
73 BOOST_AUTO_TEST_CASE( basic_constructors ) {
74  // Read Values
75  frame::basic_header h1(frame::opcode::TEXT,12,true,false);
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 }
93 
94 BOOST_AUTO_TEST_CASE( basic_size ) {
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 }
124 
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 }
140 
141 BOOST_AUTO_TEST_CASE( basic_opcode ) {
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 
151  BOOST_CHECK( frame::get_opcode(h1) == frame::opcode::CONTINUATION );
152 }
153 
154 BOOST_AUTO_TEST_CASE( extended_header_basics ) {
156  uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157  0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
158 
159  frame::extended_header h2(uint16_t(255));
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 }
181 
182 BOOST_AUTO_TEST_CASE( extended_header_extractors ) {
183  frame::basic_header h1(0x00,0x7E);
184  frame::extended_header e1(uint16_t(255));
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 }
215 
216 BOOST_AUTO_TEST_CASE( header_preparation ) {
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); //
228  frame::extended_header e2(uint16_t(255));
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 }
235 
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 }
249 
250 BOOST_AUTO_TEST_CASE( prepare_masking_key2 ) {
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 }
264 
265 // TODO: figure out a way to run/test both 4 and 8 byte versions.
266 BOOST_AUTO_TEST_CASE( circshift ) {
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 }
283 
284 BOOST_AUTO_TEST_CASE( block_byte_mask ) {
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 }
307 
308 BOOST_AUTO_TEST_CASE( block_byte_mask_inplace ) {
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 }
329 
330 BOOST_AUTO_TEST_CASE( block_word_mask ) {
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 }
353 
354 BOOST_AUTO_TEST_CASE( block_word_mask_inplace ) {
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 }
375 
376 BOOST_AUTO_TEST_CASE( continuous_word_mask ) {
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 }
412 
413 BOOST_AUTO_TEST_CASE( continuous_byte_mask ) {
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 }
449 
450 BOOST_AUTO_TEST_CASE( continuous_word_mask_inplace ) {
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 }
483 
484 BOOST_AUTO_TEST_CASE( continuous_byte_mask_inplace ) {
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 }
517 
518 BOOST_AUTO_TEST_CASE( continuous_word_mask2 ) {
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 }
bool is_control(value v)
Check if an opcode is for a control frame.
Definition: frame.hpp:139
bool get_rsv1(basic_header const &h)
check whether the frame&#39;s RSV1 bit is set
Definition: frame.hpp:339
void set_rsv1(basic_header &h, bool value)
Set the frame&#39;s RSV1 bit.
Definition: frame.hpp:348
bool get_rsv3(basic_header const &h)
check whether the frame&#39;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
uint16_t get_extended_size(extended_header const &)
Extract the extended size field from an extended header.
Definition: frame.hpp:540
bool get_rsv2(basic_header const &h)
check whether the frame&#39;s RSV2 bit is set
Definition: frame.hpp:357
opcode::value get_opcode(basic_header const &h)
Extract opcode from basic header.
Definition: frame.hpp:393
uint64_t _htonll(uint64_t src)
Convert 64 bit value to network byte order.
Definition: network.hpp:66
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(basic_bits)
Definition: frame.cpp:39
Four byte conversion union.
Definition: frame.hpp:61
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:645
size_t get_header_len(basic_header const &)
Calculates the full length of the header based on the first bytes.
Definition: frame.hpp:445
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
static unsigned int const basic_header_length
Minimum length of a WebSocket frame header.
Definition: frame.hpp:147
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:768
The constant size component of a WebSocket frame header.
Definition: frame.hpp:189
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:702
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
uint8_t get_basic_size(basic_header const &)
Extracts the raw payload length specified in the basic header.
Definition: frame.hpp:431
uint64_t get_jumbo_size(extended_header const &)
Extract the jumbo size field from an extended header.
Definition: frame.hpp:555
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
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
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
The variable size component of a WebSocket frame header.
Definition: frame.hpp:235
void set_masked(basic_header &h, bool value)
Set the frame&#39;s MASK bit.
Definition: frame.hpp:411
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
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:830
void set_fin(basic_header &h, bool value)
Set the frame&#39;s FIN bit.
Definition: frame.hpp:330
bool get_fin(basic_header const &h)
Check whether the frame&#39;s FIN bit is set.
Definition: frame.hpp:321
void set_rsv2(basic_header &h, bool value)
Set the frame&#39;s RSV2 bit.
Definition: frame.hpp:366
uint8_t bytes[MAX_EXTENDED_HEADER_LENGTH]
Definition: frame.hpp:258
void set_rsv3(basic_header &h, bool value)
Set the frame&#39;s RSV3 bit.
Definition: frame.hpp:384