~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/asn1/doc/src/asn1ct.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>1999</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>asn1ct</title>
 
27
    <prepared>Kenneth Lundin</prepared>
 
28
    <responsible>Kenneth Lundin</responsible>
 
29
    <docno>1</docno>
 
30
    <approved>Kenneth Lundin</approved>
 
31
    <checked></checked>
 
32
    <date>97-10-14</date>
 
33
    <rev>A</rev>
 
34
    <file>asn1.sgml</file>
 
35
  </header>
 
36
  <module>asn1ct</module>
 
37
  <modulesummary>ASN.1 compiler and compile-time support functions</modulesummary>
 
38
  <description>
 
39
    <p>The ASN.1 compiler takes an ASN.1 module as input and genarates a 
 
40
      corresponding Erlang module which can encode and decode the datatypes
 
41
      specified. Alternatively the compiler takes a specification module 
 
42
      (se below) specifying all input modules and generates one module with 
 
43
      encode/decode functions. There are also some generic functions which
 
44
      can be used in during development of applications which handles ASN.1
 
45
      data (encoded as BER or PER).</p>
 
46
  </description>
 
47
  <funcs>
 
48
    <func>
 
49
      <name>compile(Asn1module) -> ok | {error,Reason}</name>
 
50
      <name>compile(Asn1module , Options) -> ok | {error,Reason}</name>
 
51
      <fsummary>Compile an ASN.1 module and generate encode/decode functions according to the encoding rules BER or PER.</fsummary>
 
52
      <type>
 
53
        <v>Asn1module = atom() | string()</v>
 
54
        <v>Options = [Option]</v>
 
55
        <v>Option = ber | per | ber_bin | per_bin | uper_bin | der | compact_bit_string | noobj | {outdir,Dir} | {i,IncludeDir} | optimize | asn1config | undec_rest | {inline,OutputName} | inline</v>
 
56
        <v>Reason = term()</v>
 
57
      </type>
 
58
      <desc>
 
59
        <p>Compiles the ASN.1 module <c>Asn1module</c> and generates an 
 
60
          Erlang module <c>Asn1module.erl</c> with encode and decode 
 
61
          functions for the types defined in <c>Asn1module</c>. For each 
 
62
          ASN.1 value defined in the module an Erlang function which 
 
63
          returns the value in Erlang representation is generated.</p>
 
64
        <p>If <c>Asn1module</c> is a filename without extension first
 
65
          <c>".asn1"</c> is assumed, then <c>".asn"</c> and finally
 
66
          <c>".py"</c> (to be compatible with the old ASN.1 compiler).
 
67
          Of course <c>Asn1module</c> can be a full pathname (relative or
 
68
          absolute) including filename with (or without) extension.
 
69
                    <marker id="asn1set"></marker>
 
70
</p>
 
71
        <p>If one wishes to compile a set of Asn1 modules into one
 
72
          Erlang file with encode/decode functions one has to list all
 
73
          involved files in a configuration file. This configuration
 
74
          file must have a double extension ".set.asn", (".asn" can
 
75
          alternatively be ".asn1" or ".py"). The input files' names
 
76
          must be listed, within qoutation marks (""), one at each row
 
77
          in the file. If the input files are <c>File1.asn</c>,
 
78
          <c>File2.asn</c> and <c>File3.asn</c> the configuration file
 
79
          shall look like:</p>
 
80
        <pre>
 
81
File1.asn
 
82
File2.asn
 
83
File3.asn        </pre>
 
84
        <p>The output files will in this case get their names from the
 
85
          configuration file. If the configuration file has the name
 
86
          <c>SetOfFiles.set.asn</c> the name of the output files will be
 
87
          <c>SetOfFiles.hrl, SetOfFiles.hrl and SetOfFiles.asn1db</c>.</p>
 
88
        <p>Sometimes in a system of ASN.1 modules there are different
 
89
          default tag modes, e.g. AUTOMATIC, IMPLICIT or EXPLICIT. The
 
90
          multi file compilation resolves the default tagging as if
 
91
          the modules were compiled separetely.</p>
 
92
        <p>Another unwanted effect that may occure in multi file compilation
 
93
          is name collisions. The compiler solves this problem in two
 
94
          ways: If the definitions are identical then the output module
 
95
          keeps only one definition with the original name. But if
 
96
          definitions only have same name and differs in the definition, 
 
97
          then they will be renamed. The new names will be the definition
 
