aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/doc/src/asn1ct.xml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/doc/src/asn1ct.xml')
-rw-r--r--lib/asn1/doc/src/asn1ct.xml334
1 files changed, 181 insertions, 153 deletions
diff --git a/lib/asn1/doc/src/asn1ct.xml b/lib/asn1/doc/src/asn1ct.xml
index 32ff2d52cf..30808a5ead 100644
--- a/lib/asn1/doc/src/asn1ct.xml
+++ b/lib/asn1/doc/src/asn1ct.xml
@@ -35,43 +35,45 @@
<modulesummary>ASN.1 compiler and compile-time support functions</modulesummary>
<description>
<p>The ASN.1 compiler takes an ASN.1 module as input and generates a
- corresponding Erlang module which can encode and decode the data-types
- specified. Alternatively the compiler takes a specification module
- (se below) specifying all input modules and generates one module with
- encode/decode functions. There are also some generic functions which
- can be used in during development of applications which handles ASN.1
- data (encoded as BER or PER).</p>
+ corresponding Erlang module, which can encode and decode the specified
+ data types. Alternatively, the compiler takes a specification module
+ specifying all input modules, and generates a module with
+ encode/decode functions. In addition, some generic functions
+ can be used during development of applications that handles ASN.1
+ data (encoded as <c>BER</c> or <c>PER</c>).</p>
+
<note>
- <p>By default in OTP 17, the representation of the BIT STRING
- and OCTET STRING types as Erlang terms have changed. BIT
- STRING values are now Erlang bitstrings and OCTET STRING values
- are binaries. Also, an undecoded open type will now be wrapped in
- a <c>asn1_OPENTYPE</c> tuple. For details see <seealso
- marker="asn1_ug#BIT STRING">BIT STRING</seealso>, <seealso
- marker="asn1_ug#OCTET STRING">OCTET STRING</seealso>, and
- <seealso marker="asn1_ug#Information%20Object">ASN.1 Information Objects</seealso> in User's Guide.</p>
- <p>To revert to the old representation of the types, use the
- <c>legacy_erlang_types</c> option.</p>
+ <p>By default in OTP 17, the representation of the <c>BIT STRING</c>
+ and <c>OCTET STRING</c> types as Erlang terms were changed. <c>BIT
+ STRING</c> values are now Erlang bit strings and <c>OCTET STRING</c>
+ values are binaries. Also, an undecoded open type is now wrapped in
+ an <c>asn1_OPENTYPE</c> tuple. For details, see <seealso
+ marker="asn1_getting_started#BIT STRING">BIT STRING</seealso>, <seealso
+ marker="asn1_getting_started#OCTET STRING">OCTET STRING</seealso>, and
+ <seealso marker="asn1_getting_started#Information Object">ASN.1 Information Objects</seealso> in the User's Guide.</p>
+ <p>To revert to the old representation of the types, use option
+ <c>legacy_erlang_types</c>.</p>
</note>
+
<note>
- <p>In R16, the options have been simplified. The back-end is chosen
+ <p>In OTP R16, the options were simplified. The back end is chosen
using one of the options <c>ber</c>, <c>per</c>, or <c>uper</c>.
- The options <c>optimize</c>, <c>nif</c>, and <c>driver</c> options
- are no longer necessary (and the ASN.1 compiler will print a
- warning if they are used). The options <c>ber_bin</c>, <c>per_bin</c>,
- and <c>uper_bin</c> options will still work, but will print a warning.
+ Options <c>optimize</c>, <c>nif</c>, and <c>driver</c> options
+ are no longer necessary (and the ASN.1 compiler generates a
+ warning if they are used). Options <c>ber_bin</c>, <c>per_bin</c>,
+ and <c>uper_bin</c> options still work, but generates a warning.
</p>
- <p>Another change in R16 is that the generated <c>encode/2</c>
- function always returns a binary.
- The <c>encode/2</c> function for the BER back-end used to return
- an iolist.</p>
+ <p>Another change in OTP R16 is that the generated function
+ <c>encode/2</c> always returns a binary. Function <c>encode/2</c>
+ for the <c>BER</c> back end used to return an iolist.</p>
</note>
</description>
+
<funcs>
<func>
<name>compile(Asn1module) -> ok | {error, Reason}</name>
<name>compile(Asn1module, Options) -> ok | {error, Reason}</name>
- <fsummary>Compile an ASN.1 module and generate encode/decode functions according to the encoding rules BER or PER.</fsummary>
+ <fsummary>Compiles an ASN.1 module and generates encode/decode functions according to encoding rules BER or PER.</fsummary>
<type>
<v>Asn1module = atom() | string()</v>
<v>Options = [Option| OldOption]</v>
@@ -85,79 +87,82 @@
<v>Prefix = string()</v>
</type>
<desc>
- <p>Compiles the ASN.1 module <c>Asn1module</c> and generates an
- Erlang module <c>Asn1module.erl</c> with encode and decode
+ <p>Compiles the <c>ASN.1</c> module <c>Asn1module</c> and generates
+ an Erlang module <c>Asn1module.erl</c> with encode and decode
functions for the types defined in <c>Asn1module</c>. For each
- ASN.1 value defined in the module an Erlang function which
+ ASN.1 value defined in the module, an Erlang function that
returns the value in Erlang representation is generated.</p>
- <p>If <c>Asn1module</c> is a filename without extension first
- <c>".asn1"</c> is assumed, then <c>".asn"</c> and finally
+ <p>If <c>Asn1module</c> is a filename without extension, first
+ <c>".asn1"</c> is assumed, then <c>".asn"</c>, and finally
<c>".py"</c> (to be compatible with the old ASN.1 compiler).
- Of course <c>Asn1module</c> can be a full pathname (relative or
+ <c>Asn1module</c> can be a full pathname (relative or
absolute) including filename with (or without) extension.
<marker id="asn1set"></marker>
</p>
- <p>If one wishes to compile a set of Asn1 modules into one
- Erlang file with encode/decode functions one has to list all
+ <p>If it is needed to compile a set of <c>ASN.1</c> modules into an
+ Erlang file with encode/decode functions, ensure to list all
involved files in a configuration file. This configuration
- file must have a double extension ".set.asn", (".asn" can
- alternatively be ".asn1" or ".py"). The input files' names
- must be listed, within quotation marks (""), one at each row
+ file must have a double extension <c>".set.asn"</c>
+ (<c>".asn"</c> can alternatively be <c>".asn1"</c> or <c>".py"</c>).
+ List the input file names
+ within quotation marks (""), one at each row
in the file. If the input files are <c>File1.asn</c>,
- <c>File2.asn</c> and <c>File3.asn</c> the configuration file
- shall look like:</p>
+ <c>File2.asn</c>, and <c>File3.asn</c>, the configuration file
+ must look as follows:</p>
<pre>
File1.asn
File2.asn
-File3.asn </pre>
- <p>The output files will in this case get their names from the
- configuration file. If the configuration file has the name
- <c>SetOfFiles.set.asn</c> the name of the output files will be
- <c>SetOfFiles.hrl, SetOfFiles.erl and SetOfFiles.asn1db</c>.</p>
- <p>Sometimes in a system of ASN.1 modules there are different
- default tag modes, e.g. AUTOMATIC, IMPLICIT or EXPLICIT. The
- multi file compilation resolves the default tagging as if
+File3.asn</pre>
+ <p>The output files in this case get their names from the
+ configuration file. If the configuration file is named
+ <c>SetOfFiles.set.asn</c>, the names of the output files are
+ <c>SetOfFiles.hrl, SetOfFiles.erl, and SetOfFiles.asn1db</c>.</p>
+ <p>Sometimes in a system of <c>ASN.1</c> modules, different
+ default tag modes, for example, <c>AUTOMATIC</c>, <c>IMPLICIT</c>,
+ or <c>EXPLICIT</c>. The
+ multi-file compilation resolves the default tagging as if
the modules were compiled separately.</p>
- <p>Another unwanted effect that may occur in multi file compilation
- is name collisions. The compiler solves this problem in two
- ways: If the definitions are identical then the output module
- keeps only one definition with the original name. But if
- definitions only have same name and differs in the definition,
- then they will be renamed. The new names will be the definition
- name and the original module name concatenated.</p>
- <p>If any name collision have occurred the compiler reports a
- "NOTICE: ..." message that tells if a definition was renamed,
+ <p>Name collisions is another unwanted effect that can occur in
+ multi file-compilation. The compiler solves this problem in one
+ of two ways:</p>
+ <list type="bulleted">
+ <item>If the definitions are identical, the output module
+ keeps only one definition with the original name.</item>
+ <item>If the definitions have the same name and differs in the
+ definition, they are renamed. The new names are the definition
+ name and the original module name concatenated.</item>
+ </list>
+ <p>If a name collision occurs, the compiler reports a
+ <c>"NOTICE: ..."</c> message that tells if a definition was renamed,
and the new name that must be used to encode/decode data.</p>
-
- <p>
- <c>Options</c> is a list with options specific for the asn1
+ <p><c>Options</c> is a list with options specific for the <c>ASN.1</c>
compiler and options that are applied to the Erlang compiler.
- The latter are those that not is recognized as asn1 specific.
- Available options are:
+ The latter are not recognized as <c>ASN.1</c> specific. The
+ available options are as follows:
</p>
<taglist>
<tag><c>ber | per | uper</c></tag>
<item>
<p>
The encoding rule to be used. The supported encoding rules
- are BER (Basic Encoding Rules),
- PER aligned (Packed Encoding Rules) and PER unaligned.
- If the encoding rule option is omitted <c>ber</c>
+ are Basic Encoding Rules (BER),
+ Packed Encoding Rules (PER) aligned, and PER unaligned.
+ If the encoding rule option is omitted, <c>ber</c>
is the default.
</p>
<p>
The generated Erlang module always gets the same name
- as the ASN.1 module and as a consequence of this only one
- encoding rule per ASN.1 module can be used at runtime.
+ as the <c>ASN.1</c> module. Therefore, only one
+ encoding rule per <c>ASN.1</c> module can be used at runtime.
</p>
</item>
<tag><c>der</c></tag>
<item>
<p>
- By this option the Distinguished Encoding Rules (DER) is chosen.
+ With this option the Distinguished Encoding Rules (DER) is chosen.
DER is regarded as a specialized variant of the BER encoding
- rule, therefore the <c>der</c> option only makes sense together
- with the <c>ber</c> option.
+ rule. Therefore, this option only makes sense together
+ with option <c>ber</c>.
This option
sometimes adds sorting and value checks when encoding, which
implies a slower encoding. The decoding routines are the same
@@ -167,118 +172,123 @@ File3.asn </pre>
<tag><c>compact_bit_string</c></tag>
<item>
<p>
- The BIT STRING type will be decoded to the "compact notation".
+ The <c>BIT STRING</c> type is decoded to "compact notation".
<em>This option is not recommended for new code.</em>
</p>
- <p>For details see
- <seealso marker="asn1_ug#BIT STRING">
- BIT STRING type section in the Users Guide
- </seealso>.
+ <p>For details, see Section
+ <seealso marker="asn1_getting_started#BIT STRING">
+ BIT STRING</seealso> in the User's Guide.
</p>
- <p>This option implies the <c>legacy_erlang_types</c> option.</p>
+ <p>This option implies option <c>legacy_erlang_types</c>.</p>
</item>
<tag><c>legacy_bit_string</c></tag>
<item>
<p>
- The BIT STRING type will be decoded to the legacy
- format, i.e. a list of zeroes and ones.
+ The <c>BIT STRING</c> type is decoded to the legacy
+ format, that is, a list of zeroes and ones.
<em>This option is not recommended for new code.</em>
</p>
- <p>For details see
- <seealso marker="asn1_ug#BIT STRING">
- BIT STRING type section in the Users Guide
- </seealso>.
- <p>This option implies the <c>legacy_erlang_types</c> option.</p>
- </p>
+ <p>For details, see Section
+ <seealso marker="asn1_getting_started#BIT STRING">BIT STRING</seealso>
+ in the User's Guide</p>
+ <p>This option implies option <c>legacy_erlang_types</c>.</p>
</item>
<tag><c>legacy_erlang_types</c></tag>
<item>
- <p>Use the same Erlang types to represent BIT STRING and
- OCTET STRING as in R16. For details see <seealso
- marker="asn1_ug#BIT STRING">BIT STRING</seealso> and
- <seealso marker="asn1_ug#OCTET STRING">OCTET
- STRING</seealso> in User's Guide.</p>
- <p><em>This option is not recommended for
- new code.</em></p>
+ <p>Use the same Erlang types to represent <c>BIT STRING</c> and
+ <c>OCTET STRING</c> as in OTP R16.</p>
+ <p>For details, see Section <seealso
+ marker="asn1_getting_started#BIT STRING">BIT STRING</seealso> and Section
+ <seealso marker="asn1_getting_started#OCTET STRING">OCTET
+ STRING</seealso> in the User's Guide.</p>
+ <p><em>This option is not recommended for new code.</em></p>
</item>
<tag><c>{n2n, EnumTypeName}</c></tag>
<item>
<p>
- Tells the compiler to generate functions for conversion between
- names (as atoms) and numbers and vice versa for the EnumTypeName specified. There can be multiple occurrences of this option in order to specify several type names. The type names must be declared as ENUMERATIONS in the ASN.1 spec.
- If the EnumTypeName does not exist in the ASN.1 spec the
- compilation will stop with an error code.
- The generated conversion functions are named
+ Tells the compiler to generate functions for conversion
+ between names (as atoms) and numbers and conversely for
+ the specified <c>EnumTypeName</c>. There can be multiple
+ occurrences of this option to specify several type names.
+ The type names must be declared as <c>ENUMERATIONS</c> in
+ the ASN.1 specification.</p>
+ <p>
+ If <c>EnumTypeName</c> does not exist in the ASN.1 specification,
+ the compilation stops with an error code.</p>
+ <p>
+ The generated conversion functions are named
<c>name2num_EnumTypeName/1</c> and
<c>num2name_EnumTypeName/1</c>.
</p>
</item>
<tag><c>noobj</c></tag>
<item>
- <p>Do not compile (i.e do not produce object code) the generated
- <c>.erl</c> file. If this option is omitted the generated Erlang module
- will be compiled.</p>
+ <p>Do not compile (that is, do not produce object code) the
+ generated <c>.erl</c> file. If this option is omitted, the
+ generated Erlang module is compiled.</p>
</item>
<tag><c>{i, IncludeDir}</c></tag>
<item>
<p>Adds <c>IncludeDir</c> to the search-path for
- <c>.asn1db</c> and asn1 source files. The compiler tries
- to open a <c>.asn1db</c> file when a module imports
- definitions from another ASN.1 module. If no
- <c>.asn1db</c> file is found the asn1 source file is
- parsed. Several <c>{i, IncludeDir}</c> can be given.
+ <c>.asn1db</c> and <c>ASN.1</c> source files. The compiler
+ tries to open an <c>.asn1db</c> file when a module imports
+ definitions from another <c>ASN.1</c> module. If no
+ <c>.asn1db</c> file is found, the <c>ASN.1</c> source file is
+ parsed. Several <c>{i, IncludeDir}</c> can be given.
</p>
</item>
<tag><c>{outdir, Dir}</c></tag>
<item>
- <p>Specifies the directory <c>Dir</c> where all generated files
- shall be placed. If omitted the files are placed in the
- current directory.</p>
+ <p>Specifies directory <c>Dir</c> where all generated files
+ are to be placed. If this option is omitted, the files are
+ placed in the current directory.</p>
</item>
<tag><c>asn1config</c></tag>
<item>
- <p>When one of the specialized decodes, exclusive or
- selective decode, is wanted one has to give instructions in
- a configuration file. The option <c>asn1config</c> enables
- specialized decodes and takes the configuration file, which
- has the same name as the ASN.1 spec but with extension
- <c>.asn1config</c>, in concern.
+ <p>When using one of the specialized decodes, exclusive or
+ selective decode, instructions must be given in
+ a configuration file. Option <c>asn1config</c> enables
+ specialized decodes and takes the configuration file in
+ concern. The configuration file has
+ the same name as the ASN.1 specification, but with extension
+ <c>.asn1config</c>.
</p>
- <p>The instructions for exclusive decode must follow the
- <seealso marker="asn1_spec#Exclusive Instruction">instruction and grammar in the User's Guide</seealso>.
+ <p>For instructions for exclusive decode, see Section
+ <seealso marker="asn1_spec#Exclusive Instruction">Exclusive
+ Decode</seealso> in the User's Guide.
</p>
- <p>You can also find the instructions for selective decode
- in the
- <seealso marker="asn1_spec#Selective Instruction">User's Guide</seealso>.
+ <p>For instructions for selective decode, see Section
+ <seealso marker="asn1_spec#Selective Instruction">Selective
+ Decode</seealso> in the User's Guide.
</p>
</item>
<tag><c>undec_rest</c></tag>
<item>
- <p>A buffer that holds a message, being decoded may
- also have some following bytes. Now it is possible to get
- those following bytes returned together with the decoded
- value. If an asn1 spec is compiled with this option a tuple
- <c>{ok, Value, Rest}</c> is returned. <c>Rest</c> may be a
+ <p>A buffer that holds a message, being decoded it can also
+ have some following bytes. Those following bytes can now
+ be returned together with the decoded value. If an
+ ASN.1 specification is compiled with this option, a tuple
+ <c>{ok, Value, Rest}</c> is returned. <c>Rest</c> can be a
list or a binary. Earlier versions of the compiler ignored
those following bytes.</p>
</item>
<tag><c>no_ok_wrapper</c></tag>
<item>
- <p>If this option is given, the generated <c>encode/2</c>
- and <c>decode/2</c> functions will not wrap a successful
+ <p>With this option, the generated <c>encode/2</c>
+ and <c>decode/2</c> functions do not wrap a successful
return value in an <c>{ok,...}</c> tuple. If any error
- occurs, there will be an exception.</p>
+ occurs, an exception will be raised.</p>
</item>
<tag><c>{macro_name_prefix, Prefix}</c></tag>
<item>
<p>All macro names generated by the compiler are prefixed with
- <c>Prefix</c>. This is useful when multiple protocols that contains
+ <c>Prefix</c>. This is useful when multiple protocols that contain
macros with identical names are included in a single module.</p>
</item>
<tag><c>{record_name_prefix, Prefix}</c></tag>
<item>
<p>All record names generated by the compiler are prefixed with
- <c>Prefix</c>. This is useful when multiple protocols that contains
+ <c>Prefix</c>. This is useful when multiple protocols that contain
records with identical names are included in a single module.</p>
</item>
<tag><c>verbose</c></tag>
@@ -291,27 +301,27 @@ File3.asn </pre>
<p>Causes warnings to be treated as errors.</p>
</item>
</taglist>
- <p>Any additional option that is applied will be passed to
- the final step when the generated .erl file is compiled.
+ <p>Any more option that is applied is passed to
+ the final step when the generated <c>.erl</c> file is compiled.
</p>
<p>The compiler generates the following files:</p>
<list type="bulleted">
- <item>
- <p><c>Asn1module.hrl</c> (if any SET or SEQUENCE is defined)</p>
+ <item><c>Asn1module.hrl</c> (if any <c>SET</c> or <c>SEQUENCE</c>
+ is defined)
</item>
- <item>
- <p><c>Asn1module.erl</c> the Erlang module with encode, decode and value functions.</p>
+ <item><c>Asn1module.erl</c> - Erlang module with encode, decode,
+ and value functions
</item>
- <item>
- <p><c>Asn1module.asn1db</c> intermediate format used by the compiler when modules IMPORTS
- definitions from each other.</p>
+ <item><c>Asn1module.asn1db</c> - Intermediate format used by the
+ compiler when modules <c>IMPORT</c> definitions from each other.
</item>
</list>
</desc>
</func>
+
<func>
<name>encode(Module, Type, Value)-> {ok, Bytes} | {error, Reason}</name>
- <fsummary>Encode an ASN.1 value.</fsummary>
+ <fsummary>Encodes an ASN.1 value.</fsummary>
<type>
<v>Module = Type = atom()</v>
<v>Value = term()</v>
@@ -319,11 +329,11 @@ File3.asn </pre>
<v>Reason = term()</v>
</type>
<desc>
- <p>Encodes <c>Value</c> of <c>Type</c> defined in the ASN.1 module
- <c>Module</c>. To get as fast execution as possible the
- encode function only performs rudimentary tests that the input
- <c>Value</c>
- is a correct instance of <c>Type</c>. The length of strings is for example
+ <p>Encodes <c>Value</c> of <c>Type</c> defined in the <c>ASN.1</c> module
+ <c>Module</c>. To get as fast execution as possible, the
+ encode function performs only the rudimentary tests that input
+ <c>Value</c> is a correct instance of <c>Type</c>. So, for example,
+ the length of strings is
not always checked. Returns <c>{ok, Bytes}</c> if successful or
<c>{error, Reason}</c> if an error occurred.
</p>
@@ -331,6 +341,7 @@ File3.asn </pre>
Use <c>Module:encode(Type, Value)</c> instead.</p>
</desc>
</func>
+
<func>
<name>decode(Module, Type, Bytes) -> {ok, Value} | {error, Reason}</name>
<fsummary>Decode from Bytes into an ASN.1 value.</fsummary>
@@ -346,26 +357,37 @@ File3.asn </pre>
Use <c>Module:decode(Type, Bytes)</c> instead.</p>
</desc>
</func>
+
<func>
<name>value(Module, Type) -> {ok, Value} | {error, Reason}</name>
- <fsummary>Create an ASN.1 value for test purposes.</fsummary>
+ <fsummary>Creates an ASN.1 value for test purposes.</fsummary>
<type>
<v>Module = Type = atom()</v>
<v>Value = term()</v>
<v>Reason = term()</v>
</type>
<desc>
- <p>Returns an Erlang term which is an example of a valid Erlang
- representation of a value of the ASN.1 type <c>Type</c>. The value
+ <p>Returns an Erlang term that is an example of a valid Erlang
+ representation of a value of the <c>ASN.1</c> type <c>Type</c>. The value
is a random value and subsequent calls to this function will for most
types return different values.</p>
+ <note>
+ <p>Currently, the <c>value</c> function has many limitations.
+ Essentially, it will mostly work for old specifications based
+ on the 1997 standard for ASN.1, but not for most modern-style
+ applications. Another limitation is that the <c>value</c> function
+ may not work if options that change code generations strategies
+ such as the options <c>macro_name_prefix</c> and
+ <c>record_name_prefix</c> have been used.</p>
+ </note>
</desc>
</func>
+
<func>
<name>test(Module) -> ok | {error, Reason}</name>
<name>test(Module, Type | Options) -> ok | {error, Reason}</name>
<name>test(Module, Type, Value | Options) -> ok | {error, Reason}</name>
- <fsummary>Perform a test of encode and decode for types in an ASN.1 module.</fsummary>
+ <fsummary>Performs a test of encode and decode for types in an ASN.1 module.</fsummary>
<type>
<v>Module = Type = atom()</v>
<v>Value = term()</v>
@@ -376,9 +398,17 @@ File3.asn </pre>
<p>Performs a test of encode and decode of types in <c>Module</c>.
The generated functions are called by this function.
This function is useful during test to secure that the generated
- encode and decode functions and the general runtime support work
- as expected.</p>
-
+ encode and decode functions as well as the general runtime support
+ work as expected.</p>
+ <note>
+ <p>Currently, the <c>test</c> functions have many limitations.
+ Essentially, they will mostly work for old specifications based
+ on the 1997 standard for ASN.1, but not for most modern-style
+ applications. Another limitation is that the <c>test</c> functions
+ may not work if options that change code generations strategies
+ such as the options <c>macro_name_prefix</c> and
+ <c>record_name_prefix</c> have been used.</p>
+ </note>
<list type="bulleted">
<item>
<p><c>test/1</c> iterates over all types in <c>Module</c>.</p>
@@ -390,14 +420,12 @@ File3.asn </pre>
<p><c>test/3</c> tests type <c>Type</c> with <c>Value</c>.</p>
</item>
</list>
-
- <p>Schematically the following happens for each type in the module:</p>
+ <p>Schematically, the following occurs for each type in the module:</p>
<code type="none">
{ok, Value} = asn1ct:value(Module, Type),
{ok, Bytes} = asn1ct:encode(Module, Type, Value),
{ok, Value} = asn1ct:decode(Module, Type, Bytes).</code>
-
- <p>The <c>test</c> functions utilizes the <c>*.asn1db</c> files
+ <p>The <c>test</c> functions use the <c>*.asn1db</c> files
for all included modules. If they are located in a different
directory than the current working directory, use the include
option to add paths. This is only needed when automatically