code wiki / (root) / nx_websocket_handshake.nx

nx_websocket_handshake.nx

buildroot/runtime/nx_websocket_handshake.nx

2803 B86 linesdepth 3pulls 4 transitivereach 20 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 · 4 importers

nx_syscalls.nx nx_sha1.nx nx_base64.nx nx_websocket_handshake.nx nx_websocket_client_upgrade.nx nx_websocket_client_upgrade_test.n nx_websocket_handshake_test.nx nx_websocket_upgrade.nx

imports: nx_syscalls.nxnx_sha1.nxnx_base64.nx

imported by: nx_websocket_client_upgrade.nxnx_websocket_client_upgrade_test.nxnx_websocket_handshake_test.nxnx_websocket_upgrade.nx

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

main sys_mmap ws_accept sys_mmap ↻ ws_guid sha1 sys_mmap ↻ sha1_process_block if_ge b64_encode b64_enc_char

structs

none

consts

40const WS_GUID_LEN: i64 = 36
41const WS_SHA1_BYTES: i64 = 20
42const WS_ACCEPT_LEN: i64 = 28

functions

36func ws_guid() -> *u8
called by 1: ws_accept
47func ws_accept(key: *u8, key_len: i64, out: *u8) -> i64
74func main() -> i64