ASN1_COMPILE(1)
πΈ asn1_compile πΈ
okay so this is the General Commands Manual entry for asn1_compile(1), and bestie, it is the tool for compiling ASN.1 modules. no cap. π
π NAME π
asn1_compile β compile ASN.1 modules.
β¨ SYNOPSIS β¨
the vibe is literally:
asn1_compile [--template] [--prefix-enum] [--enum-prefix=PREFIX]
[--encode-rfc1510-bit-string] [--decode-dce-ber]
[--support-ber] [--preserve-binary=TYPE] [--sequence=TYPE]
[--decorate=DECORATION] [--one-code-file] [--gen-name=NAME]
[--option-file=FILE] [--original-order] [--no-parse-units]
[--type-file=C-HEADER-FILE] [--version] [--help]
[FILE.asn1 [NAME]]
π¦ DESCRIPTION π¦
asn1_compile compiles an ASN.1 module into C source code and header files. literally its whole job. π«Ά
okay so hereβs the range: a fairly large subset of ASN.1 as specified in X.680, plus the ASN.1 Information Object System as specified in X.681, X.682, and X.683, is supported β with support for the Distinguished Encoding Rules (DER), partial Basic Encoding Rules (BER) support, and experimental JSON support (encoding only at this time). β¨
See the compiler's README files for details about the C code and interfaces it generates.
The Information Object System support includes automatic codec support for encoding and decoding through βopen typesβ which are also known as βtyped holesβ. See RFC 5912 for examples of how to use the ASN.1 Information Object System via X.681/X.682/X.683 annotations. See the compiler's README files for more information on ASN.1 Information Object System support. π§
Extensions specific to Heimdal are generally not syntactic in nature β theyβre command-line options to this program. For example, one can use command-line options to:
- enable decoding of BER-encoded values;
- enable RFC1510-style handling of β
BIT STRINGβ types; - enable saving of as-received encodings of specific types for the purpose of signature validation;
- generate add/remove utility functions for array types;
- decorate generated β
structβ types with fields that are neither encoded nor decoded; - etc.
π ASN.1 x.680 features supported π
the supported list is giving:
- most primitive types (except
BMPStringandREAL); - all constructed types, including
SETandSET OF; - explicit and implicit tagging.
Size and range constraints on the INTEGER type cause the compiler to generate appropriate C types such as int, unsigned int, int64_t, uint64_t. Unconstrained INTEGER is treated as heim_integer, which represents an integer of arbitrary size. π₯
π Caveats and ASN.1 x.680 features not supported π
not-supported tea, so you know:
- JSON encoding support is not quite X.697 (JER) compatible. Its JSON schema is subject to change without notice.
- Control over C types generated is very limited, mainly only for integer types.
- When using the template backend,
SET { .. }types are currently not sorted by tag as they should be, but if the module author sorts them by hand then correct DER will be produced. - β
AUTOMATIC TAGSβ is not supported. - The
REALtype is not supported. - The
EmbeddedPDVtype is not supported. - The
BMPStringtype is not supported. - The
IA5Stringis not properly supported, as it's essentially treated as aUTF8Stringwith a different tag. - All supported non-octet strings are treated as like the
UTF8Stringtype. - Only types can be imported into ASN.1 modules at this time.
- Only simple value syntax is supported. Constructed value syntax (i.e., values of
SET,SEQUENCE,SET OF, andSEQUENCE OFtypes), is not supported. Values ofCHOICEtypes are also not supported.
π Options supported π
--templateβ use the βtemplateβ backend instead of the βcodegenβ backend (which is the default backend). The template backend generates βtemplatesβ which are akin to bytecode, and which are interpreted at run-time. The codegen backend generates C code for all functions directly, with no template interpretation. The template backend scales better than the codegen backend because as we add support for more encoding rules and more operations (we may add value comparators) the templates stay mostly the same, thus scaling linearly with size of module. Whereas the codegen backend scales linear with the product of module size and number of encoding rules supported. π--prefix-enumβ this option should be removed becauseENUMERATEDtypes should always have their labels prefixed. yes, the man page is literally saying remove it. π--enum-prefix=PREFIXβ this option should be removed becauseENUMERATEDtypes should always have their labels prefixed. same energy. π--encode-rfc1510-bit-stringβ use RFC1510, non-standard handling of βBIT STRINGβ types.--decode-dce-berβ no description in the original page, bestie; itβs just listed. π--support-berβ also no description in the original page; just vibing in the option list. π--preserve-binary=TYPEβ generate a field named_savein the C struct generated for the namedTYPE. This field is used to preserve the original encoding of the value of theTYPE. This is useful for cryptographic applications so that they can check signatures of encoded values as-received without having to re-encode those values. For example, theTBSCertificatetype should have values preserved so thatCertificatevalidation can check thesignatureValueover thetbsCertificate's value as-received. The alternative of encoding a value to check a signature of it is brittle. For types where non-canonical encodings (such as BER) are allowed, this alternative is bound to fail. Thus the point of this option.--sequence=TYPEβ generate add/remove functions for the named ASN.1TYPEwhich must be aSET OForSEQUENCE OFtype.--decorate=ASN1-TYPE:FIELD-ASN1-TYPE:fname[?]β add to the C struct generated for the given ASN.1SET,SEQUENCE, orCHOICEtype namedASN1-TYPEa βhiddenβ field namedfnameof the given ASN.1 typeFIELD-ASN1-TYPE, but do not encode or decode it. If thefnameends in a question mark, then treat the field asOPTIONAL. This is useful for adding fields to existing types that can be used for internal bookkeeping but which do not affect interoperability because they are neither encoded nor decoded. For example, one might decorate a request type with state needed during processing of the request.--decorate=ASN1-TYPE:void*:fnameβ add to the C struct generated for the given ASN.1SET,SEQUENCE, orCHOICEtype namedASN1-TYPEa βhiddenβ field namedfnameof typevoid *(but do not encode or decode it). The destructor and copy constructor functions generated by this compiler forASN1-TYPEwill set this field to theNULLpointer.--decorate=ASN1-TYPE:FIELD-C-TYPE:fname[?]:[copyfn]:[freefn]:headerβ add to the C struct generated for the given ASN.1SET,SEQUENCE, orCHOICEtype namedASN1-TYPEa βhiddenβ field namedfnameof the given external C typeFIELD-C-TYPE, declared in the givenheaderbut do not encode or decode this field. If thefnameends in a question mark, then treat the field asOPTIONAL. Theheadermust include double quotes or angle brackets. Thecopyfnmust be the name of a copy constructor function that takes a pointer to a source value of the type, and a pointer to a destination value of the type, in that order, and which returns zero on success or else a system error code on failure. Thefreefnmust be the name of a destructor function that takes a pointer to a value of the type and which releases resources referenced by that value, but does not free the value itself (the run-time allocates this value as needed from the C heap). Thefreefnshould also reset the value to a pristine state (such as all zeros). If thecopyfnandfreefnare empty strings, then the decoration field will neither be copied nor freed by the functions generated for theTYPE.--one-code-fileβ generate a single source code file. Otherwise a separate code file will be generated for every type.--gen-name=NAMEβ useNAMEto form the names of the files generated.--option-file=FILEβ take additional command-line options fromFILE. The options file must have one command-line option per-line, but leading whitespace is ignored, and lines that start with a hash symbol (#) are comments and are ignored.--original-orderβ attempt to preserve the original order of type definition in the ASN.1 module. By default the compiler generates types in a topological sort order.--no-parse-unitsβ do not generate to-int / from-int functions for enumeration types.--type-file=C-HEADER-FILEβ generate an include of the named header file that might be needed for common type definitions.--versionβ no description in the original page. just the flag. π--helpβ same: no description in the original page. β¨
π NOTES π
Currently only the template backend supports automatic encoding and decoding of open types via the ASN.1 Information Object System and X.681/X.682/X.683 annotations. so if youβre expecting open-type magic from another backend, bestie, thatβs the note. π
β HEIMDAL, February 22, 2021 π
π¦ where this page comes from
- nixpkgs unstable: heimdal 7.8.0-unstable-2024-09-10
- Copyright (c) 2019 Kungliga Tekniska HΓΆgskolan
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms