code wiki / (root) / asn1.nx

asn1.nx

buildroot/runtime/asn1.nx

7177 B193 linesdepth 3pulls 3 transitivereach 1 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 · 1 importers

syscalls.nx asn1.nx x509.nx

imports: syscalls.nx

imported by: x509.nx

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

main asn1_cursor_init asn1_expect_tag asn1_read_tlv_header asn1_read_tag asn1_read_length

structs

68struct Asn1Cursor {

consts

47const ASN1_INTEGER: i64 = 0x02
48const ASN1_BIT_STRING: i64 = 0x03
49const ASN1_OCTET_STRING: i64 = 0x04
50const ASN1_NULL: i64 = 0x05
51const ASN1_OID: i64 = 0x06
52const ASN1_UTF8: i64 = 0x0C
53const ASN1_PRINTABLE: i64 = 0x13
54const ASN1_UTC_TIME: i64 = 0x17
55const ASN1_GENERALIZED: i64 = 0x18
56const ASN1_SEQUENCE: i64 = 0x30
57const ASN1_SET: i64 = 0x31
60const ASN1_ERR_OOB: i64 = -1
61const ASN1_ERR_INDEFINITE: i64 = -2
62const ASN1_ERR_TAG_OVERFLOW:i64 = -3
63const ASN1_ERR_LENGTH_BAD: i64 = -4

functions

74func asn1_cursor_init(c: *Asn1Cursor, len: i64) -> i64 {
called by 2: mainx509_parse
83func asn1_read_tag(buf: *u8, c: *Asn1Cursor) -> i64 {
109func asn1_read_length(buf: *u8, c: *Asn1Cursor) -> i64 {
133func asn1_read_tlv_header(buf: *u8, c: *Asn1Cursor,
148func asn1_skip_value(c: *Asn1Cursor, len: i64) -> i64 {
158func asn1_expect_tag(buf: *u8, c: *Asn1Cursor,
175func main() -> i64 {