1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

AK+Everywhere: Change AK::fill_with_random to accept a Bytes object

Rather than the very C-like API we currently have, accepting a void* and
a length, let's take a Bytes object instead. In almost all existing
cases, the compiler figures out the length.
This commit is contained in:
Timothy Flynn 2023-04-02 13:08:43 -04:00 committed by Andreas Kling
parent 5c045b6934
commit 15532df83d
20 changed files with 37 additions and 39 deletions

View file

@ -184,7 +184,7 @@ void WebSocket::send_client_handshake()
// 7. 16-byte nonce encoded as Base64
u8 nonce_data[16];
fill_with_random(nonce_data, 16);
fill_with_random(nonce_data);
// FIXME: change to TRY() and make method fallible
m_websocket_key = MUST(encode_base64({ nonce_data, 16 })).to_deprecated_string();
builder.appendff("Sec-WebSocket-Key: {}\r\n", m_websocket_key);
@ -579,7 +579,7 @@ void WebSocket::send_frame(WebSocket::OpCode op_code, ReadonlyBytes payload, boo
// > Clients MUST choose a new masking key for each frame, using an algorithm
// > that cannot be predicted by end applications that provide data
u8 masking_key[4];
fill_with_random(masking_key, 4);
fill_with_random(masking_key);
m_impl->send(ReadonlyBytes(masking_key, 4));
// don't try to send empty payload
if (payload.size() == 0)