98
          name and the original module name concatenated.</p>
 
99
        <p>If any name collision have occured the compiler reports a 
 
100
          "NOTICE: ..." message that tells if a definition was renamed,
 
101
          and the new name that must be used to encode/decode data.</p>
 
102
        <p><c>Options</c> is a list with options specific for the asn1
 
103
          compiler and options that are applied to the Erlang compiler.
 
104
          The latter are those that not is recognized as asn1 specific.
 
105
          Available options are:</p>
 
106
        <taglist>
 
107
          <tag><c>ber | ber_bin | per | per_bin | uper_bin</c></tag>
 
108
          <item>
 
109
            <p>The encoding rule to be used. EncodingRule is BER or
 
110
            PER with the variants <c>aligned</c> or
 
111
            <c>unaligned</c>. If this option is omitted <c>ber</c> is
 
112
            the default. The <c>per</c> option means the aligned
 
113
            variant. To use the unaligned variant the <c>uper_bin</c>
 
114
            option has to be used.</p>
 
115
            <p>The generated Erlang module always gets the same name
 
116
            as the ASN.1 module and as a consequence of this only one
 
117
            encoding rule per ASN.1 module can be used at runtime.</p>
 
118
            <p>The <c>ber_bin</c> and <c>per_bin</c> options are
 
119
            equivalent with the <c>ber</c> and <c>per</c> options with
 
120
            the difference that the generated encoding/decoding
 
121
            functions take advantage of the bit syntax, which in most
 
122
            cases increases the performance considerably. The result
 
123
            from encoding is a binary or a list (mayby nested) with
 
124
            Erlang terms, including binaries.</p>
 
125
          </item>
 
126
          <tag><c>der</c></tag>
 
127
          <item>
 
128
            <p>By this option the Distinguished Encoding Rule (DER) is chosed.
 
129
              DER is regarded as a specialized variant of the BER encoding 
 
130
              rule, therefore the <c>der</c> option only makes sense when
 
131
              the <c>ber</c> or <c>ber_bin</c> option is used. This option
 
132
              sometimes adds sorting and value checks when encoding, which
 
133
              implies a slower encoding. The decoding rutines are the same
 
134
              as for <c>ber</c>.</p>
 
135
          </item>
 
136
          <tag><c>compact_bit_string</c></tag>
 
137
          <item>
 
138
            <p>Makes it possible to use a compact notation for values
 
139
              of the BIT STRING type in Erlang. The notation: </p>
 
140
            <pre>
 
141
BitString = {Unused,Binary},
 
142
Unused = integer(),
 
143
Binary = binary()            </pre>
 
144
            <p><c>Unused</c> must be a number in the range 0 to 7. It
 
145
              tells how many bits in the least significant byte in
 
146
              <c>Binary</c> that is unused. For details see <seealso marker="asn1_ug#BIT STRING">BIT STRING type section in users guide</seealso>.</p>
 
147
          </item>
 
148
          <tag><c>{i,IncludeDir}</c></tag>
 
149
          <item>
 
150
            <p>Adds <c>IncludeDir</c> to the search-path for
 
151
              <c>.asn1db</c> and asn1 source files. The compiler tries
 
152
              to open a <c>.asn1db</c> file when a module imports
 
153
              definitions from another ASN.1 module. If no
 
154
              <c>.asn1db</c> file is found the asn1 source file is
 
155
              parsed.  Several <c>{i,IncludeDir}</c> can be given.
 
156
              </p>
 
157
          </item>
 
158
          <tag><c>noobj</c></tag>
 
159
          <item>
 
160
            <p>Do not compile (i.e do not produce object code) the generated 
 
161
              <c>.erl</c> file. If this option is omitted the generated Erlang module
 
162
              will be compiled.</p>
 
163
          </item>
 
164
          <tag><c>{outdir,Dir}</c></tag>
 
165
          <item>
 
166
            <p>Specifies the directory <c>Dir</c> where all generated files 
 
167
              shall be placed. If omitted the files are placed in the 
 
168
              current directory.</p>
 
169
          </item>
 
170
          <tag><c>optimize</c></tag>
 
171
          <item>
 
172
            <p>This option is only valid together with one of the
 
173
              <c>per_bin</c> 
 
174
              or <c>ber_bin</c> option. It gives time optimized code 
 
175
              generated and it uses another runtime module and 
 
