Back to home page

EIC code displayed by LXR

 
 

    


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

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_HYBI13_IPP
0011 #define BOOST_BEAST_WEBSOCKET_DETAIL_HYBI13_IPP
0012 
0013 #include <boost/beast/websocket/detail/hybi13.hpp>
0014 #include <boost/beast/core/detail/sha1.hpp>
0015 #include <boost/beast/websocket/detail/prng.hpp>
0016 
0017 #include <boost/assert.hpp>
0018 #include <cstdint>
0019 #include <string>
0020 
0021 namespace boost {
0022 namespace beast {
0023 namespace websocket {
0024 namespace detail {
0025 
0026 void
0027 make_sec_ws_key(sec_ws_key_type& key)
0028 {
0029     auto g = make_prng(true);
0030     std::uint32_t a[4];
0031     for (auto& v : a)
0032         v = g();
0033     key.resize(key.max_size());
0034     key.resize(beast::detail::base64::encode(
0035         key.data(), &a[0], sizeof(a)));
0036 }
0037 
0038 void
0039 make_sec_ws_accept(
0040     sec_ws_accept_type& accept,
0041     string_view key)
0042 {
0043     BOOST_ASSERT(key.size() <= sec_ws_key_type::static_capacity);
0044     using namespace beast::detail::string_literals;
0045     auto const guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"_sv;
0046     beast::detail::sha1_context ctx;
0047     beast::detail::init(ctx);
0048     beast::detail::update(ctx, key.data(), key.size());
0049     beast::detail::update(ctx, guid.data(), guid.size());
0050     char digest[beast::detail::sha1_context::digest_size];
0051     beast::detail::finish(ctx, &digest[0]);
0052     accept.resize(accept.max_size());
0053     accept.resize(beast::detail::base64::encode(
0054         accept.data(), &digest[0], sizeof(digest)));
0055 }
0056 
0057 } // detail
0058 } // websocket
0059 } // beast
0060 } // boost
0061 
0062 #endif // BOOST_BEAST_WEBSOCKET_DETAIL_HYBI13_IPP