code wiki / (root) / nx_build_key_identity_lib.nx

nx_build_key_identity_lib.nx source

↩ module page · 24 lines · 1202 B

1// Debug artifacts contain logical source paths. Content identity alone cannot key them. 2// The caller supplies the same estate-relative source path passed to the compiler. 3import "nx_sha256.nx" 4import "nx_syscalls.nx" 5import "nx_build_canon_input_lib.nx" 6const BKI_DIGEST_BYTES: i64 = 32 7const BKI_INVALID: i64 = 0 - 1 8 9func bki_digest(material: *u8, material_len: i64, want_debug: i64, logical_path: *u8, path_len: i64, out: *u8) -> i64 { 10 if material_len <= 0 { return BKI_INVALID } 11 if material_len > BCI_I64_MAX - BKI_DIGEST_BYTES { return BKI_INVALID } 12 if want_debug == 0 { sha256_digest(material, material_len, out); return 0 } 13 if want_debug != 1 { return BKI_INVALID } 14 // Absolute host prefixes never enter a reusable key. Invalid identity disables cache use. 15 if bci_relative_path(logical_path, 0, path_len, path_len) != 1 { return BKI_INVALID } 16 let n: i64 = material_len + BKI_DIGEST_BYTES 17 let joined: *u8 = sys_mmap(n) 18 var i: i64 = 0 19 while i < material_len { joined[i] = material[i]; i = i + 1 } 20 sha256_digest(logical_path, path_len, ((joined as i64) + material_len) as *u8) 21 sha256_digest(joined, n, out) 22 sys_munmap(joined, n) 23 return 0 24}