176
              in the <c>per_bin</c> case a linked-in driver. The result 
 
177
              in the <c>per_bin</c> case from an encode when compiled
 
178
              with this option will be a binary.</p>
 
179
          </item>
 
180
          <tag><c>driver</c></tag>
 
181
          <item>
 
182
            <p>Option valid together with <c>ber_bin</c> and <c>optimize</c>
 
183
              options. It enables the use of a linked-in driver that gives
 
184
              considerable faster decode. In <c>ber_bin</c> the driver is
 
185
              enabled only by explicit use of the option <c>driver</c>.</p>
 
186
          </item>
 
187
          <tag><c>asn1config</c></tag>
 
188
          <item>
 
189
            <p>When one of the specialized decodes, exclusive or
 
190
              selective decode, is wanted one has to give instructions in
 
191
              a configuration file. The option <c>asn1config</c> enables
 
192
              specialized decodes and takes the configuration file, which
 
193
              has the same name as the ASN.1 spec but with extension
 
194
              <c>.asn1config</c>, in concern.
 
195
              </p>
 
196
            <p>The instructions for exclusive decode must follow the
 
197
              <seealso marker="asn1_spec#Exclusive Instruction">instruction and grammar in the User's Guide</seealso>.
 
198
              </p>
 
199
            <p>You can also find the instructions for selective decode
 
200
              in the
 
201
              <seealso marker="asn1_spec#Selective Instruction">User's Guide</seealso>.
 
202
              </p>
 
203
          </item>
 
204
          <tag><c>undec_rest</c></tag>
 
205
          <item>
 
206
            <p>A buffer that holds a message, beeing decoded may
 
207
              also have some following bytes. Now it is possible to get
 
208
              those following bytes returned together with the decoded
 
209
              value. If an asn1 spec is compiled with this option a tuple
 
210
              <c>{ok,Value,Rest}</c> is returned. <c>Rest</c> may be a
 
211
              list or a binary. Earlier versions of the compiler ignored
 
212
              those following bytes.</p>
 
213
          </item>
 
214
          <tag><c>{inline,OutputName}</c></tag>
 
215
          <item>
 
216
            <p>Compiling with this option gives one output module
 
217
              containing all asn1 run-time functionality. The asn1 specs
 
218
              are provided in a target module Module.set.asn as described
 
219
              <seealso marker="#asn1set">above</seealso>. The name of the
 
220
              resulting module containing generated encode/decode functions
 
221
              and inlined run-time functions will be
 
222
              <c>OutputName.erl</c>. The merging/inlining of code is done
 
223
              by the <c>igor</c> module of <c>syntax_tools</c>. By default
 
224
              the functions generated from the first asn1 spec in the
 
225
              <c>.set.asn</c> are exported, unless a
 
226
              <c>{export,[atom()]}</c> or <c>{export_all,true}</c> option
 
227
              are provided. The list of atoms are names of choosen asn1
 
228
              specs from the <c>.set.asn</c> file.</p>
 
229
          </item>
 
230
          <tag><c>inline</c></tag>
 
231
          <item>
 
232
            <p>It is also possible to use the sole argument <c>inline</c>.
 
233
              It is as <c>{inline,OutputName}</c>, but the output file gets the
 
234
              default name of the source <c>.set.asn</c> file.</p>
 
235
          </item>
 
236
        </taglist>
 
237
        <p>Any additional option that is applied will be passed to
 
238
          the final step when the generated .erl file is compiled.
 
239
          </p>
 
240
        <p>The compiler generates the following files:</p>
 
241
        <list type="bulleted">
 
242
          <item>
 
243
            <p><c>Asn1module.hrl</c> (if any SET or SEQUENCE is defined)</p>
 
244
          </item>
 
245
          <item>
 
246
            <p><c>Asn1module.erl</c> the Erlang module with encode, decode and value functions.</p>
 
247
          </item>
 
248
          <item>
 
249
            <p><c>Asn1module.asn1db</c> intermediate format used by the compiler when modules IMPORTS
 
250
              definitions from each other.</p>
 
251
          </item>
 
252
        </list>
 
253
      </desc>
 
254
    </func>
 
255
    <func>
 
256
      <name>encode(Module,Type,Value)-> {ok,Bytes} | {error,Reason}</name>
 
257
      <fsummary>Encode an ASN.1 value.</fsummary>
 
258
      <type>
 
259
        <v>Module = Type = atom()</v>
 
