code wiki / (root) / nx_asn1.nx

nx_asn1.nx

buildroot/runtime/nx_asn1.nx

7238 B199 linesdepth 2pulls 2 transitivereach 596 importersview sourcekind tooltopic asn1
docsdependenciesstructsconstsfunctions

about

asn1.nx -- ASN.1 DER TLV (Tag-Length-Value) primitives. Distinguished Encoding Rules (ITU-T X.690) reader. DER is the canonical form every X.509 cert uses, every TLS signature, every PKCS#8 key, every CMS message. We implement a reader-only subset -- write-side encoders are future work. DER structure: TLV byte sequence: - Tag: 1-N bytes. Low-tag-number form: 1 byte encoding class (bits 7-6), constructed flag (bit 5), tag (bits 4-0). High-tag-number form (tag >= 31): bits 4-0 = 0x1F, then tag in base-128 continuation bytes. X.509 uses low form exclusively in practice; we support both. - Length: 1-N bytes. Short form (0-127): single byte. Long form: byte 0x80+n indicates n bytes of length follow, big-endian. n <= 126; indefinite-length form (0x80) is explicitly forbidden in DER. - Value: length bytes, content depends on tag. Tags relevant to X.509: 0x02 INTEGER 0x03 BIT STRING 0x04 OCTET STRING 0x05 NULL 0x06 OBJECT IDENTIFIER 0x0C UTF8String 0x13 PrintableString 0x17 UTCTime 0x18 GeneralizedTime 0x30 SEQUENCE (constructed) 0x31 SET (constructed) 0xA0-0xA7 context-specific [0]..[7] Invariants: A1 All reads bounds-check against the caller-supplied length. Negative return signals either "invalid input" (malformed DER) or "out of bounds" (read would exceed buffer). A2 Length field rejects indefinite-length form (DER forbids). A3 No recursion; callers drive descent explicitly.

dependencies 1 imports · 10 importers

nx_syscalls.nx nx_asn1.nx nx_ecdsa_sig_der.nx nx_ecdsa_sig_der_384.nx nx_x509.nx nx_x509_pubkey_alg.nx nx_x509_pubkey_rsa.nx nx_x509_pubkey_rsa_4096.nx nx_x509_san.nx nx_x509_sig_alg.nx nx_x509_validity.nx nx_x509_validity_test.nx

imports: nx_syscalls.nx

imported by: nx_ecdsa_sig_der.nxnx_ecdsa_sig_der_384.nxnx_x509.nxnx_x509_pubkey_alg.nxnx_x509_pubkey_rsa.nxnx_x509_pubkey_rsa_4096.nxnx_x509_san.nxnx_x509_sig_alg.nxnx_x509_validity.nxnx_x509_validity_test.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap asn1_cursor_init asn1_expect_tag sys_mmap ↻ asn1_read_tlv_header asn1_read_tag asn1_read_length

structs

74struct Asn1Cursor

consts

53const ASN1_INTEGER: i64 = 0x02
54const ASN1_BIT_STRING: i64 = 0x03
55const ASN1_OCTET_STRING: i64 = 0x04
56const ASN1_NULL: i64 = 0x05
57const ASN1_OID: i64 = 0x06
58const ASN1_UTF8: i64 = 0x0C
59const ASN1_PRINTABLE: i64 = 0x13
60const ASN1_UTC_TIME: i64 = 0x17
61const ASN1_GENERALIZED: i64 = 0x18
62const ASN1_SEQUENCE: i64 = 0x30
63const ASN1_SET: i64 = 0x31
66const ASN1_ERR_OOB: i64 = -1
67const ASN1_ERR_INDEFINITE: i64 = -2
68const ASN1_ERR_TAG_OVERFLOW:i64 = -3
69const ASN1_ERR_LENGTH_BAD: i64 = -4

functions

80func asn1_cursor_init(c: *Asn1Cursor, len: i64) -> i64
89func asn1_read_tag(buf: *u8, c: *Asn1Cursor) -> i64
115func asn1_read_length(buf: *u8, c: *Asn1Cursor) -> i64
139func asn1_read_tlv_header(buf: *u8, c: *Asn1Cursor,
154func asn1_skip_value(c: *Asn1Cursor, len: i64) -> i64
164func asn1_expect_tag(buf: *u8, c: *Asn1Cursor,
181func main() -> i64