code wiki / _hdl_build / nx_sota_source_hash_gate.nx
nx_sota_source_hash_gate.nx source
↩ module page · 53 lines · 3287 B
1// Source-linked owner gate. Writes only one caller-named exclusive /tmp JSON capture.
2// Failure-code cases exercise serialization, not ENOMEM injection.
3import "nx_sota_status.nx"
4import "nx_gatekit_lib.nx"
5import "nx_gate_verdict.nx"
6const SHG_MODE: i64=0x180
7func shg_decl(row: *u8, symbol: *u8) -> i64 {
8 return ss_bdecl(row,0,bf_slen(row),symbol,0,bf_slen(symbol))
9}
10func main(argc: i64, argv: *i64) -> i64 {
11 if argc != 2 { return 2 }
12 let path: *u8=argv[1] as *u8
13 if ss_bout_ok(path) != 1 { return 2 }
14 let ctr: *i64=gv_ctr(); gv_head("SOURCE-HASH" as *u8)
15 let fd: i64=sys_openat_exclusive(path,SHG_MODE)
16 if fd < 0 { return 3 }
17 ss_json_fd=fd; ss_json_stdout=0; ss_json_failed=0; ss_json_bytes=0
18 let digest: *u8=sys_mmap(SHA256_DIGEST_BYTES)
19 let rc: i64=sha256_digest_checked_native("abc" as *u8,3,digest)
20 gv_check("real checked abc hash succeeded" as *u8,rc==0,ctr)
21 ss_jw("{\"cases\":[{\"name\":\"abc\"" as *u8); ss_bhash_fields(rc,digest); ss_jw("}" as *u8)
22 var code: i64=SHA256_E_INPUT
23 while code >= SHA256_E_RELEASE {
24 ss_jw(",{\"name\":\"synthetic-code\",\"declaration_result\":\"present\"" as *u8)
25 ss_bhash_fields(code,digest); ss_jw("}" as *u8); code=code-1
26 }
27 ss_jw(",{\"name\":\"missing-path\",\"observation\":" as *u8)
28 shg_decl("x||target" as *u8,"target" as *u8); ss_jw("}" as *u8)
29 ss_jw(",{\"name\":\"unsupported\",\"observation\":" as *u8)
30 shg_decl("x|runtime/example.txt|target" as *u8,"target" as *u8); ss_jw("}" as *u8)
31 ss_jw(",{\"name\":\"real-present\",\"observation\":" as *u8)
32 shg_decl("x|runtime/nx_sha256.nx|sha256_digest_checked_native" as *u8,"sha256_digest_checked_native" as *u8); ss_jw("}" as *u8)
33 ss_jw(",{\"name\":\"real-absent\",\"observation\":" as *u8)
34 shg_decl("x|runtime/nx_sha256.nx|t16_deliberately_absent_symbol" as *u8,"t16_deliberately_absent_symbol" as *u8); ss_jw("}]}\n" as *u8)
35 let emitted: i64=ss_json_bytes
36 gv_check("all writer calls complete" as *u8,ss_json_failed==0,ctr)
37 gv_check("capture fsync succeeded" as *u8,sys_fsync(fd)==0,ctr)
38 gv_check("capture close succeeded" as *u8,sys_close(fd)==0,ctr)
39 ss_json_fd=0-1
40 var n: i64=0; let raw: *u8=pbm_read(path,&n)
41 gv_check("capture complete read matches emitted bytes" as *u8,n==emitted,ctr)
42 if (raw as i64) > 0 {
43 gv_check("known digest rendered" as *u8,gk_has(raw,"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" as *u8),ctr)
44 gv_check("present declaration retained" as *u8,gk_has(raw,"matching_declaration_text_observed" as *u8),ctr)
45 gv_check("absent declaration retained" as *u8,gk_has(raw,"complete_source_has_no_matching_declaration_text" as *u8),ctr)
46 gv_check("mapping error explicit" as *u8,gk_has(raw,"digest_mapping_unavailable" as *u8),ctr)
47 gv_check("release error explicit" as *u8,gk_has(raw,"digest_workspace_release_failed" as *u8),ctr)
48 sys_munmap(raw,n+1)
49 } else { gv_check("capture available" as *u8,0,ctr) }
50 sys_munmap(digest,SHA256_DIGEST_BYTES)
51 gv_puts("capture_path=" as *u8); gv_puts(path); gv_puts("\n" as *u8)
52 return gv_verdict("SOURCE-HASH" as *u8,ctr,"exact complete-buffer identity; declaration text is not behavior or deployment proof" as *u8)
53}