2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
8 #ifndef BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
9 #define BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
11 #include <beast/core/detail/base64.hpp>
12 #include <beast/core/detail/sha1.hpp>
13 #include <boost/utility/string_ref.hpp>
17 #include <type_traits>
25 make_sec_ws_key(Gen& g)
27 std::array<std::uint8_t, 16> a;
28 for(int i = 0; i < 16; i += 4)
32 a[i+1] = (v >> 8) & 0xff;
33 a[i+2] = (v >> 16) & 0xff;
34 a[i+3] = (v >> 24) & 0xff;
36 return beast::detail::base64_encode(
40 template<class = void>
42 make_sec_ws_accept(boost::string_ref const& key)
44 std::string s(key.data(), key.size());
45 s += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
46 beast::detail::sha1_context ctx;
47 beast::detail::init(ctx);
48 beast::detail::update(ctx, s.data(), s.size());
49 std::array<std::uint8_t,
50 beast::detail::sha1_context::digest_size> digest;
51 beast::detail::finish(ctx, digest.data());
52 return beast::detail::base64_encode(
53 digest.data(), digest.size());