diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4011d9..df47460f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Version 260: * Qualify calls to `beast::iequals` in basic_parser.ipp * More split compilation in websocket/detail/mask.hpp * Cleanup transitive includes in beast/core/detail/type_traits.hpp +* Simplify generation of sec-websocket-key -------------------------------------------------------------------------------- diff --git a/include/boost/beast/websocket/detail/hybi13.ipp b/include/boost/beast/websocket/detail/hybi13.ipp index 0d9f7588..0cbab153 100644 --- a/include/boost/beast/websocket/detail/hybi13.ipp +++ b/include/boost/beast/websocket/detail/hybi13.ipp @@ -27,18 +27,12 @@ void make_sec_ws_key(sec_ws_key_type& key) { auto g = make_prng(true); - char a[16]; - for(int i = 0; i < 16; i += 4) - { - auto const v = g(); - a[i ] = v & 0xff; - a[i+1] = (v >> 8) & 0xff; - a[i+2] = (v >> 16) & 0xff; - a[i+3] = (v >> 24) & 0xff; - } + std::uint32_t a[4]; + for (auto& v : a) + v = g(); key.resize(key.max_size()); key.resize(beast::detail::base64::encode( - key.data(), &a[0], 16)); + key.data(), &a[0], sizeof(a))); } void