nx_doc_serve.nx
buildroot/runtime/nx_doc_serve.nx
about
nx_doc_serve.nx -- LEGAL RUNG D3: open-the-document-in-the-app-of-choice.
module: nishi-core.legal.doc_serve
capability: LEGAL_DOC_SERVE
Serves a stored document's ORIGINAL bytes so a client can open it in the app
of their choice -- inline in the browser (PDF/HTML/text) or downloaded to open
in a desktop app (Word/etc). A pure bytes-in/bytes-out HTTP response builder
(the proven nx_status_daemon handler pattern): a thin socket loop can wrap it,
but the logic + the gate need no socket.
The s-class properties (each tested with a negative control in the gate):
BYTE-EXACT INTEGRITY -- the served body is bit-identical to the stored
bytes. For a legal instrument a single altered byte
is a DIFFERENT document, so the body is Content-
Length framed (never transcoded, never delimiter-
scanned); a body that itself contains CRLFCRLF / NUL
round-trips exactly.
HEADER-INJECTION SAFE -- the attachment filename is sanitized (control chars
stripped) so a malicious "name\r\nSet-Cookie: ..."
cannot inject a response header.
SAFE-BY-DEFAULT TYPE -- unknown formats are downloaded as octet-stream
(never inlined), and X-Content-Type-Options: nosniff
stops the browser MIME-sniffing a legal document.
PER-TENANT -- the serve layer reads only from the tenant's vault
prefix (nx_vault_valid_tid -- no cross-tenant).
Composes: nx_doc_vault (D1 tenant-id discipline). license_tier: ORIGINAL
lineage_id: nishi_doc_serve_d3
dependencies 1 imports · 6 importers
imports: nx_syscalls.nx
imported by: nx_doc_serve_gate.nxnx_legal_blob_gate.nxnx_legal_portal.nxnx_legal_portal_daemon.nxnx_legal_portal_gate.nxnx_legal_portal_live_gate.nx
structs
| none |
consts
| 33 | const DF_PDF: i64 = 0 |
| 34 | const DF_DOCX: i64 = 1 |
| 35 | const DF_HTML: i64 = 2 |
| 36 | const DF_TXT: i64 = 3 |
| 37 | const DF_NXDOC: i64 = 4 // our own sovereign document format |
| 38 | const DF_OCTET: i64 = 5 // unknown -> download as octet-stream |
| 41 | const DISP_INLINE: i64 = 0 // open in the browser |
| 42 | const DISP_ATTACHMENT: i64 = 1 // download -> open in the app of choice |
functions
| 45 | func nx_doc_content_type(fmt: i64) -> *u8 |
| 57 | func nx_doc_default_disposition(fmt: i64) -> i64 |
| 63 | func ds_cat(out: *u8, o: i64, s: *u8) -> i64 { var k: i64 = 0; while s[k] != (0 as u8) { out[o] = s[k]; o = o + 1; k = k + 1 } return o } called by 1: nx_doc_serve_response |
| 64 | func ds_num(out: *u8, o: i64, v: i64) -> i64 |
| 75 | func nx_doc_serve_response(out: *u8, doc_bytes: *u8, doc_len: i64, fmt: i64, |
| 108 | func ds_body_off(resp: *u8, n: i64) -> i64 called by 1: nx_doc_serve_roundtrip_ok |
| 118 | func nx_doc_serve_roundtrip_ok(resp: *u8, n: i64, orig: *u8, orig_len: i64) -> i64 |
| 131 | func nx_doc_serve_contains(resp: *u8, n: i64, needle: *u8) -> i64 called by 1: main |