260
        <v>Value = term()</v>
 
261
        <v>Bytes = [Int] when integer(Int), Int >= 0, Int =&lt; 255</v>
 
262
        <v>Reason = term()</v>
 
263
      </type>
 
264
      <desc>
 
265
        <p>Encodes <c>Value</c> of <c>Type</c> defined in the ASN.1 module 
 
266
          <c>Module</c>. Returns a list of bytes if successful. To get as fast execution as 
 
267
          possible the 
 
268
          encode function only performs rudimentary tests that the input 
 
269
          <c>Value</c>
 
270
          is a correct instance of <c>Type</c>. The length of strings is for example
 
271
          not always checked. Returns <c>{ok,Bytes}</c> if successful or 
 
272
          <c>{error,Reason}</c> if an error occured.
 
273
          </p>
 
274
      </desc>
 
275
    </func>
 
276
    <func>
 
277
      <name>decode(Module,Type,Bytes) -> {ok,Value}|{error,Reason}</name>
 
278
      <fsummary>Decode from Bytes into an ASN.1 value.</fsummary>
 
279
      <type>
 
280
        <v>Module = Type = atom()</v>
 
281
        <v>Value = Reason = term()</v>
 
282
        <v>Bytes = [Int] when integer(Int), Int >= 0, Int =&lt; 255</v>
 
283
      </type>
 
284
      <desc>
 
285
        <p>Decodes <c>Type</c> from <c>Module</c> from the list of bytes 
 
286
          <c>Bytes</c>. Returns <c>{ok,Value}</c> if successful.</p>
 
287
      </desc>
 
288
    </func>
 
289
    <func>
 
290
      <name>validate(Module,Type,Value) ->  ok | {error,Reason}</name>
 
291
      <fsummary>Validate an ASN.1 value.</fsummary>
 
292
      <type>
 
293
        <v>Module = Type = atom()</v>
 
294
        <v>Value = term()</v>
 
295
      </type>
 
296
      <desc>
 
297
        <p>Validates that <c>Value</c> conforms  to <c>Type</c> 
 
298
          from <c>Module</c>. <em>Not implemented in this version of the ASN.1 application.</em></p>
 
299
      </desc>
 
300
    </func>
 
301
    <func>
 
302
      <name>value(Module ,Type) -> {ok,Value} | {error,Reason}</name>
 
303
      <fsummary>Create an ASN.1 value for test purposes.</fsummary>
 
304
      <type>
 
305
        <v>Module = Type = atom()</v>
 
306
        <v>Value = term()</v>
 
307
        <v>Reason = term()</v>
 
308
      </type>
 
309
      <desc>
 
310
        <p>Returns an Erlang term which is an example of a valid Erlang 
 
311
          representation of a value of the ASN.1 type <c>Type</c>. The value
 
312
          is a random value and subsequent calls to this function will for most
 
313
          types return different values.</p>
 
314
      </desc>
 
315
    </func>
 
316
    <func>
 
317
      <name>test(Module) -> ok | {error,Reason}</name>
 
318
      <name>test(Module,Type) -> ok | {error,Reason}</name>
 
319
      <name>test(Module,Type,Value) -> ok | {error,Reason}</name>
 
320
      <fsummary>Perform a test of encode and decode for types in an  ASN.1 module.</fsummary>
 
321
      <desc>
 
322
        <p>Performs a test of encode and decode of all types in <c>Module</c>. 
 
323
          The generated functions are called by this function.
 
324
          This function is useful during test to secure that the generated
 
325
          encode and decode functions and the general runtime support work 
 
326
          as expected.          <br></br>
 
327
<c>test/1</c> iterates over all types in <c>Module</c>.          <br></br>
 
328
<c>test/2</c> tests type <c>Type</c> with a random value.          <br></br>
 
329
<c><![CDATA[test/3 tests type <c>Type]]></c> with <c>Value</c>.          <br></br>
 
330
 
 
331
          Schematically the following happens for each type in the module.</p>
 
332
        <p></p>
 
333
        <code type="none">
 
334
{ok,Value} = asn1ct:value(Module,Type),
 
335
{ok,Bytes} = asn1ct:encode(Module,Type,Value),
 
336
{ok,Value} = asn1:decode(Module,Type,Bytes).         </code>
 
337
      </desc>
 
338
    </func>
 
339
  </funcs>
 
340
  
 
341
</erlref>
 
342