Skip to content
CryoCryo home
Stdlibnet::ws

handshake

import std::net::ws::handshake; · source

Free Functions

The opening handshake

The two computations RFC 6455 section 4 asks for. generate_key is the client's Sec-WebSocket-Key: 16 random bytes from the OS entropy source, base64-encoded. compute_accept is the server's Sec-WebSocket-Accept for a given client key — base64(sha1(key + GUID)) with the fixed RFC GUID — which the client checks against what it sent.

The HTTP/1.1 Upgrade exchange around them lives in WebSocket::client_handshake and server_handshake. Both digests come from encoding, pure Cryo, so the handshake needs no OpenSSL.

function generate_key() -> String;

16 random bytes, base64-encoded - the client's Sec-WebSocket-Key. secure::fill_secure_bytes is the portable OS-entropy source (getrandom on UNIX, RtlGenRandom on Windows), so this links on every target rather than binding the Linux-only getrandom symbol.

function compute_accept(client_key: Str) -> String;

Sec-WebSocket-Accept for a given client key: base64(sha1(key + GUID)).