28 #define BOOST_TEST_MODULE frame 29 #include <boost/test/unit_test.hpp> 58 BOOST_CHECK( h1.
b0 == 0x80 );
61 BOOST_CHECK( h1.
b0 == 0xC0 );
64 BOOST_CHECK( h1.
b0 == 0xE0 );
67 BOOST_CHECK( h1.
b0 == 0xF0 );
70 BOOST_CHECK( h1.
b1 == 0x80 );
156 uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
160 uint8_t h2_solution[12] = {0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
164 uint8_t h3_solution[12] = {0x01, 0x00, 0x08, 0x04, 0x02, 0x01,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
168 uint8_t h4_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
169 0x02, 0x01, 0x00, 0x00, 0x00, 0x00};
172 uint8_t h5_solution[12] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
173 0x02, 0x01, 0x08, 0x04, 0x02, 0x01};
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) );
220 uint8_t s1[14] = {0x81, 0xFF,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
222 0xD5, 0xFB, 0x70, 0xEE};
224 BOOST_CHECK( p1.size() == 14);
225 BOOST_CHECK( std::equal(p1.begin(),p1.end(),
reinterpret_cast<char*
>(s1)) );
230 uint8_t s2[4] = {0x81, 0x7E, 0x00, 0xFF};
232 BOOST_CHECK( p2.size() == 4);
233 BOOST_CHECK( std::equal(p2.begin(),p2.end(),
reinterpret_cast<char*
>(s2)) );
239 key.
i = htonl(0x12345678);
241 if (
sizeof(
size_t) == 8) {
253 key.
i = htonl(0xD5FB70EE);
256 if (
sizeof(
size_t) == 8) {
285 uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00,
292 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
293 0x00, 0x01, 0x02, 0x03,
294 0x00, 0x01, 0x02, 0x03,
305 BOOST_CHECK( std::equal(output,output+15,masked) );
309 uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00,
314 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
315 0x00, 0x01, 0x02, 0x03,
316 0x00, 0x01, 0x02, 0x03,
327 BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
331 uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00,
333 0x00, 0x00, 0x00, 0x00,
338 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
339 0x00, 0x01, 0x02, 0x03,
340 0x00, 0x01, 0x02, 0x03,
351 BOOST_CHECK( std::equal(output,output+15,masked) );
355 uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00,
360 uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
361 0x00, 0x01, 0x02, 0x03,
362 0x00, 0x01, 0x02, 0x03,
373 BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
380 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
381 0x00, 0x01, 0x02, 0x03,
382 0x00, 0x01, 0x02, 0x03,
383 0x00, 0x01, 0x02, 0x00};
392 size_t pkey,pkey_temp;
394 std::fill_n(input,16,0x00);
395 std::fill_n(output,16,0x00);
397 BOOST_CHECK( std::equal(output,output+16,masked) );
401 std::fill_n(input,16,0x00);
402 std::fill_n(output,16,0x00);
405 BOOST_CHECK( std::equal(output,output+7,masked) );
409 BOOST_CHECK( std::equal(output,output+16,masked) );
417 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
418 0x00, 0x01, 0x02, 0x03,
419 0x00, 0x01, 0x02, 0x03,
420 0x00, 0x01, 0x02, 0x00};
429 size_t pkey,pkey_temp;
431 std::fill_n(input,16,0x00);
432 std::fill_n(output,16,0x00);
434 BOOST_CHECK( std::equal(output,output+16,masked) );
438 std::fill_n(input,16,0x00);
439 std::fill_n(output,16,0x00);
442 BOOST_CHECK( std::equal(output,output+7,masked) );
446 BOOST_CHECK( std::equal(output,output+16,masked) );
453 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
454 0x00, 0x01, 0x02, 0x03,
455 0x00, 0x01, 0x02, 0x03,
456 0x00, 0x01, 0x02, 0x00};
465 size_t pkey,pkey_temp;
467 std::fill_n(buffer,16,0x00);
469 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
473 std::fill_n(buffer,16,0x00);
476 BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
480 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
487 uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
488 0x00, 0x01, 0x02, 0x03,
489 0x00, 0x01, 0x02, 0x03,
490 0x00, 0x01, 0x02, 0x00};
499 size_t pkey,pkey_temp;
501 std::fill_n(buffer,16,0x00);
503 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
507 std::fill_n(buffer,16,0x00);
510 BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
514 BOOST_CHECK( std::equal(buffer,buffer+16,masked) );
519 uint8_t buffer[12] = {0xA6, 0x15, 0x97, 0xB9,
520 0x81, 0x50, 0xAC, 0xBA,
521 0x9C, 0x1C, 0x9F, 0xF4};
523 uint8_t unmasked[12] = {0x48, 0x65, 0x6C, 0x6C,
524 0x6F, 0x20, 0x57, 0x6F,
525 0x72, 0x6C, 0x64, 0x21};
537 BOOST_CHECK( std::equal(buffer,buffer+12,unmasked) );
bool is_control(value v)
Check if an opcode is for a control frame.
bool get_rsv1(basic_header const &h)
check whether the frame's RSV1 bit is set
void set_rsv1(basic_header &h, bool value)
Set the frame's RSV1 bit.
bool get_rsv3(basic_header const &h)
check whether the frame's RSV3 bit is set
bool get_masked(basic_header const &h)
check whether the frame is masked
uint16_t get_extended_size(extended_header const &)
Extract the extended size field from an extended header.
bool get_rsv2(basic_header const &h)
check whether the frame's RSV2 bit is set
opcode::value get_opcode(basic_header const &h)
Extract opcode from basic header.
uint64_t _htonll(uint64_t src)
Convert 64 bit value to network byte order.
masking_key_type get_masking_key(basic_header const &, extended_header const &)
Extract the masking key from a frame header.
BOOST_AUTO_TEST_CASE(basic_bits)
Four byte conversion union.
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.
size_t get_header_len(basic_header const &)
Calculates the full length of the header based on the first bytes.
size_t circshift_prepared_key(size_t prepared_key, size_t offset)
circularly shifts the supplied prepared masking key by offset bytes
static unsigned int const basic_header_length
Minimum length of a WebSocket frame header.
size_t word_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular word aligned mask/unmask.
void word_mask_exact(uint8_t *input, uint8_t *output, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask.
size_t prepare_masking_key(masking_key_type const &key)
Extract a masking key into a value the size of a machine word.
uint8_t get_basic_size(basic_header const &)
Extracts the raw payload length specified in the basic header.
uint64_t get_jumbo_size(extended_header const &)
Extract the jumbo size field from an extended header.
Namespace for the WebSocket++ project.
uint64_t get_payload_size(basic_header const &, extended_header const &)
Extract the full payload size field from a WebSocket header.
unsigned int get_masking_key_offset(basic_header const &)
Calculate the offset location of the masking key within the extended header.
void set_masked(basic_header &h, bool value)
Set the frame's MASK bit.
std::string prepare_header(const basic_header &h, const extended_header &e)
Generate a properly sized contiguous string that encodes a full frame header.
size_t byte_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask.
void set_fin(basic_header &h, bool value)
Set the frame's FIN bit.
bool get_fin(basic_header const &h)
Check whether the frame's FIN bit is set.
void set_rsv2(basic_header &h, bool value)
Set the frame's RSV2 bit.
void set_rsv3(basic_header &h, bool value)
Set the frame's RSV3 bit.