Library
Module
Module type
Parameter
Class
Class type
ASN.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 asn3
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.
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 t
bool
is ASN.1 BOOLEAN
.
val bit_string : bool array t
bit_string
is ASN.1 BIT STRING
.
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.
Various ASN.1 stringy types.
Note Presently, no conversion or validation is performed on strings. They differ only in tags.
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
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
.
val parse_error : ('a, Format.formatter, unit, 'b) format4 -> 'a
parse_error fmt ...
aborts parsing with the message produced by using fmt
to format arguments ...
.