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;
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;
function compute_accept(client_key: Str) -> String;Sec-WebSocket-Accept for a given client key: base64(sha1(key + GUID)).
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
function generate_key() -> String16 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.
type struct WebSocket<S> {
conn: BufStream<S>;
is_client: boolean;
closed: boolean;
}function compute_accept(client_key: Str) -> StringSec-WebSocket-Accept for a given client key: base64(sha1(key + GUID)).
function sha1(data: u8*, len: u64, out: u8*) -> voidHash len bytes at data, writing the 20-byte digest to out. out must point to at least DIGEST_LEN bytes.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function generate_key() -> String16 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.
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringfunction compute_accept(client_key: Str) -> StringSec-WebSocket-Accept for a given client key: base64(sha1(key + GUID)).
(parameter) client_key: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::str