Asn.SASN.1 Abstract Syntax.
This module is the OCaml term-level analogue of ASN.1's surface notation.
It provides a ground type 'a t representing typed abstract syntax, a suite of primitives that correspond to ASN.1 primitives, and a suite of combinators that correspond to the combining structures of ASN.1.
ASN.1 naming and modules are not supported; these are provided by the host language instead.
type nonrec 'a t = 'a t'a t denotes a particular structure of data, irrespective of any encoding, that is represented by 'a in OCaml.
fix fasn is the fixpoint, allowing fasn to construct a syntax that refers to itself.
map ?random f g asn creates a derived syntax that encodes and decodes like asn, but uses f to project and g to inject.
~random is a function that generates random samples of 'b. Defaults to f a where a is a random 'a.
implicit ?cls n asn is the ASN.1 IMPLICIT construct, changing the tag of asn to (cls, n).
n is the tag value.
~cls is the class. Defaults to CONTEXT SPECIFIC.
Note implicit implicitly becomes explicit when applied to nodes that cannot be made IMPLICIT, like CHOICE. This is consistent with X.608 (see 31.2.7) in case of a bare tag, and with the common practice in case of a tag marked as IMPLICIT.
explicit ?cls n asn is the ASN.1 EXPLICIT construct, changing the tag of asn to (cls, n).
n is the tag value.
~cls is the class. Defaults to CONTEXT SPECIFIC.
These look like
sequence @@
(required ~label:"l1" asn1)
@ (optional ~label:"l2" asn2)
@ (required ~label:"l3" asn3)
-@ (optional ~label:"l4" asn4)or
choice3 asn1 asn2 asn3An element is a single slot in a sequence.
required ?label asn is a regular sequence element.
~label is the name of the element.
optional ?label asn is a sequence element marked with the ASN.1 OPTIONAL keyword.
~label is the name of the element.
sequence2 e1 e2 is sequence (e1 -@ e2). Other sequenceN functions are analogous.
set2 e1 e2 is set (e1 -@ e2). Other setN functions are analogous.
choice2 asn1 asn2 is the ASN.1 CHOICE construct, choosing between asn1 and asn2. Other choiceN functions are analogous.
Larger CHOICE can be obtained by nesting choice variants.
Note CHOICE containing elements with the same tag yields an illegal syntax. This will be detected by codec.
val bool : bool tbool is ASN.1 BOOLEAN.
val integer : string tinteger is ASN.1 INTEGER. The representation is a string. Be aware these are two's complement signed integers, in order to encode a positive number where the first bit is set (i.e. 128 = 0x80), you have to prepend a 0 byte: 0x00 0x80. Otherwise it (0x80) will be decoded as -128. See unsigned_integer for automated two's complement transformations.
val bit_string : bool array tbit_string is ASN.1 BIT STRING.
val bit_string_octets : string tbit_string_octets is ASN.1 BIT STRING, represented as string, and padded with 0-bits up to the next full octet.
val octet_string : string toctet_string is ASN.1 OCTET STRING.
val null : unit tnull is ASN.1 NULL.
val enumerated : (int -> 'a) -> ('a -> int) -> 'a tenumerated f g is ASN.1 ENUMERATED, with f projecting from, and g injecting into an int.
The full INTEGER range is not supported.
val generalized_time : Ptime.t tgeneralized_time is ASN.1 GeneralizedTime.
val utc_time : Ptime.t tutc_time is ASN.1 UTCTime.
Representable years are 1950–2049.
Various ASN.1 stringy types.
Note Presently, no conversion or validation is performed on strings. They differ only in tags.
val utf8_string : string tval numeric_string : string tval printable_string : string tval teletex_string : string tval videotex_string : string tval ia5_string : string tval graphic_string : string tval visible_string : string tval general_string : string tval universal_string : string tval bmp_string : string tval int : int tint is ASN.1 INTEGER, projected into an OCaml int.
val unsigned_integer : string tunsigned_integer is ASN.1 INTEGER, where the necessary two's complement transformations are already applied. That is, it represents unsigned integers encoded as ASN.1 (signed) INTEGERs. Negative ASN.1 INTEGERs are rejected with a parse error.
val bit_string_flags : (int * 'a) list -> 'a list tbit_string_flags xs is ASN.1 BIT STRING, represented as a collection of values.
xs is a list of (bit, x), where bit bit denotes the presence of x.