ASN.1 Abstract Syntax
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.
Basic combinators
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.
Tags
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.
Combining constructs
An 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.
val sequence5 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> ('a * 'b * 'c * 'd * 'e) tval sequence6 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> 'f element -> ('a * 'b * 'c * 'd * 'e * 'f) tset2 e1 e2 is set (e1 -@ e2). Other setN functions are analogous.
val set5 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> ('a * 'b * 'c * 'd * 'e) tval set6 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> 'f element -> ('a * 'b * 'c * 'd * 'e * 'f) tchoice2 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 choice5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> [ `C1 of 'a | `C2 of 'b | `C3 of 'c | `C4 of 'd | `C5 of 'e ] tval choice6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> [ `C1 of 'a | `C2 of 'b | `C3 of 'c | `C4 of 'd | `C5 of 'e | `C6 of 'f ] tPrimitives
val bool : bool tbool is ASN.1 BOOLEAN.
val bit_string : bool array tbit_string is ASN.1 BIT STRING.
bit_string_cs is ASN.1 BIT STRING, represented as Cstruct.t, and padded with 0-bits up to the next full octet.
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.
String primitives
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 tAdditional primitives
val int : int tint is ASN.1 INTEGER, projected into an OCaml int.
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.
Errors
val parse_error : ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'aparse_error fmt ... aborts parsing with the message produced by using fmt to format arguments ....