]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/websocket/detail/hybi13.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / Beast / include / beast / websocket / detail / hybi13.hpp
1 //
2 // Copyright (c) 2013-2017 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
8 #ifndef BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
9 #define BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
10
11 #include <beast/core/detail/base64.hpp>
12 #include <beast/core/detail/sha1.hpp>
13 #include <boost/utility/string_ref.hpp>
14 #include <array>
15 #include <cstdint>
16 #include <string>
17 #include <type_traits>
18
19 namespace beast {
20 namespace websocket {
21 namespace detail {
22
23 template<class Gen>
24 std::string
25 make_sec_ws_key(Gen& g)
26 {
27 std::array<std::uint8_t, 16> a;
28 for(int i = 0; i < 16; i += 4)
29 {
30 auto const v = g();
31 a[i ] = v & 0xff;
32 a[i+1] = (v >> 8) & 0xff;
33 a[i+2] = (v >> 16) & 0xff;
34 a[i+3] = (v >> 24) & 0xff;
35 }
36 return beast::detail::base64_encode(
37 a.data(), a.size());
38 }
39
40 template<class = void>
41 std::string
42 make_sec_ws_accept(boost::string_ref const& key)
43 {
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());
54 }
55
56 } // detail
57 } // websocket
58 } // beast
59
60 #endif