code wiki / (root) / websocket_handshake.nx

websocket_handshake.nx

buildroot/runtime/websocket_handshake.nx

2626 B80 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind tooltopic websocket
docsdependenciesstructsconstsfunctions

about

websocket_handshake.nx -- compute Sec-WebSocket-Accept. RFC 6455 ยง4.2.2: the server's response to a WebSocket upgrade request includes a Sec-WebSocket-Accept header whose value is base64( sha1( client_key || GUID ) ) where GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" is a literal defined in the RFC (solely to make accidental handshake-value forgery harder -- it doesn't add security). client_key is the value of the Sec-WebSocket-Key request header (a 16-byte random value, base64-encoded by the client, so 24 ASCII chars including "=" padding). Composes sha1.nx + base64.nx. The concatenation buffer is at most 24 + 36 = 60 bytes. Invariants: WH1 Caller passes the raw client key bytes (typically 24 ASCII characters); we don't decode them -- the spec says concatenate the client-sent base64 string AS IS with the GUID string and hash that. WH2 Output is 28 ASCII characters (base64 of 20 bytes).

dependencies 3 imports · 0 importers

syscalls.nx nx_sha1.nx base64.nx websocket_handshake.nx

imports: syscalls.nxnx_sha1.nxbase64.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ws_accept ws_guid sha1 sys_mmap sha1_process_block if_ge b64_encode b64_enc_char

structs

none

consts

34const WS_GUID_LEN: i64 = 36
35const WS_SHA1_BYTES: i64 = 20
36const WS_ACCEPT_LEN: i64 = 28

functions

30func ws_guid() -> *u8 {
called by 1: ws_accept
41func ws_accept(key: *u8, key_len: i64, out: *u8) -> i64 {
called by 1: main calls 3: ws_guidsha1b64_encode
68func main() -> i64 {
calls 1: ws_accept