code wiki / (root) / nx_atlas_citeverify.nx

nx_atlas_citeverify.nx source

↩ module page · 63 lines · 2465 B

1// nx_atlas_citeverify.nx -- atlas-hygiene CITATION AUTHORITY FIREWALL (blueprint Callout 1, ENFORCING). 2// ONE call: fetch the DOI from Crossref over the sovereign HTTPS fetch, decide, enforce. VERIFIED (exit 0) 3// if Crossref returns 200; QUARANTINE (exit 5) on 404; fail-closed (exit 6) on no authority response. Forks 4// the deployed nx_https_get.elf and inspects its status line. license_tier: ORIGINAL expect_exit: 0 5import "nx_syscalls.nx" 6import "nx_tool_run.nx" 7const K_MAGIC_1024: i64 = 1024 8const K_MAGIC_1048576: i64 = 1048576 9func cv_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 10func cv_contains(buf: *u8, n: i64, needle: *u8) -> i64 { 11 let m: i64 = cv_slen(needle) 12 if m == 0 { return 1 } 13 var i: i64 = 0 14 while i + m <= n { 15 var k: i64 = 0 16 while k < m { if buf[i + k] != needle[k] { k = m + 9 } else { k = k + 1 } } 17 if k == m { return 1 } 18 i = i + 1 19 } 20 return 0 21} 22func main(argc: i64, argv: *i64) -> i64 { 23 if argc < 2 { 24 sys_write(1, "ATLASCITEVERIFY ERR need doi\n" as *u8, 29) 25 sys_exit(2) 26 return 2 27 } 28 let doi: *u8 = argv[1] as *u8 29 let url: *u8 = sys_mmap(K_MAGIC_1024) 30 let prefix: *u8 = "https://api.crossref.org/works/" as *u8 31 var i: i64 = 0 32 while prefix[i] != (0 as u8) { url[i] = prefix[i]; i = i + 1 } 33 var j: i64 = 0 34 while doi[j] != (0 as u8) { url[i] = doi[j]; i = i + 1; j = j + 1 } 35 url[i] = 0 as u8 36 let path: *u8 = "./nx_https_get.elf" as *u8 37 let av: *i64 = sys_mmap(256) as *i64 38 av[0] = path as i64 39 av[1] = url as i64 40 av[2] = 0 41 let out: *u8 = sys_mmap(K_MAGIC_1048576) 42 let olen: *i64 = sys_mmap(16) as *i64 43 tr_run_capture(path, av, out, K_MAGIC_1048576, olen) 44 if cv_contains(out, olen[0], "200 OK" as *u8) == 1 { 45 sys_write(1, "ATLASCITEVERIFY VERIFIED crossref-200 doi=" as *u8, 42) 46 sys_write(1, doi, cv_slen(doi)) 47 sys_write(1, "\n" as *u8, 1) 48 sys_exit(0) 49 return 0 50 } 51 if cv_contains(out, olen[0], "404" as *u8) == 1 { 52 sys_write(1, "ATLASCITEVERIFY QUARANTINE crossref-404 doi=" as *u8, 44) 53 sys_write(1, doi, cv_slen(doi)) 54 sys_write(1, "\n" as *u8, 1) 55 sys_exit(5) 56 return 5 57 } 58 sys_write(1, "ATLASCITEVERIFY QUARANTINE no-authority-response doi=" as *u8, 53) 59 sys_write(1, doi, cv_slen(doi)) 60 sys_write(1, "\n" as *u8, 1) 61 sys_exit(6) 62 return 6 63}