ゴミ箱
hybi13.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-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 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
11 #define BOOST_BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
12 
17 #include <boost/assert.hpp>
18 #include <array>
19 #include <cstdint>
20 #include <string>
21 #include <type_traits>
22 
23 namespace boost {
24 namespace beast {
25 namespace websocket {
26 namespace detail {
27 
28 using sec_ws_key_type = static_string<
30 
33 
34 template<class Gen>
35 void
37 {
38  char a[16];
39  for(int i = 0; i < 16; i += 4)
40  {
41  auto const v = g();
42  a[i ] = v & 0xff;
43  a[i+1] = (v >> 8) & 0xff;
44  a[i+2] = (v >> 16) & 0xff;
45  a[i+3] = (v >> 24) & 0xff;
46  }
47  key.resize(key.max_size());
49  key.data(), &a[0], 16));
50 }
51 
52 template<class = void>
53 void
55  string_view key)
56 {
57  BOOST_ASSERT(key.size() <= sec_ws_key_type::max_size_n);
59  m.append("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
62  beast::detail::update(ctx, m.data(), m.size());
64  beast::detail::finish(ctx, &digest[0]);
65  accept.resize(accept.max_size());
67  accept.data(), &digest[0], sizeof(digest)));
68 }
69 
70 } // detail
71 } // websocket
72 } // beast
73 } // boost
74 
75 #endif
void init(sha1_context &ctx) noexcept
Definition: sha1.hpp:235
Definition: async_result.hpp:20
size_type constexpr max_size() const
Returns the maximum number of characters that can be stored, excluding the null terminator.
Definition: static_string.hpp:470
static std::size_t constexpr max_size_n
Maximum size of the string excluding the null terminator.
Definition: static_string.hpp:87
void finish(sha1_context &ctx, void *digest) noexcept
Definition: sha1.hpp:273
std::size_t constexpr encoded_size(std::size_t n)
Returns max chars needed to encode a base64 string.
Definition: base64.hpp:92
void update(sha1_context &ctx, void const *message, std::size_t size) noexcept
Definition: sha1.hpp:248
void resize(std::size_t n)
Definition: static_string.ipp:461
std::size_t encode(void *dest, void const *src, std::size_t len)
Definition: base64.hpp:120
Definition: sha1.hpp:222
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
void make_sec_ws_key(sec_ws_key_type &key, Gen &g)
Definition: hybi13.hpp:36
Definition: static_string.hpp:44
static unsigned int constexpr digest_size
Definition: sha1.hpp:225
CharT * data()
Returns a pointer to the first character of a string.
Definition: static_string.hpp:329
static_string< beast::detail::base64::encoded_size(16)> sec_ws_key_type
Definition: hybi13.hpp:29
void make_sec_ws_accept(sec_ws_accept_type &accept, string_view key)
Definition: hybi13.hpp:54