code wiki / (root) / nx_patent_check_test.nx

nx_patent_check_test.nx source

↩ module page · 85 lines · 3186 B

1// nx_patent_check_test.nx -- smoke for the offline patent gate. 2// 3// Builds a synthetic patent table at /tmp/nx_patent_t1.txt with one 4// row per status enum, then verifies lookup + safety predicate + 5// observability counters. 6 7import "nx_syscalls.nx" 8import "nx_tier.nx" 9import "nx_str.nx" 10import "nx_patent_check.nx" 11 12const NX_PT_MODE: i64 = 420 // 0o644 13 14func nx_pt_write_str(fd: i64, s: *u8) -> nx_int { 15 var n: i64 = 0 16 while s[n] != 0 { n = n + 1 } 17 let w: i64 = sys_write(fd, s, n) 18 if w != n { return 1 } 19 return 0 20} 21 22func nx_pt_write_fixture(path: *u8) -> nx_int { 23 let fd: i64 = sys_openat_wr(path, NX_PT_MODE) 24 if fd < 0 { return 1 } 25 26 // 5 rows: pd / expired / active / unknown / comment-and-blank 27 if nx_pt_write_str(fd, "# fixture\n" as *u8) != 0 { return 2 } 28 if nx_pt_write_str(fd, "gcd_euclidean\tpd\tnone\t-300\tnone\tEuclid\n" as *u8) != 0 { return 3 } 29 if nx_pt_write_str(fd, "rsa\texpired\tUS_4405829\t1977\t2000\tRSA expired 2000\n" as *u8) != 0 { return 4 } 30 if nx_pt_write_str(fd, "hevc_h265\tactive\tmultiple\t2010\t2030\tactive\n" as *u8) != 0 { return 5 } 31 if nx_pt_write_str(fd, "xxhash_codebase\tunknown\tunknown\t2012\tunknown\tcleanroom\n" as *u8) != 0 { return 6 } 32 if nx_pt_write_str(fd, "\n" as *u8) != 0 { return 7 } 33 34 sys_close(fd) 35 return 0 36} 37 38func main() -> nx_exit { 39 let path: *u8 = "/tmp/nx_patent_t1.txt" as *u8 40 41 let prep: nx_int = nx_pt_write_fixture(path) 42 if prep != 0 { return 10 + prep } 43 44 let t: *NxPatentTable = nx_patent_load(path) 45 if (t as nx_size) == 0 { return 20 } 46 if nx_patent_n_records(t) != 4 { return 21 } 47 48 // PD case 49 let s1: nx_int = nx_patent_check(t, "gcd_euclidean" as *u8) 50 if s1 != NX_PAT_PD { return 30 } 51 let safe1: nx_int = nx_patent_is_safe(t, "gcd_euclidean" as *u8) 52 if safe1 != 1 { return 31 } 53 54 // Expired case 55 let s2: nx_int = nx_patent_check(t, "rsa" as *u8) 56 if s2 != NX_PAT_EXPIRED { return 40 } 57 let safe2: nx_int = nx_patent_is_safe(t, "rsa" as *u8) 58 if safe2 != 1 { return 41 } 59 60 // Active case -- UNSAFE 61 let s3: nx_int = nx_patent_check(t, "hevc_h265" as *u8) 62 if s3 != NX_PAT_ACTIVE { return 50 } 63 let safe3: nx_int = nx_patent_is_safe(t, "hevc_h265" as *u8) 64 if safe3 != 0 { return 51 } 65 66 // Unknown case -- UNSAFE 67 let s4: nx_int = nx_patent_check(t, "xxhash_codebase" as *u8) 68 if s4 != NX_PAT_UNKNOWN { return 60 } 69 let safe4: nx_int = nx_patent_is_safe(t, "xxhash_codebase" as *u8) 70 if safe4 != 0 { return 61 } 71 72 // Miss -- default deny 73 let s5: nx_int = nx_patent_check(t, "not_in_table" as *u8) 74 if s5 != NX_PAT_UNKNOWN { return 70 } 75 let safe5: nx_int = nx_patent_is_safe(t, "not_in_table" as *u8) 76 if safe5 != 0 { return 71 } 77 78 // Counters 79 if nx_patent_n_by_status(t, NX_PAT_PD) != 1 { return 80 } 80 if nx_patent_n_by_status(t, NX_PAT_EXPIRED) != 1 { return 81 } 81 if nx_patent_n_by_status(t, NX_PAT_ACTIVE) != 1 { return 82 } 82 if nx_patent_n_by_status(t, NX_PAT_UNKNOWN) != 1 { return 83 } 83 84 return 0 85}