Simplify generation of sec-websocket-key

The result of `g()` is a random number, therefore it's not necessary
to care about endianness in this case.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2019-06-23 18:31:30 +02:00
committed by Vinnie Falco
parent b8b04f8f39
commit 1635df0e11
2 changed files with 5 additions and 10 deletions

View File

@ -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
--------------------------------------------------------------------------------

View File

@ -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