mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 06:15:24 +02:00
Don't rely on undefined behavior
This commit is contained in:
@@ -23,15 +23,17 @@ template<class Gen>
|
|||||||
std::string
|
std::string
|
||||||
make_sec_ws_key(Gen& g)
|
make_sec_ws_key(Gen& g)
|
||||||
{
|
{
|
||||||
union U
|
std::array<std::uint8_t, 16> a;
|
||||||
|
for(int i = 0; i < 16; i += 4)
|
||||||
{
|
{
|
||||||
std::array<std::uint32_t, 4> a4;
|
auto const v = g();
|
||||||
std::array<std::uint8_t, 16> a16;
|
a[i ] = v & 0xff;
|
||||||
};
|
a[i+1] = (v >> 8) & 0xff;
|
||||||
U u;
|
a[i+2] = (v >> 16) & 0xff;
|
||||||
for(int i = 0; i < 4; ++i)
|
a[i+3] = (v >> 24) & 0xff;
|
||||||
u.a4[i] = g();
|
}
|
||||||
return beast::detail::base64_encode(u.a16.data(), u.a16.size());
|
return beast::detail::base64_encode(
|
||||||
|
a.data(), a.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class = void>
|
template<class = void>
|
||||||
|
Reference in New Issue
Block a user