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) t
val sequence6 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> 'f element -> ('a * 'b * 'c * 'd * 'e * 'f) t
set2 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) t
val set6 : 'a element -> 'b element -> 'c element -> 'd element -> 'e element -> 'f element -> ('a * 'b * 'c * 'd * 'e * 'f) t
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 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 ] t
val 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 ] t
Primitives
val bool : bool t
bool
is ASN.1 BOOLEAN
.
val bit_string : bool array t
bit_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 t
null
is ASN.1 NULL
.
val enumerated : (int -> 'a) -> ('a -> int) -> 'a t
enumerated 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 t
val numeric_string : string t
val printable_string : string t
val teletex_string : string t
val videotex_string : string t
val ia5_string : string t
val graphic_string : string t
val visible_string : string t
val general_string : string t
val universal_string : string t
val bmp_string : string t
Additional primitives
val int : int t
int
is ASN.1 INTEGER
, projected into an OCaml int
.
val bit_string_flags : (int * 'a) list -> 'a list t
bit_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 -> 'a
parse_error fmt ...
aborts parsing with the message produced by using fmt
to format arguments ...
.