Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:33

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_MASK_IPP
0011 #define BOOST_BEAST_WEBSOCKET_DETAIL_MASK_IPP
0012 
0013 #include <boost/beast/websocket/detail/mask.hpp>
0014 
0015 namespace boost {
0016 namespace beast {
0017 namespace websocket {
0018 namespace detail {
0019 
0020 void
0021 prepare_key(prepared_key& prepared, std::uint32_t key)
0022 {
0023     prepared[0] = (key >>  0) & 0xff;
0024     prepared[1] = (key >>  8) & 0xff;
0025     prepared[2] = (key >> 16) & 0xff;
0026     prepared[3] = (key >> 24) & 0xff;
0027 }
0028 
0029 inline
0030 void
0031 rol(prepared_key& v, std::size_t n)
0032 {
0033     auto v0 = v;
0034     for(std::size_t i = 0; i < v.size(); ++i )
0035         v[i] = v0[(i + n) % v.size()];
0036 }
0037 
0038 // Apply mask in place
0039 //
0040 void
0041 mask_inplace(net::mutable_buffer const& b, prepared_key& key)
0042 {
0043     auto n = b.size();
0044     auto const mask = key; // avoid aliasing
0045     auto p = static_cast<unsigned char*>(b.data());
0046     while(n >= 4)
0047     {
0048         for(int i = 0; i < 4; ++i)
0049             p[i] ^= mask[i];
0050         p += 4;
0051         n -= 4;
0052     }
0053     if(n > 0)
0054     {
0055         for(std::size_t i = 0; i < n; ++i)
0056             p[i] ^= mask[i];
0057         rol(key, n);
0058     }
0059 }
0060 
0061 } // detail
0062 } // websocket
0063 } // beast
0064 } // boost
0065 
0066 #endif