code wiki / _hdl_build / nx_hub_render_gate.nx
nx_hub_render_gate.nx source
↩ module page · 91 lines · 5354 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_hub_render_gate.nx -- hermetic gate for the LEVELED hub index. Proves each level sees EXACTLY its
4// allowed cards and NO MORE (no-leak at the render layer = gated cards ABSENT from a lower level's bytes):
5// operator(3): welcome+family+ops (3 cards); production + retired artifacts excluded
6// member(2): welcome+family (2); ops ABSENT
7// viewer(1): welcome (1); family + ops ABSENT
8// Sovereign: nx_syscalls + nx_hub_render. license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_hub_render.nx"
11
12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
13" as *u8); return ok }
14func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
15func g_app(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){buf[off+i]=s[i]; i=i+1} return off+i }
16func g_row7(buf: *u8, off: i64, a: *u8, b: *u8, c: *u8, d: *u8, e: *u8, f: *u8, g: *u8) -> i64 {
17 var o: i64=g_app(buf,off,a); buf[o]=9 as u8; o=o+1
18 o=g_app(buf,o,b); buf[o]=9 as u8; o=o+1
19 o=g_app(buf,o,c); buf[o]=9 as u8; o=o+1
20 o=g_app(buf,o,d); buf[o]=9 as u8; o=o+1
21 o=g_app(buf,o,e); buf[o]=9 as u8; o=o+1
22 o=g_app(buf,o,f); buf[o]=9 as u8; o=o+1
23 o=g_app(buf,o,g); buf[o]=10 as u8; o=o+1
24 return o
25}
26// count occurrences of needle[0..nl) in buf[0..n)
27func g_count(buf: *u8, n: i64, needle: *u8, nl: i64) -> i64 {
28 if nl == 0 { return 0 }
29 var c: i64 = 0; var i: i64 = 0
30 while i + nl <= n {
31 var j: i64 = 0; var ok: i64 = 1
32 while j < nl { if buf[i+j] != needle[j] { ok = 0; j = nl } else { j = j + 1 } }
33 if ok == 1 { c = c + 1 }
34 i = i + 1
35 }
36 return c
37}
38
39func main(argc: i64, argv: *i64) -> i64 {
40 gp("=== nx_hub_render_gate (leveled hub index; gated cards ABSENT from lower-level bytes) ===\n" as *u8)
41 let reg: *u8 = sys_mmap(16384); var rn: i64 = 0
42 rn = g_row7(reg, rn, "welcome" as *u8, "hub" as *u8, "viewer" as *u8, "welcome" as *u8, "Welcome" as *u8, "10" as *u8, "1" as *u8)
43 rn = g_row7(reg, rn, "family" as *u8, "hub" as *u8, "member" as *u8, "family" as *u8, "Family Area" as *u8, "10" as *u8, "1" as *u8)
44 rn = g_row7(reg, rn, "ops" as *u8, "hub" as *u8, "operator" as *u8, "ops" as *u8, "Operations" as *u8, "10" as *u8, "1" as *u8)
45 rn = g_row7(reg, rn, "tictactoe" as *u8, "production" as *u8, "public" as *u8, "tictactoe" as *u8, "Tic-Tac-Toe" as *u8, "10" as *u8, "1" as *u8)
46 rn = g_row7(reg, rn, "secret" as *u8, "hub" as *u8, "member" as *u8, "secret" as *u8, "Secret" as *u8, "10" as *u8, "1" as *u8)
47 rn = g_row7(reg, rn, "secret" as *u8, "hub" as *u8, "member" as *u8, "secret" as *u8, "Secret" as *u8, "20" as *u8, "0" as *u8) // tombstone
48
49 let out: *u8 = sys_mmap(65536)
50 var pass: i64 = 0; var fail: i64 = 0
51 let cls: *u8 = "class=\"card\"" as *u8; let cln: i64 = g_slen(cls)
52 let h_wel: *u8 = "/hub/welcome" as *u8; let h_fam: *u8 = "/hub/family" as *u8; let h_ops: *u8 = "/hub/ops" as *u8
53 let h_tic: *u8 = "/hub/tictactoe" as *u8; let h_sec: *u8 = "/hub/secret" as *u8
54
55 // ---- operator (level 3) ----
56 var o: i64 = mr_render_index(reg, rn, 3, out, 65536)
57 var cards: i64 = g_count(out, o, cls, cln)
58 if cards == 3 {
59 if g_count(out, o, h_wel, g_slen(h_wel)) == 1 { if g_count(out, o, h_fam, g_slen(h_fam)) == 1 { if g_count(out, o, h_ops, g_slen(h_ops)) == 1 {
60 if g_count(out, o, h_tic, g_slen(h_tic)) == 0 { if g_count(out, o, h_sec, g_slen(h_sec)) == 0 {
61 pass = pass + 1; gp(" T1 operator->welcome+family+ops (3); production+retired excluded PASS\n" as *u8)
62 } }
63 } } }
64 }
65 if cards != 3 { fail = fail + 1; gp(" T1 FAIL cards=" as *u8); gn(cards); gp("\n" as *u8) }
66
67 // ---- member (level 2): ops ABSENT ----
68 o = mr_render_index(reg, rn, 2, out, 65536)
69 cards = g_count(out, o, cls, cln)
70 if cards == 2 { if g_count(out, o, h_wel, g_slen(h_wel)) == 1 { if g_count(out, o, h_fam, g_slen(h_fam)) == 1 { if g_count(out, o, h_ops, g_slen(h_ops)) == 0 {
71 pass = pass + 1; gp(" T2 member->welcome+family (2); ops ABSENT (no-leak) PASS\n" as *u8)
72 } } } }
73 if cards != 2 { fail = fail + 1; gp(" T2 FAIL cards=" as *u8); gn(cards); gp("\n" as *u8) }
74
75 // ---- viewer (level 1): family+ops ABSENT ----
76 o = mr_render_index(reg, rn, 1, out, 65536)
77 cards = g_count(out, o, cls, cln)
78 if cards == 1 { if g_count(out, o, h_wel, g_slen(h_wel)) == 1 { if g_count(out, o, h_fam, g_slen(h_fam)) == 0 { if g_count(out, o, h_ops, g_slen(h_ops)) == 0 {
79 pass = pass + 1; gp(" T3 viewer->welcome (1); family+ops ABSENT (no-leak) PASS\n" as *u8)
80 } } } }
81 if cards != 1 { fail = fail + 1; gp(" T3 FAIL cards=" as *u8); gn(cards); gp("\n" as *u8) }
82
83 // ---- no-session (level 0): nothing ----
84 o = mr_render_index(reg, rn, 0, out, 65536)
85 cards = g_count(out, o, cls, cln)
86 if cards == 0 { pass = pass + 1; gp(" T4 (NEG) level0->0 cards PASS\n" as *u8) } else { fail = fail + 1; gp(" T4 FAIL cards=" as *u8); gn(cards); gp("\n" as *u8) }
87
88 gp("RESULT pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail)
89 if fail == 0 { gp(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
90 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1
91}