code wiki / _hdl_build / nx_quic_frame_test.nx

nx_quic_frame_test.nx source

↩ module page · 57 lines · 3103 B

1// nx_quic_frame_gate.nx -- RUNG 4 gate: QUIC core frames vs RFC 9000 sec 19 (CRYPTO/ACK/PADDING/PING/ 2// CONNECTION_CLOSE). Round-trips fields + payload byte-exact + verifies the frame-type bytes. Native, sovereign. 3// license_tier: ORIGINAL 4import "nx_quic_frame.nx" 5import "nx_g_check_lib.nx" 6import "nx_g_pn_lib.nx" 7import "nx_g_puts_lib.nx" 8 9func main() -> i64 { 10 g_puts("nx_quic_frame gate -- core frames vs RFC 9000 sec 19\n" as *u8) 11 var pass: i64=0; var total: i64=0 12 let info: *i64 = sys_mmap(8*6) as *i64 13 let out: *u8 = sys_mmap(256) 14 15 // ---- CRYPTO (0x06): offset 0x123456, 64 bytes of data ---- 16 let data: *u8 = sys_mmap(64) 17 var i: i64=0; while i<64 { data[i]=((i*5+9)&255) as u8; i=i+1 } 18 let clen: i64 = quic_crypto_encode(out, 1193046, data, 64) 19 var c_ok: i64=0 20 if out[0]==(0x06 as u8) { if clen==71 { if quic_crypto_parse(out, clen, info)==0 { 21 if info[0]==1193046 { if info[1]==64 { 22 c_ok=1; var k: i64=0; while k<64 { if out[info[2]+k]!=data[k] { c_ok=0; k=64 } else { k=k+1 } } 23 } } } } } 24 pass = pass + g_check("CRYPTO 0x06: offset=0x123456,len=64, data byte-exact (71B frame)" as *u8, c_ok); total=total+1 25 26 // ---- ACK (0x02): largest=1000, delay=25, first_range=10, range count=0 ---- 27 let alen: i64 = quic_ack_encode(out, 1000, 25, 10) 28 var a_ok: i64=0 29 if out[0]==(0x02 as u8) { if quic_ack_parse(out, alen, info)==0 { 30 if info[0]==1000 { if info[1]==25 { if info[2]==0 { if info[3]==10 { a_ok=1 } } } } } } 31 pass = pass + g_check("ACK 0x02: largest=1000,delay=25,count=0,first=10 round-trip" as *u8, a_ok); total=total+1 32 33 // ---- CONNECTION_CLOSE (0x1c): err=0,frametype=0,reason='bye' ---- 34 let reason: *u8 = sys_mmap(8) 35 reason[0]=98 as u8; reason[1]=121 as u8; reason[2]=101 as u8 // "bye" 36 let xlen: i64 = quic_conn_close_encode(out, 0, 0, reason, 3) 37 var x_ok: i64=0 38 if out[0]==(0x1c as u8) { if quic_conn_close_parse(out, xlen, info)==0 { 39 if info[0]==0 { if info[1]==0 { if info[2]==3 { 40 x_ok=1; var k: i64=0; while k<3 { if out[info[3]+k]!=reason[k] { x_ok=0; k=3 } else { k=k+1 } } 41 } } } } } 42 pass = pass + g_check("CONNECTION_CLOSE 0x1c: err=0,type=0,reason='bye' byte-exact" as *u8, x_ok); total=total+1 43 44 // ---- frame-type bytes + rejection ---- 45 var t_ok: i64=1 46 if quic_padding_byte() != 0x00 { t_ok=0 } 47 if quic_ping_byte() != 0x01 { t_ok=0 } 48 out[0]=0x09 as u8 // not a CRYPTO frame 49 if quic_crypto_parse(out, 8, info) != 0 - 1 { t_ok=0 } 50 if quic_ack_parse(out, 8, info) != 0 - 1 { t_ok=0 } // 0x09 is not ACK either 51 pass = pass + g_check("type bytes PADDING=0x00/PING=0x01 + parsers reject wrong type" as *u8, t_ok); total=total+1 52 53 g_puts("---- quic_frame gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 54 if pass == total { g_puts("VERDICT: GREEN (QUIC core frames, RFC 9000 sec 19, sovereign) -- WIRE FORMAT layer R1-R4 complete\n" as *u8); return 0 } 55 g_puts("VERDICT: RED\n" as *u8) 56 return 1 57}