nx_asn1_write.nx
buildroot/runtime/hub/nx_asn1_write.nx
about
nx_asn1_write.nx -- V-HOST-4a: sovereign ASN.1 DER encoder.
Sibling to existing asn1.nx (READ surface; cursor-based parser).
This module adds the WRITE surface needed for X.509 cert generation
(bin/nx_cert_gen V-HOST-4 closes the openssl bridge from
NISHI_ANDELINWEST_DEPLOY_PLAYBOOK ยง3).
COMPOSES (per "avoid duplicate primitives"):
nx_syscalls (no allocation; caller-owned out buffer)
asn1.nx (READ surface; this module mirrors with WRITE)
COMPOSED BY:
hub/nx_x509_build.nx (V-HOST-4b; queued)
bin/nx_cert_gen.nx (V-HOST-4c; queued)
future: nx_acme cert request (CSR builder; reusable for ACME)
future: nx_pkcs8_emit (sovereign priv-key DER export)
V-HOST-4a SCOPE:
- DER encoding of: INTEGER, BIT STRING, OCTET STRING,
OBJECT IDENTIFIER, SEQUENCE, SET, NULL, UTF8 STRING,
IA5 STRING, GeneralizedTime, UTCTime, BOOLEAN, [n] EXPLICIT/IMPLICIT
- Length encoding: short form (< 128) + long form (>= 128 up to 4 bytes)
- Tag construction: universal + context-specific + IMPLICIT/EXPLICIT
- Wrapper helpers for nested SEQUENCE (DER 2-pass write OR
fixup-length pattern)
V-HOST-4a NON-SCOPE (not needed for X.509 V1):
- BER (non-canonical) encoding
- REAL / EMBEDDED PDV / EXTERNAL types
- Streaming encode (this writes flat to caller buffer)
Status: V-HOST-4a. 2026-05-27.
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_cert_gen.nxnx_x509_build.nx
structs
| none |
consts
| 37 | const NX_AW_OK: i64 = 0 |
| 38 | const NX_AW_BAD_INPUT: i64 = 3600 |
| 39 | const NX_AW_BUF_OVERFLOW: i64 = 3601 |
| 40 | const NX_AW_LENGTH_TOO_LARGE: i64 = 3602 |
| 41 | const NX_AW_INTEGER_TOO_LARGE: i64 = 3603 |
| 42 | const NX_AW_BAD_TAG: i64 = 3604 |
| 45 | const NX_AW_MAX_BUF: i64 = 65536 // 64 KB; covers V1 certs comfortably |
| 46 | const NX_AW_MAX_LENGTH_BYTES: i64 = 4 // long-form length up to 32 bits |
| 50 | const NX_AW_CLASS_UNIVERSAL: i64 = 0x00 |
| 51 | const NX_AW_CLASS_APPLICATION: i64 = 0x40 |
| 52 | const NX_AW_CLASS_CONTEXT: i64 = 0x80 |
| 53 | const NX_AW_CLASS_PRIVATE: i64 = 0xC0 |
| 55 | const NX_AW_FORM_PRIMITIVE: i64 = 0x00 |
| 56 | const NX_AW_FORM_CONSTRUCTED: i64 = 0x20 |
| 59 | const NX_AW_TAG_BOOLEAN: i64 = 0x01 |
| 60 | const NX_AW_TAG_INTEGER: i64 = 0x02 |
| 61 | const NX_AW_TAG_BIT_STRING: i64 = 0x03 |
| 62 | const NX_AW_TAG_OCTET_STRING: i64 = 0x04 |
| 63 | const NX_AW_TAG_NULL: i64 = 0x05 |
| 64 | const NX_AW_TAG_OID: i64 = 0x06 |
| 65 | const NX_AW_TAG_UTF8_STRING: i64 = 0x0C |
| 66 | const NX_AW_TAG_SEQUENCE: i64 = 0x10 // CONSTRUCTED implied |
| 67 | const NX_AW_TAG_SET: i64 = 0x11 // CONSTRUCTED implied |
| 68 | const NX_AW_TAG_PRINTABLE_STRING: i64 = 0x13 |
| 69 | const NX_AW_TAG_IA5_STRING: i64 = 0x16 |
| 70 | const NX_AW_TAG_UTC_TIME: i64 = 0x17 |
| 71 | const NX_AW_TAG_GENERALIZED_TIME: i64 = 0x18 |
functions
| 76 | func nx_aw_put_tag(out: *u8, cap: i64, off: i64, tag_byte: i64) -> i64 |
| 85 | func nx_aw_put_length(out: *u8, cap: i64, off: i64, length: i64) -> i64 |
| 118 | func nx_aw_put_boolean(out: *u8, cap: i64, off: i64, val: i64) -> i64 |
| 128 | func nx_aw_put_null(out: *u8, cap: i64, off: i64) -> i64 |
| 135 | func nx_aw_put_integer(out: *u8, cap: i64, off: i64, val: i64) -> i64 |
| 168 | func nx_aw_put_integer_bytes(out: *u8, cap: i64, off: i64, |
| 188 | func nx_aw_put_octet_string(out: *u8, cap: i64, off: i64, |
| 199 | func nx_aw_put_bit_string(out: *u8, cap: i64, off: i64, |
| 219 | func nx_aw_put_oid(out: *u8, cap: i64, off: i64, |
| 231 | func nx_aw_put_utf8_string(out: *u8, cap: i64, off: i64, |
| 242 | func nx_aw_put_ia5_string(out: *u8, cap: i64, off: i64, |
| 253 | func nx_aw_put_printable_string(out: *u8, cap: i64, off: i64, |
| 264 | func nx_aw_put_utc_time(out: *u8, cap: i64, off: i64, |
| 275 | func nx_aw_put_generalized_time(out: *u8, cap: i64, off: i64, |
| 291 | func nx_aw_wrap_sequence(out: *u8, cap: i64, off: i64, |
| 302 | func nx_aw_wrap_set(out: *u8, cap: i64, off: i64, |
| 315 | func nx_aw_wrap_explicit(out: *u8, cap: i64, off: i64, called by 3: acme_csr_attributesnx_x509_build_extensionsnx_x509_build_tbs calls 2: nx_aw_put_tagnx_aw_put_length |
| 329 | func nx_aw_wrap_implicit_primitive(out: *u8, cap: i64, off: i64, |
| 344 | func nx_aw_put_raw(out: *u8, cap: i64, off: i64, |