mask.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_MASK_HPP
  10. #define BOOST_BEAST_WEBSOCKET_DETAIL_MASK_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/beast/core/buffers_range.hpp>
  13. #include <boost/asio/buffer.hpp>
  14. #include <array>
  15. #include <climits>
  16. #include <cstdint>
  17. #include <random>
  18. #include <type_traits>
  19. namespace boost {
  20. namespace beast {
  21. namespace websocket {
  22. namespace detail {
  23. using prepared_key = std::array<unsigned char, 4>;
  24. BOOST_BEAST_DECL
  25. void
  26. prepare_key(prepared_key& prepared, std::uint32_t key);
  27. // Apply mask in place
  28. //
  29. BOOST_BEAST_DECL
  30. void
  31. mask_inplace(net::mutable_buffer const& b, prepared_key& key);
  32. // Apply mask in place
  33. //
  34. template<class MutableBufferSequence>
  35. void
  36. mask_inplace(
  37. MutableBufferSequence const& buffers,
  38. prepared_key& key)
  39. {
  40. for(net::mutable_buffer b :
  41. beast::buffers_range_ref(buffers))
  42. detail::mask_inplace(b, key);
  43. }
  44. } // detail
  45. } // websocket
  46. } // beast
  47. } // boost
  48. #if BOOST_BEAST_HEADER_ONLY
  49. #include <boost/beast/websocket/detail/mask.ipp>
  50. #endif
  51. #endif