blob: 28b061946ffda5cef5c8567c5c1726844d3f38c5 [file] [log] [blame]
Lev Walkin84291e02004-06-03 03:49:45 +00001#LyX 1.3 created this file. For more info see http://www.lyx.org/
2\lyxformat 221
3\textclass book
Lev Walkin26587ab2004-08-23 15:12:04 +00004\begin_preamble
Lev Walkin26587ab2004-08-23 15:12:04 +00005\usepackage{extramarks}
6\lhead{\firstxmark}
7\rfoot{\lastxmark}
Lev Walkind3630792004-09-30 22:26:19 +00008\usepackage{color}
9\definecolor{gray40}{gray}{.4}
10\definecolor{urlblue}{rgb}{0,0,.6}
11\usepackage[colorlinks=true,
12linkcolor={gray40},
13urlcolor={urlblue},
14pdfauthor={Lev Walkin},
Lev Walkindee61782005-02-02 09:53:46 +000015pdftitle={Using the Open Source ASN.1 Compiler},
Lev Walkind3630792004-09-30 22:26:19 +000016pdfkeywords={ASN.1,asn1c,compiler}
17]{hyperref}
18%\fancyhf{}
19%\fancyhead[LE,RO]{\thepage}
20%\fancyhead[LO]{\rightmark}
21%\fancyhead[RE]{\leftmark}
22%\fancyfoot[R]{\lastxmark}
Lev Walkin26587ab2004-08-23 15:12:04 +000023\end_preamble
Lev Walkin84291e02004-06-03 03:49:45 +000024\language english
25\inputencoding latin1
Lev Walkin26587ab2004-08-23 15:12:04 +000026\fontscheme times
Lev Walkin84291e02004-06-03 03:49:45 +000027\graphics default
28\paperfontsize default
29\spacing single
30\papersize Default
31\paperpackage a4
32\use_geometry 0
33\use_amsmath 0
34\use_natbib 0
35\use_numerical_citations 0
36\paperorientation portrait
Lev Walkind3630792004-09-30 22:26:19 +000037\secnumdepth 2
38\tocdepth 2
Lev Walkin84291e02004-06-03 03:49:45 +000039\paragraph_separation indent
40\defskip medskip
41\quotes_language swedish
42\quotes_times 2
43\papercolumns 1
Lev Walkin26587ab2004-08-23 15:12:04 +000044\papersides 2
45\paperpagestyle fancy
Lev Walkin84291e02004-06-03 03:49:45 +000046
47\layout Title
48
Lev Walkindee61782005-02-02 09:53:46 +000049Using the Open Source ASN.1 Compiler
Lev Walkin84291e02004-06-03 03:49:45 +000050\layout Author
51
52Lev Walkin <
Lev Walkind3630792004-09-30 22:26:19 +000053\begin_inset ERT
54status Collapsed
Lev Walkin84291e02004-06-03 03:49:45 +000055
Lev Walkind3630792004-09-30 22:26:19 +000056\layout Standard
57
58\backslash
59href{mailto:vlm@lionet.info?Subject=asn1c}{vlm@lionet.info}
Lev Walkin84291e02004-06-03 03:49:45 +000060\end_inset
61
62>
63\layout Standard
64
65
Lev Walkin26587ab2004-08-23 15:12:04 +000066\begin_inset ERT
67status Open
68
69\layout Standard
70
71\backslash
Lev Walkin7f70fe52005-02-22 07:28:26 +000072lhead{This document describes
Lev Walkind3630792004-09-30 22:26:19 +000073\backslash
Lev Walkin2f80e472006-08-18 07:11:27 +000074href{http://lionet.info/asn1c}{asn1c-0.9.21}}
Lev Walkind3630792004-09-30 22:26:19 +000075\layout Standard
76
77\backslash
78rhead{$Revision$}
Lev Walkin26587ab2004-08-23 15:12:04 +000079\end_inset
80
81
82\layout Standard
83
84
Lev Walkin84291e02004-06-03 03:49:45 +000085\begin_inset LatexCommand \tableofcontents{}
86
87\end_inset
88
89
Lev Walkin26587ab2004-08-23 15:12:04 +000090\layout Standard
91
92
93\begin_inset ERT
Lev Walkind3630792004-09-30 22:26:19 +000094status Open
Lev Walkin26587ab2004-08-23 15:12:04 +000095
96\layout Standard
97
98\backslash
99pagestyle{headings}
100\end_inset
101
102
Lev Walkin4a83dd52004-08-07 05:00:07 +0000103\layout Part
104
Lev Walkin09889622005-02-21 14:16:10 +0000105Using the ASN.1 Compiler
Lev Walkin84291e02004-06-03 03:49:45 +0000106\layout Chapter
107
Lev Walkin09889622005-02-21 14:16:10 +0000108Introduction to the ASN.1 Compiler
Lev Walkin84291e02004-06-03 03:49:45 +0000109\layout Standard
110
Lev Walkin09889622005-02-21 14:16:10 +0000111The purpose of the ASN.1 compiler, of which this document is part, is to
Lev Walkin7f70fe52005-02-22 07:28:26 +0000112 convert the specifications in ASN.1 notation into some other language.
Lev Walkin09889622005-02-21 14:16:10 +0000113 At this moment, only C and C++ target languages are supported, the latter
Lev Walkin7f70fe52005-02-22 07:28:26 +0000114 is in upward compatibility mode.
Lev Walkin84291e02004-06-03 03:49:45 +0000115\layout Standard
116
Lev Walkin09889622005-02-21 14:16:10 +0000117The compiler reads the specification and emits a series of target language
118 structures (C's structs, unions, enums) describing the corresponding ASN.1
119 types.
Lev Walkin7f70fe52005-02-22 07:28:26 +0000120 The compiler also creates the code which allows automatic serialization
121 and deserialization of these structures using several standardized encoding
122 rules (BER, DER, XER).
Lev Walkin84291e02004-06-03 03:49:45 +0000123\layout Standard
124
Lev Walkin09889622005-02-21 14:16:10 +0000125For example, suppose the following ASN.1 module is given
126\begin_inset Foot
127collapsed true
Lev Walkin84291e02004-06-03 03:49:45 +0000128
Lev Walkin84291e02004-06-03 03:49:45 +0000129\layout Standard
130
Lev Walkin09889622005-02-21 14:16:10 +0000131Please look into Part
132\begin_inset LatexCommand \vref{par:ASN.1-Basics}
133
Lev Walkin84291e02004-06-03 03:49:45 +0000134\end_inset
135
Lev Walkin09889622005-02-21 14:16:10 +0000136 for a quick reference on how to understand the ASN.1 notation.
Lev Walkin84291e02004-06-03 03:49:45 +0000137\end_inset
138
Lev Walkin09889622005-02-21 14:16:10 +0000139:
Lev Walkin84291e02004-06-03 03:49:45 +0000140\layout LyX-Code
141
Lev Walkin09889622005-02-21 14:16:10 +0000142RectangleTest DEFINITIONS ::=
Lev Walkin84291e02004-06-03 03:49:45 +0000143\layout LyX-Code
144
145BEGIN
146\layout LyX-Code
147
148
149\layout LyX-Code
150
Lev Walkin84291e02004-06-03 03:49:45 +0000151Rectangle ::= SEQUENCE {
152\layout LyX-Code
153
154 height INTEGER, -- Height of the rectangle
155\layout LyX-Code
156
Lev Walkin26587ab2004-08-23 15:12:04 +0000157 width INTEGER -- Width of the rectangle
Lev Walkin84291e02004-06-03 03:49:45 +0000158\layout LyX-Code
159
160}
161\layout LyX-Code
162
163
164\layout LyX-Code
165
166END
167\layout Standard
168
Lev Walkin09889622005-02-21 14:16:10 +0000169The compiler would read this ASN.1 definition and produce the following C
170 type
Lev Walkin84291e02004-06-03 03:49:45 +0000171\begin_inset Foot
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000172collapsed false
Lev Walkin84291e02004-06-03 03:49:45 +0000173
174\layout Standard
175
176
177\emph on
Lev Walkin99301892004-09-14 12:48:17 +0000178-fnative-types
Lev Walkin84291e02004-06-03 03:49:45 +0000179\emph default
180 compiler option is used to produce basic C
181\emph on
182int
183\emph default
Lev Walkin26587ab2004-08-23 15:12:04 +0000184 types instead of infinite width INTEGER_t structures.
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000185 See Section
186\begin_inset LatexCommand \vref{sec:Command-line-options}
Lev Walkin26587ab2004-08-23 15:12:04 +0000187
188\end_inset
189
190.
Lev Walkin84291e02004-06-03 03:49:45 +0000191\end_inset
192
193:
194\layout LyX-Code
195
196typedef struct Rectangle_s {
197\layout LyX-Code
198
199 int height;
200\layout LyX-Code
201
202 int width;
203\layout LyX-Code
204
205} Rectangle_t;
206\layout Standard
207
Lev Walkin09889622005-02-21 14:16:10 +0000208It would also create the code for converting this structure into platform-indepe
209ndent wire representation (a serializer API) and the decoder of such wire
210 representation back into local, machine-specific type (a deserializer API).
211\layout Section
Lev Walkin84291e02004-06-03 03:49:45 +0000212
Lev Walkin09889622005-02-21 14:16:10 +0000213Quick start with asn1c
Lev Walkin84291e02004-06-03 03:49:45 +0000214\layout Standard
215
Lev Walkin26587ab2004-08-23 15:12:04 +0000216After building and installing the compiler, the
217\emph on
218asn1c
219\begin_inset Foot
220collapsed false
221
222\layout Standard
223
224The 1 symbol in asn
225\series bold
2261
227\series default
228c is a digit, not an
229\begin_inset Quotes sld
230\end_inset
231
232ell
233\begin_inset Quotes srd
234\end_inset
235
236 letter.
237\end_inset
238
239
240\emph default
Lev Walkin09889622005-02-21 14:16:10 +0000241 command may be used to compile the ASN.1 module
Lev Walkin84291e02004-06-03 03:49:45 +0000242\begin_inset Foot
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000243collapsed false
Lev Walkin84291e02004-06-03 03:49:45 +0000244
245\layout Standard
246
247This is probably
248\series bold
249not
250\series default
251 what you want to try out right now -- read through the rest of this chapter
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000252 and check the Section
253\begin_inset LatexCommand \vref{sec:Command-line-options}
Lev Walkin09889622005-02-21 14:16:10 +0000254
255\end_inset
256
Lev Walkin26587ab2004-08-23 15:12:04 +0000257 to find out about
258\series bold
259-P
260\series default
261 and
262\series bold
263-R
264\series default
265 options.
Lev Walkin84291e02004-06-03 03:49:45 +0000266\end_inset
267
268:
269\layout LyX-Code
270
271asn1c
272\emph on
Lev Walkin09889622005-02-21 14:16:10 +0000273<module.asn1>
Lev Walkin84291e02004-06-03 03:49:45 +0000274\layout Standard
275
Lev Walkin09889622005-02-21 14:16:10 +0000276If several ASN.1 modules contain interdependencies, all of the files must
Lev Walkin26587ab2004-08-23 15:12:04 +0000277 be specified altogether:
Lev Walkin84291e02004-06-03 03:49:45 +0000278\layout LyX-Code
279
280asn1c
281\emph on
Lev Walkin09889622005-02-21 14:16:10 +0000282<module1.asn1> <module2.asn1> ...
Lev Walkin84291e02004-06-03 03:49:45 +0000283\layout Standard
284
Lev Walkin26587ab2004-08-23 15:12:04 +0000285The compiler
286\series bold
287-E
288\series default
289 and
290\series bold
291-EF
292\series default
293 options are used for testing the parser and the semantic fixer, respectively.
294 These options will instruct the compiler to dump out the parsed (and fixed,
295 if
296\series bold
297-F
298\series default
299 is involved) ASN.1 specification as it was "understood" by the compiler.
300 It might be useful to check whether a particular syntactic construction
Lev Walkin84291e02004-06-03 03:49:45 +0000301 is properly supported by the compiler.
302\layout LyX-Code
303
Lev Walkin26587ab2004-08-23 15:12:04 +0000304asn1c
305\series bold
306-EF
307\series default
308
Lev Walkin84291e02004-06-03 03:49:45 +0000309\emph on
Lev Walkin09889622005-02-21 14:16:10 +0000310<module-to-test.asn1>
Lev Walkin84291e02004-06-03 03:49:45 +0000311\layout Standard
312
Lev Walkin26587ab2004-08-23 15:12:04 +0000313The
314\series bold
315-P
316\series default
317 option is used to dump the compiled output on the screen instead of creating
318 a bunch of .c and .h files on disk in the current directory.
319 You would probably want to start with
320\series bold
321-P
322\series default
323 option instead of creating a mess in your current directory.
324 Another option,
325\series bold
326-R
327\series default
328, asks compiler to only generate the files which need to be generated, and
329 supress linking in the numerous support files.
330\layout Standard
331
332Print the compiled output instead of creating multiple source files:
333\layout LyX-Code
334
335asn1c
336\series bold
337-P
338\series default
339
340\emph on
Lev Walkin09889622005-02-21 14:16:10 +0000341<module-to-compile-and-print.asn1>
Lev Walkin84291e02004-06-03 03:49:45 +0000342\layout Section
343
Lev Walkin09889622005-02-21 14:16:10 +0000344Recognizing compiler output
345\layout Standard
346
347After compiling, the following entities will be created in your current
348 directory:
349\layout Itemize
350
351A set of .c and .h files, generally a single pair for each type defined in
352 the ASN.1 specifications.
353 These files will be named similarly to the ASN.1 types (
354\emph on
355Rectangle.c
356\emph default
357 and
358\emph on
359Rectangle.h
360\emph default
361 for the RectangleTest ASN.1 module defined in the beginning of this document).
362\layout Itemize
363
364A set of helper .c and .h files which contain generic encoders, decoders and
365 other useful routines.
366 There will be quite a few of them, some of them even are not always necessary,
367 but the overall amount of code after compilation will be rather small anyway.
368\layout Itemize
369
370A
371\emph on
372Makefile.am.sample
373\emph default
374 file mentioning all the files created at the earlier steps.
375 This file is suitable for either automake suite or the plain `make` utility.
376\layout Standard
377
378It is your responsibility to create .c file with the
379\emph on
380 int main()
381\emph default
382 routine.
383\layout Standard
384
385In other words, after compiling the Rectangle module, you have the following
386 set of files: { Makefile.am.sample, Rectangle.c, Rectangle.h,
387\series bold
388\SpecialChar \ldots{}
389
390\series default
391 }, where
392\series bold
393
394\begin_inset Quotes sld
395\end_inset
396
397\SpecialChar \ldots{}
398
399\begin_inset Quotes srd
400\end_inset
401
402
403\series default
404 stands for the set of additional
405\begin_inset Quotes sld
406\end_inset
407
408helper
409\begin_inset Quotes srd
410\end_inset
411
412 files created by the compiler.
413 If you add a simple file with the
414\emph on
415int main()
416\emph default
417 routine, it would even be possible to compile everything with the single
418 instruction:
419\layout LyX-Code
420
421cc -I.
422 -o rectangle.exe *.c # It could be
423\emph on
424that
425\emph default
426 simple
427\layout Standard
428
429Refer to the Chapter
430\begin_inset LatexCommand \vref{cha:Step-by-step-examples}
431
432\end_inset
433
434 for a sample
435\emph on
436int main()
437\emph default
438 routine.
439\layout Section
440
Lev Walkin26587ab2004-08-23 15:12:04 +0000441
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000442\begin_inset LatexCommand \label{sec:Command-line-options}
Lev Walkin26587ab2004-08-23 15:12:04 +0000443
444\end_inset
445
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000446Command line options
Lev Walkin26587ab2004-08-23 15:12:04 +0000447\layout Standard
448
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000449The following table summarizes the asn1c command line options.
Lev Walkin26587ab2004-08-23 15:12:04 +0000450\layout Standard
451
452
453\begin_inset Tabular
Lev Walkin2f80e472006-08-18 07:11:27 +0000454<lyxtabular version="3" rows="29" columns="2">
Lev Walkind3630792004-09-30 22:26:19 +0000455<features islongtable="true">
Lev Walkin26587ab2004-08-23 15:12:04 +0000456<column alignment="left" valignment="top" leftline="true" width="0">
457<column alignment="block" valignment="top" leftline="true" rightline="true" width="3in">
458<row topline="true" bottomline="true">
459<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
460\begin_inset Text
461
462\layout Standard
463
464
465\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000466\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000467Overall Options
468\end_inset
469</cell>
470<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
471\begin_inset Text
472
473\layout Standard
474
475
476\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000477\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000478Description
479\end_inset
480</cell>
481</row>
482<row topline="true">
483<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
484\begin_inset Text
485
486\layout Standard
487
Lev Walkinf47d0682005-03-05 01:07:04 +0000488
489\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000490-E
491\end_inset
492</cell>
493<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
494\begin_inset Text
495
496\layout Standard
497
498
499\size small
500Stop after the parsing stage and print the reconstructed ASN.1 specification
501 code to the standard output.
502\end_inset
503</cell>
504</row>
505<row topline="true">
506<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
507\begin_inset Text
508
509\layout Standard
510
Lev Walkinf47d0682005-03-05 01:07:04 +0000511
512\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000513-F
514\end_inset
515</cell>
516<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
517\begin_inset Text
518
519\layout Standard
520
521
522\size small
523Used together with -E, instructs the compiler to stop after the ASN.1 syntax
524 tree fixing stage and dump the reconstructed ASN.1 specification to the
525 standard output.
526\end_inset
527</cell>
528</row>
529<row topline="true">
530<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
531\begin_inset Text
532
533\layout Standard
534
Lev Walkinf47d0682005-03-05 01:07:04 +0000535
536\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000537-P
538\end_inset
539</cell>
540<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
541\begin_inset Text
542
543\layout Standard
544
545
546\size small
547Dump the compiled output to the standard output instead of cre- ating the
548 target language files on disk.
549\end_inset
550</cell>
551</row>
552<row topline="true">
553<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
554\begin_inset Text
555
556\layout Standard
557
Lev Walkinf47d0682005-03-05 01:07:04 +0000558
559\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000560-R
561\end_inset
562</cell>
563<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
564\begin_inset Text
565
566\layout Standard
567
568
569\size small
570Restrict the compiler to generate only the ASN.1 tables, omit- ting the usual
571 support code.
572\end_inset
573</cell>
574</row>
Lev Walkinf7484512004-10-13 09:13:56 +0000575<row topline="true">
Lev Walkin26587ab2004-08-23 15:12:04 +0000576<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
577\begin_inset Text
578
579\layout Standard
580
Lev Walkinf47d0682005-03-05 01:07:04 +0000581
582\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000583-S
584\emph on
585<directory>
586\end_inset
587</cell>
588<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
589\begin_inset Text
590
591\layout Standard
592
593
594\size small
595Use the specified directory with ASN.1 skeleton files.
596\end_inset
597</cell>
598</row>
Lev Walkinf7484512004-10-13 09:13:56 +0000599<row topline="true" bottomline="true">
600<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
601\begin_inset Text
602
603\layout Standard
604
Lev Walkinf47d0682005-03-05 01:07:04 +0000605
606\size small
Lev Walkinf7484512004-10-13 09:13:56 +0000607-X
608\end_inset
609</cell>
610<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
611\begin_inset Text
612
613\layout Standard
614
Lev Walkinf47d0682005-03-05 01:07:04 +0000615
616\size small
Lev Walkinf7484512004-10-13 09:13:56 +0000617Generate the XML DTD for the specified ASN.1 modules.
618\end_inset
619</cell>
620</row>
Lev Walkin26587ab2004-08-23 15:12:04 +0000621<row topline="true">
622<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
623\begin_inset Text
624
625\layout Standard
626
627
628\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000629\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000630Warning Options
631\end_inset
632</cell>
633<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634\begin_inset Text
635
636\layout Standard
637
638
639\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000640\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000641Description
642\end_inset
643</cell>
644</row>
645<row topline="true">
646<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
647\begin_inset Text
648
649\layout Standard
650
Lev Walkinf47d0682005-03-05 01:07:04 +0000651
652\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000653-Werror
654\end_inset
655</cell>
656<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
657\begin_inset Text
658
659\layout Standard
660
661
662\size small
663Treat warnings as errors; abort if any warning is produced.
664\end_inset
665</cell>
666</row>
667<row topline="true">
668<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
669\begin_inset Text
670
671\layout Standard
672
Lev Walkinf47d0682005-03-05 01:07:04 +0000673
674\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000675-Wdebug-lexer
676\end_inset
677</cell>
678<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
679\begin_inset Text
680
681\layout Standard
682
683
684\size small
685Enable lexer debugging during the ASN.1 parsing stage.
686\end_inset
687</cell>
688</row>
689<row topline="true">
690<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
691\begin_inset Text
692
693\layout Standard
694
Lev Walkinf47d0682005-03-05 01:07:04 +0000695
696\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000697-Wdebug-fixer
698\end_inset
699</cell>
700<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
701\begin_inset Text
702
703\layout Standard
704
705
706\size small
707 Enable ASN.1 syntax tree fixer debugging during the fixing stage.
708\end_inset
709</cell>
710</row>
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000711<row topline="true" bottomline="true" newpage="true">
Lev Walkin26587ab2004-08-23 15:12:04 +0000712<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
713\begin_inset Text
714
715\layout Standard
716
Lev Walkinf47d0682005-03-05 01:07:04 +0000717
718\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000719-Wdebug-compiler
720\end_inset
721</cell>
722<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
723\begin_inset Text
724
725\layout Standard
726
727
728\size small
729Enable debugging during the actual compile time.
730\end_inset
731</cell>
732</row>
733<row topline="true">
734<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
735\begin_inset Text
736
737\layout Standard
738
739
740\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000741\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000742Language Options
743\end_inset
744</cell>
745<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
746\begin_inset Text
747
748\layout Standard
749
750
751\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +0000752\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000753Description
754\end_inset
755</cell>
756</row>
757<row topline="true">
758<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
759\begin_inset Text
760
761\layout Standard
762
Lev Walkinf47d0682005-03-05 01:07:04 +0000763
764\size small
Lev Walkindd32b592004-09-06 08:07:29 +0000765-fall-defs-global
766\end_inset
767</cell>
768<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
769\begin_inset Text
770
771\layout Standard
772
Lev Walkinf47d0682005-03-05 01:07:04 +0000773
774\size small
Lev Walkin1f756282004-09-29 13:29:17 +0000775Normally the compiler hides the definitions (asn_DEF_xxx) of the inner structure
776 elements (members of SEQUENCE, SET and other types).
Lev Walkindd32b592004-09-06 08:07:29 +0000777 This option makes all such definitions global.
Lev Walkin1f756282004-09-29 13:29:17 +0000778 Enabling this option may pollute the namespace by making lots of asn_DEF_xxx
Lev Walkindd32b592004-09-06 08:07:29 +0000779 structures globally visible, but will allow you to manipulate (encode and
780 decode) the individual members of any complex ASN.1 structure.
781\end_inset
782</cell>
783</row>
784<row topline="true">
785<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
786\begin_inset Text
787
788\layout Standard
789
Lev Walkinf47d0682005-03-05 01:07:04 +0000790
791\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000792-fbless-SIZE
793\end_inset
794</cell>
795<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
796\begin_inset Text
797
798\layout Standard
799
800
801\size small
802Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which
803 this constraint is normally prohibited by the standard.
804 This is a violation of an ASN.1 standard and compiler may fail to produce
805 the meaningful code.
806\end_inset
807</cell>
808</row>
809<row topline="true">
810<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
811\begin_inset Text
812
813\layout Standard
814
Lev Walkinf47d0682005-03-05 01:07:04 +0000815
816\size small
817-fcompound-names
818\end_inset
819</cell>
820<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
821\begin_inset Text
822
823\layout Standard
824
825
826\size small
827Use complex names for C structures.
828 Using complex names prevents name clashes in case the module reuses the
829 same identifiers in multiple contexts.
830\end_inset
831</cell>
832</row>
833<row topline="true">
834<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
835\begin_inset Text
836
837\layout Standard
838
Lev Walkina895afb2005-10-06 10:09:34 +0000839
840\size small
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000841-findirect-choice
842\end_inset
843</cell>
844<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
845\begin_inset Text
846
847\layout Standard
848
Lev Walkina895afb2005-10-06 10:09:34 +0000849
850\size small
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000851When generating code for a CHOICE type, compile the CHOICE members as indirect
852 pointers instead of declaring them inline.
853 Consider using this option together with
854\series bold
855-fno-include-deps
856\series default
857 to prevent circular references.
858
859\end_inset
860</cell>
861</row>
862<row topline="true">
863<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
864\begin_inset Text
865
866\layout Standard
867
Lev Walkina895afb2005-10-06 10:09:34 +0000868
869\size small
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000870-fknown-extern-type=
871\emph on
872<name>
873\end_inset
874</cell>
875<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
876\begin_inset Text
877
878\layout Standard
879
Lev Walkina895afb2005-10-06 10:09:34 +0000880
881\size small
Lev Walkin72a0f5a2005-07-24 08:28:39 +0000882Pretend the specified type is known.
883 The compiler will assume the target language source files for the given
884 type have been provided manually.
885
886\end_inset
887</cell>
888</row>
889<row topline="true">
890<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
891\begin_inset Text
892
893\layout Standard
894
Lev Walkinf47d0682005-03-05 01:07:04 +0000895
896\size small
Lev Walkin99301892004-09-14 12:48:17 +0000897-fnative-types
Lev Walkin26587ab2004-08-23 15:12:04 +0000898\end_inset
899</cell>
900<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
901\begin_inset Text
902
903\layout Standard
904
905
906\size small
Lev Walkin99301892004-09-14 12:48:17 +0000907Use the native machine's data types (int, double) whenever possible, instead
Lev Walkind3630792004-09-30 22:26:19 +0000908 of the compound INTEGER_t, ENUMERATED_t and REAL_t types.
Lev Walkin26587ab2004-08-23 15:12:04 +0000909
910\end_inset
911</cell>
912</row>
913<row topline="true">
914<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
915\begin_inset Text
916
917\layout Standard
918
Lev Walkinf47d0682005-03-05 01:07:04 +0000919
920\size small
Lev Walkin4e940a02004-09-26 13:13:13 +0000921-fno-constraints
922\end_inset
923</cell>
924<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
925\begin_inset Text
926
927\layout Standard
928
Lev Walkinf47d0682005-03-05 01:07:04 +0000929
930\size small
Lev Walkin4e940a02004-09-26 13:13:13 +0000931Do not generate ASN.1 subtype constraint checking code.
Lev Walkinf47d0682005-03-05 01:07:04 +0000932 This may produce a shorter executable.
Lev Walkin4e940a02004-09-26 13:13:13 +0000933\end_inset
934</cell>
935</row>
936<row topline="true">
937<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
938\begin_inset Text
939
940\layout Standard
941
Lev Walkinf47d0682005-03-05 01:07:04 +0000942
943\size small
944-fno-include-deps
945\end_inset
946</cell>
947<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
948\begin_inset Text
949
950\layout Standard
951
952
953\size small
954Do not generate courtesy #include lines for non-critical dependencies.
955\end_inset
956</cell>
957</row>
958<row topline="true">
959<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
960\begin_inset Text
961
962\layout Standard
963
964
965\size small
Lev Walkin26587ab2004-08-23 15:12:04 +0000966-funnamed-unions
967\end_inset
968</cell>
969<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
970\begin_inset Text
971
972\layout Standard
973
974
975\size small
976Enable unnamed unions in the definitions of target language's structures.
977\end_inset
978</cell>
979</row>
Lev Walkinb1fa18e2005-11-21 09:18:18 +0000980<row topline="true" bottomline="true">
Lev Walkina895afb2005-10-06 10:09:34 +0000981<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
982\begin_inset Text
983
984\layout Standard
985
986
987\size small
988-fskeletons-copy
989\end_inset
990</cell>
991<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
992\begin_inset Text
993
994\layout Standard
995
996
997\size small
998Copy support files rather than symlink them.
999\end_inset
1000</cell>
1001</row>
Lev Walkin72a0f5a2005-07-24 08:28:39 +00001002<row topline="true">
Lev Walkin26587ab2004-08-23 15:12:04 +00001003<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1004\begin_inset Text
1005
1006\layout Standard
1007
1008
1009\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +00001010\size small
Lev Walkin2f80e472006-08-18 07:11:27 +00001011Codecs Generation Options
1012\end_inset
1013</cell>
1014<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1015\begin_inset Text
1016
1017\layout Standard
1018
1019
1020\series bold
1021\size small
1022Description
1023\end_inset
1024</cell>
1025</row>
1026<row topline="true">
1027<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1028\begin_inset Text
1029
1030\layout Standard
1031
1032
1033\size small
1034-gen-PER
1035\end_inset
1036</cell>
1037<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1038\begin_inset Text
1039
1040\layout Standard
1041
1042
1043\size small
1044Generate Packed Encoding Rules (PER) support code.
1045\end_inset
1046</cell>
1047</row>
1048<row topline="true" bottomline="true">
1049<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1050\begin_inset Text
1051
1052\layout Standard
1053
1054
1055\size small
1056-pdu=
1057\emph on
1058auto
1059\end_inset
1060</cell>
1061<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1062\begin_inset Text
1063
1064\layout Standard
1065
1066
1067\size small
1068Generate PDU tables by discovering Protocol Data Units automatically.
1069\end_inset
1070</cell>
1071</row>
1072<row topline="true">
1073<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1074\begin_inset Text
1075
1076\layout Standard
1077
1078
1079\series bold
1080\size small
Lev Walkin26587ab2004-08-23 15:12:04 +00001081Output Options
1082\end_inset
1083</cell>
1084<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1085\begin_inset Text
1086
1087\layout Standard
1088
1089
1090\series bold
Lev Walkinf47d0682005-03-05 01:07:04 +00001091\size small
Lev Walkin26587ab2004-08-23 15:12:04 +00001092Description
1093\end_inset
1094</cell>
1095</row>
1096<row topline="true">
1097<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1098\begin_inset Text
1099
1100\layout Standard
1101
Lev Walkinf47d0682005-03-05 01:07:04 +00001102
1103\size small
Lev Walkin26587ab2004-08-23 15:12:04 +00001104-print-constraints
1105\end_inset
1106</cell>
1107<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1108\begin_inset Text
1109
1110\layout Standard
1111
1112
1113\size small
1114When -EF are also specified, this option forces the compiler to explain
1115 its internal understanding of subtype constraints.
1116\end_inset
1117</cell>
1118</row>
1119<row topline="true" bottomline="true">
1120<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1121\begin_inset Text
1122
1123\layout Standard
1124
Lev Walkinf47d0682005-03-05 01:07:04 +00001125
1126\size small
Lev Walkin26587ab2004-08-23 15:12:04 +00001127-print-lines
1128\end_inset
1129</cell>
1130<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1131\begin_inset Text
1132
1133\layout Standard
1134
1135
1136\size small
1137Generate "-- #line" comments in -E output.
1138\end_inset
1139</cell>
1140</row>
1141</lyxtabular>
1142
1143\end_inset
1144
1145
Lev Walkin09889622005-02-21 14:16:10 +00001146\layout Chapter
1147
1148Using the ASN.1 Compiler
Lev Walkin26587ab2004-08-23 15:12:04 +00001149\layout Section
Lev Walkin84291e02004-06-03 03:49:45 +00001150
Lev Walkin09889622005-02-21 14:16:10 +00001151Invoking the ASN.1 helper code
Lev Walkind3630792004-09-30 22:26:19 +00001152\begin_inset OptArg
1153collapsed true
1154
1155\layout Standard
1156
1157Invoking the helper code
1158\end_inset
1159
1160
Lev Walkin84291e02004-06-03 03:49:45 +00001161\layout Standard
1162
Lev Walkin7f70fe52005-02-22 07:28:26 +00001163First of all, you should include one or more header files into your application.
1164 Typically, it is enough to include the header file of the main PDU type.
1165 For our Rectangle module, including the Rectangle.h file is sufficient:
Lev Walkin84291e02004-06-03 03:49:45 +00001166\layout LyX-Code
1167
1168#include <Rectangle.h>
1169\layout Standard
1170
1171The header files defines the C structure corresponding to the ASN.1 definition
1172 of a rectangle and the declaration of the ASN.1 type descriptor, which is
1173 used as an argument to most of the functions provided by the ASN.1 module.
1174 For example, here is the code which frees the Rectangle_t structure:
1175\layout LyX-Code
1176
Lev Walkin26587ab2004-08-23 15:12:04 +00001177Rectangle_t *rect = ...;
1178\layout LyX-Code
1179
1180
Lev Walkin84291e02004-06-03 03:49:45 +00001181\layout LyX-Code
1182
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00001183asn_DEF_Rectangle.free_struct(&asn_DEF_Rectangle,
Lev Walkin84291e02004-06-03 03:49:45 +00001184\layout LyX-Code
1185
1186 rect, 0);
1187\layout Standard
1188
1189This code defines a
1190\emph on
1191rect
1192\emph default
1193 pointer which points to the Rectangle_t structure which needs to be freed.
Lev Walkin7f70fe52005-02-22 07:28:26 +00001194 The second line invokes the generic
1195\emph on
1196free_struct()
1197\emph default
1198 routine created specifically for this Rectangle_t structure.
Lev Walkin84291e02004-06-03 03:49:45 +00001199 The
1200\emph on
Lev Walkin1f756282004-09-29 13:29:17 +00001201asn_DEF_Rectangle
Lev Walkin84291e02004-06-03 03:49:45 +00001202\emph default
Lev Walkin7f70fe52005-02-22 07:28:26 +00001203 is the type descriptor, which holds a collection of routines to deal with
1204 the Rectangle_t structure.
Lev Walkin84291e02004-06-03 03:49:45 +00001205\layout Standard
1206
Lev Walkin7f70fe52005-02-22 07:28:26 +00001207The following member functions of the asn_DEF_Rectangle type descriptor
1208 are of interest:
Lev Walkin84291e02004-06-03 03:49:45 +00001209\layout Description
1210
Lev Walkin84291e02004-06-03 03:49:45 +00001211ber_decoder This is the generic
1212\emph on
1213restartable
1214\begin_inset Foot
1215collapsed false
1216
1217\layout Standard
1218
1219Restartable means that if the decoder encounters the end of the buffer,
1220 it will fail, but may later be invoked again with the rest of the buffer
1221 to continue decoding.
1222\end_inset
1223
1224
1225\emph default
1226BER decoder (Basic Encoding Rules).
1227 This decoder would create and/or fill the target structure for you.
Lev Walkin2f80e472006-08-18 07:11:27 +00001228 See Section
Lev Walkin09889622005-02-21 14:16:10 +00001229\begin_inset LatexCommand \vref{sub:Decoding-BER}
Lev Walkin84291e02004-06-03 03:49:45 +00001230
1231\end_inset
1232
1233.
1234\layout Description
1235
1236der_encoder This is the generic DER encoder (Distinguished Encoding Rules).
Lev Walkin35d446b2004-09-24 20:56:07 +00001237 This encoder will take the target structure and encode it into a series
Lev Walkin84291e02004-06-03 03:49:45 +00001238 of bytes.
Lev Walkin2f80e472006-08-18 07:11:27 +00001239 See Section
Lev Walkin09889622005-02-21 14:16:10 +00001240\begin_inset LatexCommand \vref{sub:Encoding-DER}
Lev Walkin84291e02004-06-03 03:49:45 +00001241
1242\end_inset
1243
1244.
Lev Walkin2f80e472006-08-18 07:11:27 +00001245 NOTE: DER encoding is a subset of BER.
1246 Any BER decoder should be able to handle DER input.
1247\layout Description
1248
1249xer_decoder This is the generic XER decoder.
1250 It takes both BASIC-XER or CANONICAL-XER encodings and deserializes the
1251 data into a local, machine-dependent representation.
1252 See Section
1253\begin_inset LatexCommand \vref{sub:Decoding-XER}
1254
1255\end_inset
1256
1257.
Lev Walkin84291e02004-06-03 03:49:45 +00001258\layout Description
1259
Lev Walkin09889622005-02-21 14:16:10 +00001260xer_encoder This is the XER encoder (XML Encoding Rules).
Lev Walkin35d446b2004-09-24 20:56:07 +00001261 This encoder will take the target structure and represent it as an XML
Lev Walkin09889622005-02-21 14:16:10 +00001262 (text) document using either BASIC-XER or CANONICAL-XER encoding rules.
Lev Walkin2f80e472006-08-18 07:11:27 +00001263 See Section
Lev Walkin09889622005-02-21 14:16:10 +00001264\begin_inset LatexCommand \vref{sub:Encoding-XER}
1265
1266\end_inset
1267
1268.
1269\layout Description
1270
Lev Walkin2f80e472006-08-18 07:11:27 +00001271uper_decoder This is the Unaligned PER decoder.
1272\layout Description
Lev Walkin35d446b2004-09-24 20:56:07 +00001273
Lev Walkin2f80e472006-08-18 07:11:27 +00001274uper_encoder This is the Unaligned Basic PER encoder.
1275 This encoder will take the target structure and encode it into a series
1276 of bytes.
Lev Walkin35d446b2004-09-24 20:56:07 +00001277\layout Description
1278
1279check_constraints Check that the contents of the target structure are semantical
1280ly valid and constrained to appropriate implicit or explicit subtype constraints.
Lev Walkin2f80e472006-08-18 07:11:27 +00001281 See Section
Lev Walkin35d446b2004-09-24 20:56:07 +00001282\begin_inset LatexCommand \vref{sub:Validating-the-target}
1283
1284\end_inset
1285
1286.
1287\layout Description
1288
Lev Walkin84291e02004-06-03 03:49:45 +00001289print_struct This function convert the contents of the passed target structure
1290 into human readable form.
1291 This form is not formal and cannot be converted back into the structure,
1292 but it may turn out to be useful for debugging or quick-n-dirty printing.
Lev Walkin2f80e472006-08-18 07:11:27 +00001293 See Section
Lev Walkin09889622005-02-21 14:16:10 +00001294\begin_inset LatexCommand \vref{sub:Printing-the-target}
Lev Walkin84291e02004-06-03 03:49:45 +00001295
1296\end_inset
1297
1298.
1299\layout Description
1300
1301free_struct This is a generic disposal which frees the target structure.
Lev Walkin2f80e472006-08-18 07:11:27 +00001302 See Section
Lev Walkin09889622005-02-21 14:16:10 +00001303\begin_inset LatexCommand \vref{sub:Freeing-the-target}
Lev Walkin35d446b2004-09-24 20:56:07 +00001304
1305\end_inset
1306
1307.
1308\layout Standard
1309
Lev Walkin84291e02004-06-03 03:49:45 +00001310Each of the above function takes the type descriptor (
1311\emph on
Lev Walkin1f756282004-09-29 13:29:17 +00001312asn_DEF_\SpecialChar \ldots{}
Lev Walkin84291e02004-06-03 03:49:45 +00001313
1314\emph default
1315) and the target structure (
1316\emph on
1317rect
1318\emph default
1319, in the above example).
Lev Walkin09889622005-02-21 14:16:10 +00001320\layout Subsection
1321
1322
1323\begin_inset LatexCommand \label{sub:Decoding-BER}
1324
1325\end_inset
1326
1327Decoding BER
Lev Walkin84291e02004-06-03 03:49:45 +00001328\layout Standard
1329
Lev Walkin09889622005-02-21 14:16:10 +00001330The Basic Encoding Rules describe the most widely used (by the ASN.1 community)
Lev Walkin7f70fe52005-02-22 07:28:26 +00001331 way to encode and decode a given structure in a machine-independent way.
Lev Walkin09889622005-02-21 14:16:10 +00001332 Several other encoding rules (CER, DER) define a more restrictive versions
1333 of BER, so the generic BER parser is also capable of decoding the data
1334 encoded by CER and DER encoders.
1335 The opposite is not true.
1336\layout Standard
1337
Lev Walkin7f70fe52005-02-22 07:28:26 +00001338
1339\emph on
Lev Walkin09889622005-02-21 14:16:10 +00001340The ASN.1 compiler provides the generic BER decoder which is implicitly capable
1341 of decoding BER, CER and DER encoded data.
1342\layout Standard
1343
1344The decoder is restartable (stream-oriented), which means that in case the
1345 buffer has less data than it is expected, the decoder will process whatever
1346 there is available and ask for more data to be provided.
1347 Please note that the decoder may actually process less data than it was
1348 given in the buffer, which means that you must be able to make the next
1349 buffer contain the unprocessed part of the previous buffer.
1350\layout Standard
1351
1352Suppose, you have two buffers of encoded data: 100 bytes and 200 bytes.
1353\layout Itemize
1354
1355You may concatenate these buffers and feed the BER decoder with 300 bytes
1356 of data, or
1357\layout Itemize
1358
1359You may feed it the first buffer of 100 bytes of data, realize that the
1360 ber_decoder consumed only 95 bytes from it and later feed the decoder with
1361 205 bytes buffer which consists of 5 unprocessed bytes from the first buffer
Lev Walkin7f70fe52005-02-22 07:28:26 +00001362 and the additional 200 bytes from the second buffer.
Lev Walkin09889622005-02-21 14:16:10 +00001363\layout Standard
1364
Lev Walkin7f70fe52005-02-22 07:28:26 +00001365This is not as convenient as it could be (like, the BER encoder could consume
Lev Walkin09889622005-02-21 14:16:10 +00001366 the whole 100 bytes and keep these 5 bytes in some temporary storage),
Lev Walkin7f70fe52005-02-22 07:28:26 +00001367 but in case of existing stream based processing it might actually fit well
1368 into existing algorithm.
Lev Walkin09889622005-02-21 14:16:10 +00001369 Suggestions are welcome.
1370\layout Standard
1371
Lev Walkin7f70fe52005-02-22 07:28:26 +00001372Here is the simplest example of BER decoding.
Lev Walkin84291e02004-06-03 03:49:45 +00001373\layout LyX-Code
1374
1375Rectangle_t *
1376\layout LyX-Code
1377
Lev Walkin26587ab2004-08-23 15:12:04 +00001378simple_deserializer(const void *buffer, size_t buf_size) {
Lev Walkin84291e02004-06-03 03:49:45 +00001379\layout LyX-Code
1380
1381 Rectangle_t *rect = 0; /* Note this 0! */
1382\layout LyX-Code
1383
Lev Walkina646ccb2004-10-20 15:48:55 +00001384 asn_dec_rval_t rval;
Lev Walkin84291e02004-06-03 03:49:45 +00001385\layout LyX-Code
1386
1387
1388\layout LyX-Code
1389
Lev Walkin09889622005-02-21 14:16:10 +00001390 rval =
1391\series bold
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00001392asn_DEF_Rectangle.ber_decoder
Lev Walkin09889622005-02-21 14:16:10 +00001393\series default
1394(0,
Lev Walkin84291e02004-06-03 03:49:45 +00001395\layout LyX-Code
1396
Lev Walkin1f756282004-09-29 13:29:17 +00001397 &asn_DEF_Rectangle,
Lev Walkin84291e02004-06-03 03:49:45 +00001398\layout LyX-Code
1399
1400 (void **)&rect,
1401\layout LyX-Code
1402
1403 buffer, buf_size,
1404\layout LyX-Code
1405
1406 0);
1407\layout LyX-Code
1408
1409
1410\layout LyX-Code
1411
1412 if(rval
1413\series bold
1414.code
1415\series default
1416 == RC_OK) {
1417\layout LyX-Code
1418
1419 return rect; /* Decoding succeeded */
1420\layout LyX-Code
1421
1422 } else {
1423\layout LyX-Code
1424
Lev Walkin26587ab2004-08-23 15:12:04 +00001425 /* Free partially decoded rect */
1426\layout LyX-Code
1427
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00001428 asn_DEF_Rectangle.free_struct(
Lev Walkin84291e02004-06-03 03:49:45 +00001429\layout LyX-Code
1430
Lev Walkin1f756282004-09-29 13:29:17 +00001431 &asn_DEF_Rectangle, rect, 0);
Lev Walkin84291e02004-06-03 03:49:45 +00001432\layout LyX-Code
1433
1434 return 0;
1435\layout LyX-Code
1436
1437 }
1438\layout LyX-Code
1439
1440}
1441\layout Standard
1442
1443The code above defines a function,
1444\emph on
1445simple_deserializer
1446\emph default
Lev Walkin7f70fe52005-02-22 07:28:26 +00001447, which takes a buffer and its length and is expected to return a pointer
1448 to the Rectangle_t structure.
Lev Walkin84291e02004-06-03 03:49:45 +00001449 Inside, it tries to convert the bytes passed into the target structure
Lev Walkin7f70fe52005-02-22 07:28:26 +00001450 (rect) using the BER decoder and returns the rect pointer afterwards.
Lev Walkin84291e02004-06-03 03:49:45 +00001451 If the structure cannot be deserialized, it frees the memory which might
1452 be left allocated by the unfinished
1453\emph on
1454ber_decoder
1455\emph default
Lev Walkin09889622005-02-21 14:16:10 +00001456 routine and returns 0 (no data).
Lev Walkin7f70fe52005-02-22 07:28:26 +00001457 (This
Lev Walkin84291e02004-06-03 03:49:45 +00001458\series bold
Lev Walkin09889622005-02-21 14:16:10 +00001459 freeing is necessary
Lev Walkin84291e02004-06-03 03:49:45 +00001460\series default
1461 because the ber_decoder is a restartable procedure, and may fail just because
Lev Walkin7f70fe52005-02-22 07:28:26 +00001462 there is more data needs to be provided before decoding could be finalized).
Lev Walkin84291e02004-06-03 03:49:45 +00001463 The code above obviously does not take into account the way the
1464\emph on
Lev Walkin7f70fe52005-02-22 07:28:26 +00001465ber_decoder()
Lev Walkin84291e02004-06-03 03:49:45 +00001466\emph default
1467 failed, so the freeing is necessary because the part of the buffer may
1468 already be decoded into the structure by the time something goes wrong.
1469\layout Standard
1470
Lev Walkin7f70fe52005-02-22 07:28:26 +00001471A little less wordy would be to invoke a globally available
Lev Walkin84291e02004-06-03 03:49:45 +00001472\emph on
Lev Walkin7f70fe52005-02-22 07:28:26 +00001473ber_decode()
Lev Walkin84291e02004-06-03 03:49:45 +00001474\emph default
Lev Walkin7f70fe52005-02-22 07:28:26 +00001475 function instead of dereferencing the asn_DEF_Rectangle type descriptor:
Lev Walkin84291e02004-06-03 03:49:45 +00001476\layout LyX-Code
1477
Lev Walkin1f756282004-09-29 13:29:17 +00001478rval = ber_decode(0, &asn_DEF_Rectangle, (void **)&rect,
Lev Walkin84291e02004-06-03 03:49:45 +00001479\layout LyX-Code
1480
1481 buffer, buf_size);
1482\layout Standard
1483
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00001484Note that the initial (asn_DEF_Rectangle.ber_decoder) reference is gone,
Lev Walkin84291e02004-06-03 03:49:45 +00001485 and also the last argument (0) is no longer necessary.
1486\layout Standard
1487
Lev Walkin09889622005-02-21 14:16:10 +00001488These two ways of BER decoder invocations are fully equivalent.
Lev Walkin84291e02004-06-03 03:49:45 +00001489\layout Standard
1490
1491The BER de
1492\emph on
1493coder
1494\emph default
Lev Walkin1f756282004-09-29 13:29:17 +00001495 may fail because of (
Lev Walkin84291e02004-06-03 03:49:45 +00001496\emph on
1497the following RC_\SpecialChar \ldots{}
1498 codes are defined in ber_decoder.h
1499\emph default
1500):
1501\layout Itemize
1502
1503RC_WMORE: There is more data expected than it is provided (stream mode continuat
1504ion feature);
1505\layout Itemize
1506
1507RC_FAIL: General failure to decode the buffer;
1508\layout Itemize
1509
1510\SpecialChar \ldots{}
1511 other codes may be defined as well.
1512\layout Standard
1513
Lev Walkina646ccb2004-10-20 15:48:55 +00001514Together with the return code (.code) the asn_dec_rval_t type contains the
Lev Walkin84291e02004-06-03 03:49:45 +00001515 number of bytes which is consumed from the buffer.
1516 In the previous hypothetical example of two buffers (of 100 and 200 bytes),
1517 the first call to ber_decode() would return with .code = RC_WMORE and .consumed
1518 = 95.
1519 The .consumed field of the BER decoder return value is
1520\series bold
1521always
1522\series default
1523 valid, even if the decoder succeeds or fails with any other return code.
1524\layout Standard
1525
1526Please look into ber_decoder.h for the precise definition of ber_decode()
1527 and related types.
Lev Walkin26587ab2004-08-23 15:12:04 +00001528\layout Subsection
Lev Walkin84291e02004-06-03 03:49:45 +00001529
1530
1531\begin_inset LatexCommand \label{sub:Encoding-DER}
1532
1533\end_inset
1534
1535Encoding DER
1536\layout Standard
1537
Lev Walkin35d446b2004-09-24 20:56:07 +00001538The Distinguished Encoding Rules is the
1539\emph on
1540canonical
1541\emph default
1542 variant of BER encoding rules.
1543 The DER is best suited to encode the structures where all the lengths are
1544 known beforehand.
Lev Walkin84291e02004-06-03 03:49:45 +00001545 This is probably exactly how you want to encode: either after a BER decoding
1546 or after a manual fill-up, the target structure contains the data which
1547 size is implicitly known before encoding.
Lev Walkin09889622005-02-21 14:16:10 +00001548 Among other uses, the DER encoding is used to encode X.509 certificates.
Lev Walkin84291e02004-06-03 03:49:45 +00001549\layout Standard
1550
1551As with BER decoder, the DER encoder may be invoked either directly from
Lev Walkin1f756282004-09-29 13:29:17 +00001552 the ASN.1 type descriptor (asn_DEF_Rectangle) or from the stand-alone function,
Lev Walkin84291e02004-06-03 03:49:45 +00001553 which is somewhat simpler:
1554\layout LyX-Code
1555
Lev Walkin84291e02004-06-03 03:49:45 +00001556
1557\layout LyX-Code
1558
1559/*
1560\layout LyX-Code
1561
1562 * This is the serializer itself,
1563\layout LyX-Code
1564
1565 * it supplies the DER encoder with the
1566\layout LyX-Code
1567
1568 * pointer to the custom output function.
1569\layout LyX-Code
1570
1571 */
1572\layout LyX-Code
1573
1574ssize_t
1575\layout LyX-Code
1576
1577simple_serializer(FILE *ostream, Rectangle_t *rect) {
1578\layout LyX-Code
1579
Lev Walkin35d446b2004-09-24 20:56:07 +00001580 asn_enc_rval_t er; /* Encoder return value */
Lev Walkin84291e02004-06-03 03:49:45 +00001581\layout LyX-Code
1582
1583
1584\layout LyX-Code
1585
Lev Walkin1f756282004-09-29 13:29:17 +00001586 er = der_encode(&asn_DEF_Rect, rect,
Lev Walkin84291e02004-06-03 03:49:45 +00001587\layout LyX-Code
1588
Lev Walkin26587ab2004-08-23 15:12:04 +00001589 write_stream, ostream);
Lev Walkin84291e02004-06-03 03:49:45 +00001590\layout LyX-Code
1591
Lev Walkin35d446b2004-09-24 20:56:07 +00001592 if(er.
Lev Walkin84291e02004-06-03 03:49:45 +00001593\series bold
Lev Walkin35d446b2004-09-24 20:56:07 +00001594encoded
Lev Walkin84291e02004-06-03 03:49:45 +00001595\series default
1596 == -1) {
1597\layout LyX-Code
1598
1599 /*
1600\layout LyX-Code
1601
Lev Walkin35d446b2004-09-24 20:56:07 +00001602 * Failed to encode the rectangle data.
Lev Walkin84291e02004-06-03 03:49:45 +00001603\layout LyX-Code
1604
1605 */
1606\layout LyX-Code
1607
1608 fprintf(stderr,
1609\begin_inset Quotes sld
1610\end_inset
1611
1612Cannot encode %s: %s
1613\backslash
1614n
1615\begin_inset Quotes srd
1616\end_inset
1617
1618,
1619\layout LyX-Code
1620
Lev Walkin35d446b2004-09-24 20:56:07 +00001621 er.
Lev Walkin84291e02004-06-03 03:49:45 +00001622\series bold
Lev Walkin35d446b2004-09-24 20:56:07 +00001623failed_type
Lev Walkin84291e02004-06-03 03:49:45 +00001624\series default
1625->name,
1626\layout LyX-Code
1627
1628 strerror(errno));
1629\layout LyX-Code
1630
1631 return -1;
1632\layout LyX-Code
1633
1634 } else {
1635\layout LyX-Code
1636
1637 /* Return the number of bytes */
1638\layout LyX-Code
1639
Lev Walkin35d446b2004-09-24 20:56:07 +00001640 return er.encoded;
Lev Walkin84291e02004-06-03 03:49:45 +00001641\layout LyX-Code
1642
1643 }
1644\layout LyX-Code
1645
1646}
1647\layout Standard
1648
1649As you see, the DER encoder does not write into some sort of buffer or something.
1650 It just invokes the custom function (possible, multiple times) which would
1651 save the data into appropriate storage.
1652 The optional argument
1653\emph on
1654app_key
1655\emph default
1656 is opaque for the DER encoder code and just used by
1657\emph on
1658_write_stream()
1659\emph default
1660 as the pointer to the appropriate output stream to be used.
1661\layout Standard
1662
1663If the custom write function is not given (passed as 0), then the DER encoder
1664 will essentially do the same thing (i.e., encode the data) but no callbacks
1665 will be invoked (so the data goes nowhere).
1666 It may prove useful to determine the size of the structure's encoding before
1667 actually doing the encoding
1668\begin_inset Foot
1669collapsed false
1670
1671\layout Standard
1672
1673It is actually faster too: the encoder might skip over some computations
1674 which aren't important for the size determination.
1675\end_inset
1676
1677.
1678\layout Standard
1679
1680Please look into der_encoder.h for the precise definition of der_encode()
1681 and related types.
Lev Walkin26587ab2004-08-23 15:12:04 +00001682\layout Subsection
Lev Walkin84291e02004-06-03 03:49:45 +00001683
1684
Lev Walkin35d446b2004-09-24 20:56:07 +00001685\begin_inset LatexCommand \label{sub:Encoding-XER}
1686
1687\end_inset
1688
1689Encoding XER
1690\layout Standard
1691
1692The XER stands for XML Encoding Rules, where XML, in turn, is eXtensible
1693 Markup Language, a text-based format for information exchange.
1694 The encoder routine API comes in two flavors: stdio-based and callback-based.
1695 With the callback-based encoder, the encoding process is very similar to
1696 the DER one, described in Section
1697\begin_inset LatexCommand \vref{sub:Encoding-DER}
1698
1699\end_inset
1700
1701.
1702 The following example uses the definition of write_stream() from up there.
1703\layout LyX-Code
1704
1705/*
1706\layout LyX-Code
1707
1708 * This procedure generates the XML document
1709\layout LyX-Code
1710
1711 * by invoking the XER encoder.
1712\layout LyX-Code
1713
1714 * NOTE: Do not copy this code verbatim!
1715\layout LyX-Code
1716
1717 * If the stdio output is necessary,
1718\layout LyX-Code
1719
1720 * use the xer_fprint() procedure instead.
1721\layout LyX-Code
1722
1723 * See Section
1724\begin_inset LatexCommand \vref{sub:Printing-the-target}
1725
1726\end_inset
1727
1728.
1729\layout LyX-Code
1730
1731 */
1732\layout LyX-Code
1733
1734int
1735\layout LyX-Code
1736
1737print_as_XML(FILE *ostream, Rectangle_t *rect) {
1738\layout LyX-Code
1739
1740 asn_enc_rval_t er; /* Encoder return value */
1741\layout LyX-Code
1742
1743
1744\layout LyX-Code
1745
Lev Walkin09889622005-02-21 14:16:10 +00001746 er = xer_encode(&asn_DEF_Rectangle, rect,
Lev Walkin35d446b2004-09-24 20:56:07 +00001747\layout LyX-Code
1748
1749 XER_F_BASIC, /* BASIC-XER or CANONICAL-XER */
1750\layout LyX-Code
1751
1752 write_stream, ostream);
1753\layout LyX-Code
1754
1755
1756\layout LyX-Code
1757
1758 return (er.encoded == -1) ? -1 : 0;
1759\layout LyX-Code
1760
1761}
1762\layout Standard
1763
1764Please look into xer_encoder.h for the precise definition of xer_encode()
1765 and related types.
1766\layout Standard
1767
1768See Section
1769\begin_inset LatexCommand \ref{sub:Printing-the-target}
1770
1771\end_inset
1772
1773 for the example of stdio-based XML encoder and other pretty-printing suggestion
1774s.
1775\layout Subsection
1776
1777
Lev Walkin09889622005-02-21 14:16:10 +00001778\begin_inset LatexCommand \label{sub:Decoding-XER}
1779
1780\end_inset
1781
1782Decoding XER
1783\layout Standard
1784
1785The data encoded using the XER rules can be subsequently decoded using the
1786 xer_decode() API call:
1787\layout LyX-Code
1788
1789Rectangle_t *
1790\layout LyX-Code
1791
1792XML_to_Rectangle(const void *buffer, size_t buf_size) {
1793\layout LyX-Code
1794
1795 Rectangle_t *rect = 0; /* Note this 0! */
1796\layout LyX-Code
1797
1798 asn_dec_rval_t rval;
1799\layout LyX-Code
1800
1801
1802\layout LyX-Code
1803
1804 rval = xer_decode(0, &asn_DEF_Rectangle, (void **)&rect,
1805\layout LyX-Code
1806
1807 buffer, buf_size);
1808\layout LyX-Code
1809
1810 if(rval
1811\series bold
1812.code
1813\series default
1814 == RC_OK) {
1815\layout LyX-Code
1816
1817 return rect; /* Decoding succeeded */
1818\layout LyX-Code
1819
1820 } else {
1821\layout LyX-Code
1822
1823 /* Free partially decoded rect */
1824\layout LyX-Code
1825
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00001826 asn_DEF_Rectangle.free_struct(
Lev Walkin09889622005-02-21 14:16:10 +00001827\layout LyX-Code
1828
1829 &asn_DEF_Rectangle, rect, 0);
1830\layout LyX-Code
1831
1832 return 0;
1833\layout LyX-Code
1834
1835 }
1836\layout LyX-Code
1837
1838}
1839\layout Standard
1840
1841The decoder takes both BASIC-XER and CANONICAL-XER encodings.
1842\layout Standard
1843
Lev Walkin7f70fe52005-02-22 07:28:26 +00001844The decoder shares its data consumption properties with BER decoder; please
1845 read the Section
1846\begin_inset LatexCommand \vref{sub:Decoding-BER}
1847
1848\end_inset
1849
1850 to know more.
1851\layout Standard
1852
Lev Walkin09889622005-02-21 14:16:10 +00001853Please look into xer_decoder.h for the precise definition of xer_decode()
1854 and related types.
1855\layout Subsection
1856
1857
Lev Walkin84291e02004-06-03 03:49:45 +00001858\begin_inset LatexCommand \label{sub:Validating-the-target}
1859
1860\end_inset
1861
1862Validating the target structure
1863\layout Standard
1864
1865Sometimes the target structure needs to be validated.
1866 For example, if the structure was created by the application (as opposed
1867 to being decoded from some external source), some important information
1868 required by the ASN.1 specification might be missing.
1869 On the other hand, the successful decoding of the data from some external
1870 source does not necessarily mean that the data is fully valid either.
1871 It might well be the case that the specification describes some subtype
1872 constraints that were not taken into account during decoding, and it would
1873 actually be useful to perform the last check when the data is ready to
1874 be encoded or when the data has just been decoded to ensure its validity
1875 according to some stricter rules.
1876\layout Standard
1877
1878The asn_check_constraints() function checks the type for various implicit
1879 and explicit constraints.
1880 It is recommended to use asn_check_constraints() function after each decoding
1881 and before each encoding.
1882\layout Standard
1883
1884Please look into constraints.h for the precise definition of asn_check_constraint
1885s() and related types.
Lev Walkin26587ab2004-08-23 15:12:04 +00001886\layout Subsection
Lev Walkin84291e02004-06-03 03:49:45 +00001887
1888
1889\begin_inset LatexCommand \label{sub:Printing-the-target}
1890
1891\end_inset
1892
1893Printing the target structure
1894\layout Standard
1895
1896There are two ways to print the target structure: either invoke the print_struct
1897 member of the ASN.1 type descriptor, or using the asn_fprint() function,
1898 which is a simpler wrapper of the former:
1899\layout LyX-Code
1900
Lev Walkin1f756282004-09-29 13:29:17 +00001901asn_fprint(stdout, &asn_DEF_Rectangle, rect);
Lev Walkin84291e02004-06-03 03:49:45 +00001902\layout Standard
1903
1904Please look into constr_TYPE.h for the precise definition of asn_fprint()
1905 and related types.
Lev Walkin35d446b2004-09-24 20:56:07 +00001906\layout Standard
1907
1908Another practical alternative to this custom format printing would be to
1909 invoke XER encoder.
1910 The default BASIC-XER encoder performs reasonable formatting for the output
1911 to be useful and human readable.
1912 To invoke the XER decoder in a manner similar to asn_fprint(), use the
1913 xer_fprint() call:
1914\layout LyX-Code
1915
Lev Walkin1f756282004-09-29 13:29:17 +00001916xer_fprint(stdout, &asn_DEF_Rectangle, rect);
Lev Walkin35d446b2004-09-24 20:56:07 +00001917\layout Standard
1918
1919See Section
1920\begin_inset LatexCommand \vref{sub:Encoding-XER}
1921
1922\end_inset
1923
1924 for XML-related details.
Lev Walkin26587ab2004-08-23 15:12:04 +00001925\layout Subsection
Lev Walkin84291e02004-06-03 03:49:45 +00001926
1927
1928\begin_inset LatexCommand \label{sub:Freeing-the-target}
1929
1930\end_inset
1931
1932Freeing the target structure
1933\layout Standard
1934
1935Freeing the structure is slightly more complex than it may seem to.
1936 When the ASN.1 structure is freed, all the members of the structure and
Lev Walkin2f80e472006-08-18 07:11:27 +00001937 their submembers are recursively freed as well.
Lev Walkin84291e02004-06-03 03:49:45 +00001938 But it might not be feasible to free the structure itself.
1939 Consider the following case:
1940\layout LyX-Code
1941
1942struct my_figure { /* The custom structure */
1943\layout LyX-Code
1944
1945 int flags; /* <some custom member> */
1946\layout LyX-Code
1947
1948 /* The type is generated by the ASN.1 compiler */
1949\layout LyX-Code
1950
1951
1952\emph on
1953Rectangle_t rect;
1954\layout LyX-Code
1955
1956 /* other members of the structure */
1957\layout LyX-Code
1958
1959};
1960\layout Standard
1961
1962In this example, the application programmer defined a custom structure with
1963 one ASN.1-derived member (rect).
1964 This member is not a reference to the Rectangle_t, but an in-place inclusion
1965 of the Rectangle_t structure.
1966 If the freeing is necessary, the usual procedure of freeing everything
1967 must not be applied to the &rect pointer itself, because it does not point
Lev Walkin7f70fe52005-02-22 07:28:26 +00001968 to the memory block directly allocated by the memory allocation routine,
1969 but instead lies within a block allocated for the my_figure structure.
Lev Walkin84291e02004-06-03 03:49:45 +00001970\layout Standard
1971
1972To solve this problem, the free_struct routine has the additional argument
Lev Walkin7f70fe52005-02-22 07:28:26 +00001973 (besides the obvious type descriptor and target structure pointers), which
1974 is the flag specifying whether the outer pointer itself must be freed (0,
1975 default) or it should be left intact (non-zero value).
Lev Walkin84291e02004-06-03 03:49:45 +00001976\layout LyX-Code
1977
Lev Walkin09889622005-02-21 14:16:10 +00001978
1979\series bold
1980/* 1.
1981 Rectangle_t is defined within my_figure */
Lev Walkin84291e02004-06-03 03:49:45 +00001982\layout LyX-Code
1983
Lev Walkin09889622005-02-21 14:16:10 +00001984struct my_figure {
1985\layout LyX-Code
1986
1987 Rectangle_t rect;
1988\layout LyX-Code
1989
1990} *mf =
Lev Walkin84291e02004-06-03 03:49:45 +00001991\series bold
1992...
1993\series default
1994;
1995\layout LyX-Code
1996
1997/*
1998\layout LyX-Code
1999
Lev Walkin09889622005-02-21 14:16:10 +00002000 * Freeing the Rectangle_t
Lev Walkin84291e02004-06-03 03:49:45 +00002001\layout LyX-Code
2002
Lev Walkin09889622005-02-21 14:16:10 +00002003 * without freeing the mf->rect area
Lev Walkin84291e02004-06-03 03:49:45 +00002004\layout LyX-Code
2005
2006 */
2007\layout LyX-Code
2008
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00002009asn_DEF_Rectangle.free_struct(
Lev Walkin84291e02004-06-03 03:49:45 +00002010\layout LyX-Code
2011
Lev Walkin1f756282004-09-29 13:29:17 +00002012 &asn_DEF_Rectangle, &mf->rect,
Lev Walkin09889622005-02-21 14:16:10 +00002013\series bold
Lev Walkin84291e02004-06-03 03:49:45 +000020141
Lev Walkin09889622005-02-21 14:16:10 +00002015\emph on
Lev Walkin84291e02004-06-03 03:49:45 +00002016
Lev Walkin09889622005-02-21 14:16:10 +00002017\emph default
2018/* !free */
2019\series default
2020);
Lev Walkin84291e02004-06-03 03:49:45 +00002021\layout LyX-Code
2022
Lev Walkin09889622005-02-21 14:16:10 +00002023
2024\layout LyX-Code
2025
2026
2027\layout LyX-Code
2028
2029
2030\series bold
2031/* 2.
2032 Rectangle_t is a stand-alone pointer */
Lev Walkin84291e02004-06-03 03:49:45 +00002033\layout LyX-Code
2034
2035Rectangle_t *rect =
2036\series bold
2037...
2038\series default
2039;
2040\layout LyX-Code
2041
2042/*
2043\layout LyX-Code
2044
2045 * Freeing the Rectangle_t
2046\layout LyX-Code
2047
2048 * and freeing the rect pointer
2049\layout LyX-Code
2050
2051 */
2052\layout LyX-Code
2053
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00002054asn_DEF_Rectangle.free_struct(
Lev Walkin84291e02004-06-03 03:49:45 +00002055\layout LyX-Code
2056
Lev Walkin1f756282004-09-29 13:29:17 +00002057 &asn_DEF_Rectangle, rect,
Lev Walkin09889622005-02-21 14:16:10 +00002058\series bold
Lev Walkin84291e02004-06-03 03:49:45 +000020590
Lev Walkin09889622005-02-21 14:16:10 +00002060\emph on
2061
Lev Walkin84291e02004-06-03 03:49:45 +00002062\emph default
Lev Walkin09889622005-02-21 14:16:10 +00002063/* free the pointer too */
2064\series default
2065);
Lev Walkin84291e02004-06-03 03:49:45 +00002066\layout Standard
2067
2068It is safe to invoke the
2069\emph on
2070free_struct
2071\emph default
2072 function with the target structure pointer set to 0 (NULL), the function
2073 will do nothing.
Lev Walkin2f80e472006-08-18 07:11:27 +00002074\layout Standard
2075
2076For the programmer's convenience, the following macros are available:
2077\layout LyX-Code
2078
2079ASN_STRUCT_FREE(asn_DEF, ptr);
2080\layout LyX-Code
2081
2082ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr);
2083\layout Standard
2084
2085These macros bear the same semantics as the
2086\emph on
2087free_struct
2088\emph default
2089 function invocation, discussed above.
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002090\layout Chapter
Lev Walkindba8ca02005-01-14 11:38:49 +00002091
Lev Walkindee61782005-02-02 09:53:46 +00002092
2093\begin_inset LatexCommand \label{cha:Step-by-step-examples}
2094
2095\end_inset
2096
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002097Step by step examples
2098\layout Section
2099
2100A
2101\begin_inset Quotes sld
2102\end_inset
2103
2104Rectangle
2105\begin_inset Quotes srd
2106\end_inset
2107
2108 Encoder
2109\layout Standard
2110
Lev Walkin2f80e472006-08-18 07:11:27 +00002111This example will help you create a simple BER and XER encoder of a
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002112\begin_inset Quotes sld
2113\end_inset
2114
2115Rectangle
2116\begin_inset Quotes srd
2117\end_inset
2118
2119 type used throughout this document.
2120\layout Enumerate
2121
2122Create a file named
2123\series bold
2124rectangle.asn1
2125\series default
2126 with the following contents:
2127\begin_deeper
2128\layout LyX-Code
2129
2130RectangleModule1 DEFINITIONS ::=
2131\layout LyX-Code
2132
2133BEGIN
2134\layout LyX-Code
2135
2136
2137\layout LyX-Code
2138
2139Rectangle ::= SEQUENCE {
2140\layout LyX-Code
2141
2142 height INTEGER,
2143\layout LyX-Code
2144
2145 width INTEGER
2146\layout LyX-Code
2147
2148}
2149\layout LyX-Code
2150
2151
2152\layout LyX-Code
2153
2154END
2155\end_deeper
2156\layout Enumerate
2157
2158Compile it into the set of .c and .h files using asn1c compiler
2159\begin_inset LatexCommand \cite{ASN1C}
2160
2161\end_inset
2162
2163:
2164\begin_deeper
2165\layout LyX-Code
2166
2167
2168\emph on
2169asn1c -fnative-types
2170\series bold
2171\emph default
2172rectangle.asn1
2173\end_deeper
2174\layout Enumerate
2175
2176Alternatively, use the Online ASN.1 compiler
2177\begin_inset LatexCommand \cite{AONL}
2178
2179\end_inset
2180
2181 by uploading the
2182\series bold
2183rectangle.asn1
2184\series default
2185 file into the Web form and unpacking the produced archive on your computer.
2186\layout Enumerate
2187
2188By this time, you should have gotten multiple files in the current directory,
2189 including the
2190\series bold
2191Rectangle.c
2192\series default
2193 and
2194\series bold
2195Rectangle.h
2196\series default
2197.
2198\layout Enumerate
2199
2200Create a main() routine which creates the Rectangle_t structure in memory
2201 and encodes it using BER and XER encoding rules.
2202 Let's name the file
2203\series bold
2204main.c
2205\series default
2206:
2207\begin_inset ERT
2208status Open
2209
2210\layout Standard
2211
2212\backslash
2213clearpage{}
2214\end_inset
2215
2216
2217\begin_deeper
2218\layout LyX-Code
2219
2220
2221\size small
2222#include <stdio.h>
2223\layout LyX-Code
2224
2225
2226\size small
2227#include <sys/types.h>
2228\layout LyX-Code
2229
2230
2231\size small
2232#include <Rectangle.h> /* Rectangle ASN.1 type */
2233\layout LyX-Code
2234
2235
2236\layout LyX-Code
2237
2238
2239\size small
2240/*
2241\layout LyX-Code
2242
2243
2244\size small
2245 * This is a custom function which writes the
2246\layout LyX-Code
2247
2248
2249\size small
2250 * encoded output into some FILE stream.
2251\layout LyX-Code
2252
2253
2254\size small
2255 */
2256\layout LyX-Code
2257
2258
2259\size small
2260static int
2261\layout LyX-Code
2262
2263
2264\size small
2265write_out(const void *buffer, size_t size, void *app_key) {
2266\layout LyX-Code
2267
2268
2269\size small
2270 FILE *out_fp = app_key;
2271\layout LyX-Code
2272
2273
2274\size small
2275 size_t wrote;
2276\layout LyX-Code
2277
2278
2279\size small
2280
2281\layout LyX-Code
2282
2283
2284\size small
2285 wrote = fwrite(buffer, 1, size, out_fp);
2286\layout LyX-Code
2287
2288
2289\size small
2290
2291\layout LyX-Code
2292
2293
2294\size small
2295 return (wrote == size) ? 0 : -1;
2296\layout LyX-Code
2297
2298
2299\size small
2300}
2301\layout LyX-Code
2302
2303
2304\layout LyX-Code
2305
2306
2307\size small
Lev Walkin6b0df9f2005-01-31 15:06:32 +00002308int main(int ac, char **av) {
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002309\layout LyX-Code
2310
2311
2312\size small
2313 Rectangle_t *rectangle; /* Type to encode */
2314\layout LyX-Code
2315
2316
2317\size small
2318 asn_enc_rval_t ec; /* Encoder return value */
2319\layout LyX-Code
2320
2321
2322\size small
2323
2324\layout LyX-Code
2325
2326
2327\size small
2328 /* Allocate the Rectangle_t */
2329\layout LyX-Code
2330
2331
2332\size small
Lev Walkindee61782005-02-02 09:53:46 +00002333 rectangle = calloc(1, sizeof(Rectangle_t)); /* not malloc! */
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002334\layout LyX-Code
2335
2336
2337\size small
2338 if(!rectangle) {
2339\layout LyX-Code
2340
2341
2342\size small
2343 perror(
2344\begin_inset Quotes sld
2345\end_inset
2346
2347calloc() failed
2348\begin_inset Quotes srd
2349\end_inset
2350
2351);
2352\layout LyX-Code
2353
2354
2355\size small
2356 exit(71); /* better, EX_OSERR */
2357\layout LyX-Code
2358
2359
2360\size small
2361 }
2362\layout LyX-Code
2363
2364
2365\size small
2366
2367\layout LyX-Code
2368
2369
2370\size small
2371 /* Initialize the Rectangle members */
2372\layout LyX-Code
2373
2374
2375\size small
2376 rectangle->height = 42; /* any random value */
2377\layout LyX-Code
2378
2379
2380\size small
2381 rectangle->width = 23; /* any random value */
2382\layout LyX-Code
2383
2384
2385\size small
2386
2387\layout LyX-Code
2388
2389
2390\size small
2391 /* BER encode the data if filename is given */
2392\layout LyX-Code
2393
2394
2395\size small
2396 if(ac < 2) {
2397\layout LyX-Code
2398
2399
2400\size small
2401 fprintf(stderr,
2402\begin_inset Quotes sld
2403\end_inset
2404
2405Specify filename for BER output
2406\backslash
2407n
2408\begin_inset Quotes srd
2409\end_inset
2410
2411);
2412\layout LyX-Code
2413
2414
2415\size small
2416 } else {
2417\layout LyX-Code
2418
2419
2420\size small
2421 const char *filename = av[1];
2422\layout LyX-Code
2423
2424
2425\size small
2426 FILE *fp = fopen(filename,
2427\begin_inset Quotes sld
2428\end_inset
2429
Lev Walkind4eb17d2005-07-21 18:45:37 +00002430wb
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002431\begin_inset Quotes srd
2432\end_inset
2433
2434); /* for BER output */
2435\layout LyX-Code
2436
2437
2438\layout LyX-Code
2439
2440
2441\size small
2442 if(!fp) {
2443\layout LyX-Code
2444
2445
2446\size small
2447 perror(filename);
2448\layout LyX-Code
2449
2450
2451\size small
2452 exit(71); /* better, EX_OSERR */
2453\layout LyX-Code
2454
2455
2456\size small
2457 }
2458\layout LyX-Code
2459
2460
2461\size small
2462
2463\layout LyX-Code
2464
2465
2466\size small
2467 /* Encode the Rectangle type as BER (DER) */
2468\layout LyX-Code
2469
2470
2471\size small
2472 ec = der_encode(&asn_DEF_Rectangle,
2473\layout LyX-Code
2474
2475
2476\size small
Lev Walkin6b0df9f2005-01-31 15:06:32 +00002477 rectangle, write_out, fp);
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002478\layout LyX-Code
2479
2480
2481\size small
2482 fclose(fp);
2483\layout LyX-Code
2484
2485
2486\size small
2487 if(ec.encoded == -1) {
2488\layout LyX-Code
2489
2490
2491\size small
2492 fprintf(stderr,
2493\layout LyX-Code
2494
2495
2496\size small
2497
2498\begin_inset Quotes sld
2499\end_inset
2500
2501Could not encode Rectangle (at %s)
2502\backslash
2503n
2504\begin_inset Quotes srd
2505\end_inset
2506
2507,
2508\layout LyX-Code
2509
2510
2511\size small
2512 ec.failed_type ? ec.failed_type->name :
2513\begin_inset Quotes sld
2514\end_inset
2515
2516unknown
2517\begin_inset Quotes srd
2518\end_inset
2519
2520);
2521\layout LyX-Code
2522
2523
2524\size small
2525 exit(65); /* better, EX_DATAERR */
2526\layout LyX-Code
2527
2528
2529\size small
2530 } else {
2531\layout LyX-Code
2532
2533
2534\size small
2535 fprintf(stderr,
2536\begin_inset Quotes sld
2537\end_inset
2538
2539Created %s with BER encoded Rectangle
2540\backslash
2541n
2542\begin_inset Quotes srd
2543\end_inset
2544
2545,
2546\layout LyX-Code
2547
2548
2549\size small
2550 filename);
2551\layout LyX-Code
2552
2553
2554\size small
2555 }
2556\layout LyX-Code
2557
2558
2559\size small
2560 }
2561\layout LyX-Code
2562
2563
2564\size small
2565
2566\layout LyX-Code
2567
2568
2569\size small
2570 /* Also print the constructed Rectangle XER encoded (XML) */
2571\layout LyX-Code
2572
2573
2574\size small
2575 xer_fprint(stdout, &asn_DEF_Rectangle, rectangle);
2576\layout LyX-Code
2577
2578
2579\size small
2580
2581\layout LyX-Code
2582
2583
2584\size small
2585 return 0; /* Encoding finished successfully */
2586\layout LyX-Code
2587
2588
2589\size small
2590}
2591\end_deeper
2592\layout Enumerate
2593
2594Compile all files together using C compiler (varies by platform):
2595\begin_deeper
2596\layout LyX-Code
2597
2598
2599\emph on
2600cc -I.
2601 -o
2602\series bold
2603rencode
2604\series default
2605 *.c
2606\end_deeper
2607\layout Enumerate
2608
2609Voila! You have just created the BER and XER encoder of a Rectangle type,
2610 named
2611\series bold
2612rencode
2613\series default
2614!
2615\layout Standard
2616
2617
2618\begin_inset ERT
2619status Collapsed
2620
2621\layout Standard
2622
2623\backslash
2624clearpage{}
2625\end_inset
2626
2627
2628\layout Section
2629
Lev Walkindee61782005-02-02 09:53:46 +00002630
2631\begin_inset LatexCommand \label{sec:A-Rectangle-Decoder}
2632
2633\end_inset
2634
Lev Walkinfecbd1e2005-01-31 10:10:04 +00002635A
Lev Walkindba8ca02005-01-14 11:38:49 +00002636\begin_inset Quotes sld
2637\end_inset
2638
2639Rectangle
2640\begin_inset Quotes srd
2641\end_inset
2642
2643 Decoder
2644\layout Standard
2645
Lev Walkindee61782005-02-02 09:53:46 +00002646This example will help you to create a simple BER decoder of a simple
Lev Walkindba8ca02005-01-14 11:38:49 +00002647\begin_inset Quotes sld
2648\end_inset
2649
2650Rectangle
2651\begin_inset Quotes srd
2652\end_inset
2653
2654 type used throughout this document.
2655\layout Enumerate
2656
2657Create a file named
2658\series bold
2659rectangle.asn1
2660\series default
2661 with the following contents:
2662\begin_deeper
2663\layout LyX-Code
2664
2665RectangleModule1 DEFINITIONS ::=
2666\layout LyX-Code
2667
2668BEGIN
2669\layout LyX-Code
2670
2671
2672\layout LyX-Code
2673
2674Rectangle ::= SEQUENCE {
2675\layout LyX-Code
2676
2677 height INTEGER,
2678\layout LyX-Code
2679
2680 width INTEGER
2681\layout LyX-Code
2682
2683}
2684\layout LyX-Code
2685
2686
2687\layout LyX-Code
2688
2689END
2690\end_deeper
2691\layout Enumerate
2692
2693Compile it into the set of .c and .h files using asn1c compiler
2694\begin_inset LatexCommand \cite{ASN1C}
2695
2696\end_inset
2697
2698:
2699\begin_deeper
2700\layout LyX-Code
2701
2702
2703\emph on
2704asn1c -fnative-types
2705\series bold
2706\emph default
2707rectangle.asn1
2708\end_deeper
2709\layout Enumerate
2710
2711Alternatively, use the Online ASN.1 compiler
2712\begin_inset LatexCommand \cite{AONL}
2713
2714\end_inset
2715
2716 by uploading the
2717\series bold
2718rectangle.asn1
2719\series default
Lev Walkinfc67f3e2005-01-17 11:05:04 +00002720 file into the Web form and unpacking the produced archive on your computer.
Lev Walkindba8ca02005-01-14 11:38:49 +00002721\layout Enumerate
2722
Lev Walkinfc67f3e2005-01-17 11:05:04 +00002723By this time, you should have gotten multiple files in the current directory,
2724 including the
2725\series bold
2726Rectangle.c
2727\series default
2728 and
2729\series bold
2730Rectangle.h
2731\series default
2732.
Lev Walkindba8ca02005-01-14 11:38:49 +00002733\layout Enumerate
2734
2735Create a main() routine which takes the binary input file, decodes it as
Lev Walkinfc67f3e2005-01-17 11:05:04 +00002736 it were a BER-encoded Rectangle type, and prints out the text (XML) representat
2737ion of the Rectangle type.
Lev Walkindba8ca02005-01-14 11:38:49 +00002738 Let's name the file
2739\series bold
2740main.c
2741\series default
2742:
Lev Walkinfc67f3e2005-01-17 11:05:04 +00002743\begin_inset ERT
Lev Walkindee61782005-02-02 09:53:46 +00002744status Collapsed
Lev Walkinfc67f3e2005-01-17 11:05:04 +00002745
2746\layout Standard
2747
2748\backslash
2749clearpage{}
2750\end_inset
2751
2752
Lev Walkindba8ca02005-01-14 11:38:49 +00002753\begin_deeper
2754\layout LyX-Code
2755
2756
2757\size small
2758#include <stdio.h>
2759\layout LyX-Code
2760
2761
2762\size small
2763#include <sys/types.h>
2764\layout LyX-Code
2765
2766
2767\size small
2768#include <Rectangle.h> /* Rectangle ASN.1 type */
2769\layout LyX-Code
2770
2771
2772\size small
2773
2774\layout LyX-Code
2775
2776
2777\size small
2778int main(int ac, char **av) {
2779\layout LyX-Code
2780
2781
2782\size small
2783 char buf[1024]; /* Temporary buffer */
2784\layout LyX-Code
2785
2786
2787\size small
2788 Rectangle_t *rectangle = 0; /* Type to decode */
2789\layout LyX-Code
2790
2791
2792\size small
2793 asn_dec_rval_t rval; /* Decoder return value */
2794\layout LyX-Code
2795
2796
2797\size small
2798 FILE *fp; /* Input file handler */
2799\layout LyX-Code
2800
2801
2802\size small
2803 size_t size; /* Number of bytes read */
2804\layout LyX-Code
2805
2806
2807\size small
2808 char *filename; /* Input file name */
2809\layout LyX-Code
2810
2811
2812\size small
2813
2814\layout LyX-Code
2815
2816
2817\size small
2818 /* Require a single filename argument */
2819\layout LyX-Code
2820
2821
2822\size small
2823 if(ac != 2) {
2824\layout LyX-Code
2825
2826
2827\size small
2828 fprintf(stderr,
2829\begin_inset Quotes sld
2830\end_inset
2831
2832Usage: %s <file.ber>
2833\backslash
2834n
2835\begin_inset Quotes srd
2836\end_inset
2837
2838, av[0]);
2839\layout LyX-Code
2840
2841
2842\size small
2843 exit(64); /* better, EX_USAGE */
2844\layout LyX-Code
2845
2846
2847\size small
2848 } else {
2849\layout LyX-Code
2850
2851
2852\size small
2853 filename = av[1];
2854\layout LyX-Code
2855
2856
2857\size small
2858 }
2859\layout LyX-Code
2860
2861
2862\size small
2863
2864\layout LyX-Code
2865
2866
2867\size small
2868 /* Open input file as read-only binary */
2869\layout LyX-Code
2870
2871
2872\size small
2873 fp = fopen(filename,
2874\begin_inset Quotes sld
2875\end_inset
2876
2877rb
2878\begin_inset Quotes srd
2879\end_inset
2880
2881);
2882\layout LyX-Code
2883
2884
2885\size small
2886 if(!fp) {
2887\layout LyX-Code
2888
2889
2890\size small
2891 perror(filename);
2892\layout LyX-Code
2893
2894
2895\size small
2896 exit(66); /* better, EX_NOINPUT */
2897\layout LyX-Code
2898
2899
2900\size small
2901 }
2902\layout LyX-Code
2903
2904
2905\size small
2906
2907\layout LyX-Code
2908
2909
2910\size small
2911 /* Read up to the buffer size */
2912\layout LyX-Code
2913
2914
2915\size small
2916 size = fread(buf, 1, sizeof(buf), fp);
2917\layout LyX-Code
2918
2919
2920\size small
2921 fclose(fp);
2922\layout LyX-Code
2923
2924
2925\size small
2926 if(!size) {
2927\layout LyX-Code
2928
2929
2930\size small
2931 fprintf(stderr,
2932\begin_inset Quotes sld
2933\end_inset
2934
2935%s: Empty or broken
2936\backslash
2937n
2938\begin_inset Quotes srd
2939\end_inset
2940
2941, filename);
2942\layout LyX-Code
2943
2944
2945\size small
2946 exit(65); /* better, EX_DATAERR */
2947\layout LyX-Code
2948
2949
2950\size small
2951 }
2952\layout LyX-Code
2953
2954
2955\size small
2956
2957\layout LyX-Code
2958
2959
2960\size small
2961 /* Decode the input buffer as Rectangle type */
2962\layout LyX-Code
2963
2964
2965\size small
2966 rval = ber_decode(0, &asn_DEF_Rectangle,
2967\layout LyX-Code
2968
2969
2970\size small
2971 (void **)&rectangle, buf, size);
2972\layout LyX-Code
2973
2974
2975\size small
2976 if(rval.code != RC_OK) {
2977\layout LyX-Code
2978
2979
2980\size small
2981 fprintf(stderr,
2982\layout LyX-Code
2983
2984
2985\size small
2986
2987\begin_inset Quotes sld
2988\end_inset
2989
2990%s: Broken Rectangle encoding at byte %ld
2991\backslash
2992n
2993\begin_inset Quotes srd
2994\end_inset
2995
2996,
2997\layout LyX-Code
2998
2999
3000\size small
3001 filename, (long)rval.consumed);
3002\layout LyX-Code
3003
3004
3005\size small
3006 exit(65); /* better, EX_DATAERR */
3007\layout LyX-Code
3008
3009
3010\size small
3011 }
3012\layout LyX-Code
3013
3014
3015\size small
3016
3017\layout LyX-Code
3018
3019
3020\size small
3021 /* Print the decoded Rectangle type as XML */
3022\layout LyX-Code
3023
3024
3025\size small
3026 xer_fprint(stdout, &asn_DEF_Rectangle, rectangle);
3027\layout LyX-Code
3028
3029
3030\size small
3031
3032\layout LyX-Code
3033
3034
3035\size small
3036 return 0; /* Decoding finished successfully */
3037\layout LyX-Code
3038
3039
3040\size small
3041}
3042\end_deeper
3043\layout Enumerate
3044
Lev Walkinfc67f3e2005-01-17 11:05:04 +00003045Compile all files together using C compiler (varies by platform):
Lev Walkindba8ca02005-01-14 11:38:49 +00003046\begin_deeper
3047\layout LyX-Code
3048
3049
3050\emph on
3051cc -I.
Lev Walkinfc67f3e2005-01-17 11:05:04 +00003052 -o
3053\series bold
3054rdecode
3055\series default
3056 *.c
Lev Walkindba8ca02005-01-14 11:38:49 +00003057\end_deeper
3058\layout Enumerate
3059
Lev Walkinfecbd1e2005-01-31 10:10:04 +00003060Voila! You have just created the BER decoder of a Rectangle type, named
3061
Lev Walkindba8ca02005-01-14 11:38:49 +00003062\series bold
3063rdecode
3064\series default
3065!
Lev Walkindee61782005-02-02 09:53:46 +00003066\layout Chapter
3067
3068Constraint validation examples
3069\layout Standard
3070
3071This chapter shows how to define ASN.1 constraints and use the generated
3072 validation code.
3073\layout Section
3074
3075Adding constraints into
3076\begin_inset Quotes sld
3077\end_inset
3078
3079Rectangle
3080\begin_inset Quotes srd
3081\end_inset
3082
3083 type
3084\layout Standard
3085
3086This example shows how to add basic constraints to the ASN.1 specification
3087 and how to invoke the constraints validation code in your application.
3088\layout Enumerate
3089
3090Create a file named
3091\series bold
3092rectangle.asn1
3093\series default
3094 with the following contents:
3095\begin_deeper
3096\layout LyX-Code
3097
3098RectangleModuleWithConstraints DEFINITIONS ::=
3099\layout LyX-Code
3100
3101BEGIN
3102\layout LyX-Code
3103
3104
3105\layout LyX-Code
3106
3107Rectangle ::= SEQUENCE {
3108\layout LyX-Code
3109
3110 height INTEGER (0..100), -- Value range constraint
3111\layout LyX-Code
3112
3113 width INTEGER (0..MAX) -- Makes width non-negative
3114\layout LyX-Code
3115
3116}
3117\layout LyX-Code
3118
3119
3120\layout LyX-Code
3121
3122END
3123\end_deeper
3124\layout Enumerate
3125
3126Compile the file according to procedures shown in the previous chapter.
3127\layout Enumerate
3128
3129Modify the Rectangle type processing routine (you can start with the main()
3130 routine shown in the Section
3131\begin_inset LatexCommand \vref{sec:A-Rectangle-Decoder}
3132
3133\end_inset
3134
3135) by placing the following snippet of code
3136\emph on
3137before
3138\emph default
3139 encoding and/or
3140\emph on
3141after
3142\emph default
3143 decoding the Rectangle type
3144\begin_inset Foot
3145collapsed true
3146
3147\layout Standard
3148
3149Placing the constraint checking code
3150\emph on
3151before
3152\emph default
3153 encoding helps to make sure you know the data is correct and within constraints
3154 before sharing the data with anyone else.
3155\layout Standard
3156
3157Placing the constraint checking code
3158\emph on
3159after
3160\emph default
3161 decoding, but before any further action depending on the decoded data,
3162 helps to make sure the application got the valid contents before making
3163 use of it.
3164\end_inset
3165
3166:
3167\begin_inset ERT
3168status Collapsed
3169
3170\layout Standard
3171
3172\backslash
3173clearpage{}
3174\end_inset
3175
3176
3177\begin_deeper
3178\layout LyX-Code
3179
3180
3181\size small
3182int ret; /* Return value */
3183\layout LyX-Code
3184
3185
3186\size small
3187char errbuf[128]; /* Buffer for error message */
3188\layout LyX-Code
3189
3190
3191\size small
3192size_t errlen = sizeof(errbuf); /* Size of the buffer */
3193\layout LyX-Code
3194
3195
3196\size small
3197
3198\layout LyX-Code
3199
3200
3201\size small
3202/* ...
3203 here may go Rectangle decoding code ...
3204 */
3205\layout LyX-Code
3206
3207
3208\size small
3209
3210\layout LyX-Code
3211
3212
3213\size small
Lev Walkin0f5c5cf2005-08-29 10:23:20 +00003214ret = asn_check_constraints(&asn_DEF_Rectangle,
Lev Walkindee61782005-02-02 09:53:46 +00003215\layout LyX-Code
3216
3217
3218\size small
3219 rectangle, errbuf, &errlen);
3220\layout LyX-Code
3221
3222
3223\size small
3224/* assert(errlen < sizeof(errbuf)); // you may rely on that */
3225\layout LyX-Code
3226
3227
3228\size small
3229if(ret) {
3230\layout LyX-Code
3231
3232
3233\size small
3234 fprintf(stderr,
3235\begin_inset Quotes sld
3236\end_inset
3237
3238Constraint validation failed: %s
3239\backslash
3240n
3241\begin_inset Quotes srd
3242\end_inset
3243
3244,
3245\layout LyX-Code
3246
3247
3248\size small
3249 errbuf /* errbuf is properly nul-terminated */
3250\layout LyX-Code
3251
3252
3253\size small
3254 );
3255\layout LyX-Code
3256
3257
3258\size small
3259 /* exit(...); // Replace with appropriate action */
3260\layout LyX-Code
3261
3262
3263\size small
3264}
3265\layout LyX-Code
3266
3267
3268\size small
3269
3270\layout LyX-Code
3271
3272
3273\size small
3274/* ...
3275 here may go Rectangle encoding code ...
3276 */
3277\end_deeper
3278\layout Enumerate
3279
3280Compile the resulting C code as shown in the previous chapters.
3281\layout Enumerate
3282
Lev Walkin1411d052005-02-02 11:06:38 +00003283Try to test the constraints checking code by assigning integer value 101
3284 to the
3285\series bold
3286.height
3287\series default
3288 member of the Rectangle structure, or a negative value to the
3289\series bold
3290.width
3291\series default
3292 member.
3293 In either case, the program should print
3294\begin_inset Quotes sld
3295\end_inset
3296
3297Constraint validation failed
3298\begin_inset Quotes srd
3299\end_inset
3300
3301 message, followed by the short explanation why validation did not succeed.
3302\layout Enumerate
3303
Lev Walkindee61782005-02-02 09:53:46 +00003304Done.
Lev Walkin09889622005-02-21 14:16:10 +00003305\layout Part
3306
3307
3308\begin_inset LatexCommand \label{par:ASN.1-Basics}
3309
3310\end_inset
3311
3312ASN.1 Basics
3313\layout Chapter
3314
3315
3316\begin_inset LatexCommand \label{cha:Abstract-Syntax-Notation:}
3317
3318\end_inset
3319
3320Abstract Syntax Notation: ASN.1
3321\layout Standard
3322
3323
3324\emph on
3325This chapter defines some basic ASN.1 concepts and describes several most
3326 widely used types.
3327 It is by no means an authoritative or complete reference.
3328 For more complete ASN.1 description, please refer to Olivier Dubuisson's
3329 book
3330\begin_inset LatexCommand \cite{Dub00}
3331
3332\end_inset
3333
3334 or the ASN.1 body of standards itself
3335\begin_inset LatexCommand \cite{ITU-T/ASN.1}
3336
3337\end_inset
3338
3339.
3340\layout Standard
3341
3342The Abstract Syntax Notation One is used to formally describe the semantics
3343 of data transmitted across the network.
3344 Two communicating parties may have different formats of their native data
3345 types (i.e.
3346 number of bits in the integer type), thus it is important to have a way
3347 to describe the data in a manner which is independent from the particular
3348 machine's representation.
3349 The ASN.1 specifications are used to achieve the following:
3350\layout Itemize
3351
3352The specification expressed in the ASN.1 notation is a formal and precise
3353 way to communicate the data semantics to human readers;
3354\layout Itemize
3355
3356The ASN.1 specifications may be used as input for automatic compilers which
3357 produce the code for some target language (C, C++, Java, etc) to encode
3358 and decode the data according to some encoding rules (which are also defined
3359 by the ASN.1 standard).
3360\layout Standard
3361
3362Consider the following example:
3363\layout LyX-Code
3364
3365Rectangle ::= SEQUENCE {
3366\layout LyX-Code
3367
3368 height INTEGER,
3369\layout LyX-Code
3370
3371 width INTEGER
3372\layout LyX-Code
3373
3374}
3375\layout Standard
3376
3377This ASN.1 specification describes a constructed type,
3378\emph on
3379Rectangle
3380\emph default
3381, containing two integer fields.
3382 This specification may tell the reader that there exists this kind of data
3383 structure and that some entity may be prepared to send or receive it.
3384 The question on
3385\emph on
3386how
3387\emph default
3388 that entity is going to send or receive the
3389\emph on
3390encoded data
3391\emph default
3392 is outside the scope of ASN.1.
3393 For example, this data structure may be encoded according to some encoding
3394 rules and sent to the destination using the TCP protocol.
3395 The ASN.1 specifies several ways of encoding (or
3396\begin_inset Quotes sld
3397\end_inset
3398
3399serializing
3400\begin_inset Quotes srd
3401\end_inset
3402
3403, or
3404\begin_inset Quotes sld
3405\end_inset
3406
3407marshaling
3408\begin_inset Quotes srd
3409\end_inset
3410
3411) the data: BER, PER, XER and others, including CER and DER derivatives
3412 from BER.
3413\layout Standard
3414
3415The complete specification must be wrapped in a module, which looks like
3416 this:
3417\layout LyX-Code
3418
3419RectangleModule1
3420\layout LyX-Code
3421
3422 { iso org(3) dod(6) internet(1) private(4)
3423\layout LyX-Code
3424
3425 enterprise(1) spelio(9363) software(1)
3426\layout LyX-Code
3427
3428 asn1c(5) docs(2) rectangle(1) 1 }
3429\layout LyX-Code
3430
3431 DEFINITIONS AUTOMATIC TAGS ::=
3432\layout LyX-Code
3433
3434BEGIN
3435\layout LyX-Code
3436
3437
3438\layout LyX-Code
3439
3440-- This is a comment which describes nothing.
3441\layout LyX-Code
3442
3443Rectangle ::= SEQUENCE {
3444\layout LyX-Code
3445
3446 height INTEGER, -- Height of the rectangle
3447\layout LyX-Code
3448
3449 width INTEGER -- Width of the rectangle
3450\layout LyX-Code
3451
3452}
3453\layout LyX-Code
3454
3455
3456\layout LyX-Code
3457
3458END
3459\layout Standard
3460
3461The module header consists of module name (RectangleModule1), the module
3462 object identifier ({...}), a keyword
3463\begin_inset Quotes sld
3464\end_inset
3465
3466DEFINITIONS
3467\begin_inset Quotes srd
3468\end_inset
3469
3470, a set of module flags (AUTOMATIC TAGS) and
3471\begin_inset Quotes sld
3472\end_inset
3473
3474::= BEGIN
3475\begin_inset Quotes srd
3476\end_inset
3477
3478.
3479 The module ends with an
3480\begin_inset Quotes sld
3481\end_inset
3482
3483END
3484\begin_inset Quotes srd
3485\end_inset
3486
3487 statement.
3488\layout Section
3489
3490Some of the ASN.1 Basic Types
3491\layout Subsection
3492
3493The BOOLEAN type
3494\layout Standard
3495
3496The BOOLEAN type models the simple binary TRUE/FALSE, YES/NO, ON/OFF or
3497 a similar kind of two-way choice.
3498\layout Subsection
3499
3500The INTEGER type
3501\layout Standard
3502
3503The INTEGER type is a signed natural number type without any restrictions
3504 on its size.
3505 If the automatic checking on INTEGER value bounds are necessary, the subtype
3506 constraints must be used.
3507\layout LyX-Code
3508
3509SimpleInteger ::= INTEGER
3510\layout LyX-Code
3511
3512
3513\layout LyX-Code
3514
3515-- An integer with a very limited range
3516\layout LyX-Code
3517
3518SmallPositiveInt ::= INTEGER (0..127)
3519\layout LyX-Code
3520
3521
3522\layout LyX-Code
3523
3524-- Integer, negative
3525\layout LyX-Code
3526
3527NegativeInt ::= INTEGER (MIN..0)
3528\layout Subsection
3529
3530The ENUMERATED type
3531\layout Standard
3532
3533The ENUMERATED type is semantically equivalent to the INTEGER type with
3534 some integer values explicitly named.
3535\layout LyX-Code
3536
3537FruitId ::= ENUMERATED { apple(1), orange(2) }
3538\layout LyX-Code
3539
3540
3541\layout LyX-Code
3542
3543-- The numbers in braces are optional,
3544\layout LyX-Code
3545
3546-- the enumeration can be performed
3547\layout LyX-Code
3548
3549-- automatically by the compiler
3550\layout LyX-Code
3551
3552ComputerOSType ::= ENUMERATED {
3553\layout LyX-Code
3554
3555 FreeBSD, -- acquires value 0
3556\layout LyX-Code
3557
3558 Windows, -- acquires value 1
3559\layout LyX-Code
3560
3561 Solaris(5), -- remains 5
3562\layout LyX-Code
3563
3564 Linux, -- becomes 6
3565\layout LyX-Code
3566
3567 MacOS -- becomes 7
3568\layout LyX-Code
3569
3570}
3571\layout Subsection
3572
3573The OCTET STRING type
3574\layout Standard
3575
3576This type models the sequence of 8-bit bytes.
3577 This may be used to transmit some opaque data or data serialized by other
3578 types of encoders (i.e.
3579 video file, photo picture, etc).
3580\layout Subsection
3581
3582The OBJECT IDENTIFIER type
3583\layout Standard
3584
3585The OBJECT IDENTIFIER is used to represent the unique identifier of any
3586 object, starting from the very root of the registration tree.
3587 If your organization needs to uniquely identify something (a router, a
3588 room, a person, a standard, or whatever), you are encouraged to get your
3589 own identification subtree at
3590\begin_inset LatexCommand \htmlurl{http://www.iana.org/protocols/forms.htm}
3591
3592\end_inset
3593
3594.
3595\layout Standard
3596
3597For example, the very first ASN.1 module in this Chapter (RectangleModule1)
3598 has the following OBJECT IDENTIFIER: 1 3 6 1 4 1 9363 1 5 2 1 1.
3599\layout LyX-Code
3600
3601ExampleOID ::= OBJECT IDENTIFIER
3602\layout LyX-Code
3603
3604
3605\layout LyX-Code
3606
3607rectangleModule1-oid ExampleOID
3608\layout LyX-Code
3609
3610 ::= { 1 3 6 1 4 1 9363 1 5 2 1 1 }
3611\layout LyX-Code
3612
3613
3614\layout LyX-Code
3615
3616-- An identifier of the Internet.
3617\layout LyX-Code
3618
3619internet-id OBJECT IDENTIFIER
3620\layout LyX-Code
3621
3622 ::= { iso(1) identified-organization(3)
3623\layout LyX-Code
3624
3625 dod(6) internet(1) }
3626\layout Standard
3627
3628As you see, names are optional.
3629\layout Subsection
3630
3631The RELATIVE-OID type
3632\layout Standard
3633
3634The RELATIVE-OID type has the semantics of a subtree of an OBJECT IDENTIFIER.
3635 There may be no need to repeat the whole sequence of numbers from the root
3636 of the registration tree where the only thing of interest is some of the
3637 tree's subsequence.
3638\layout LyX-Code
3639
3640this-document RELATIVE-OID ::= { docs(2) usage(1) }
3641\layout LyX-Code
3642
3643
3644\layout LyX-Code
3645
3646this-example RELATIVE-OID ::= {
3647\layout LyX-Code
3648
3649 this-document assorted-examples(0) this-example(1) }
3650\layout Section
3651
3652Some of the ASN.1 String Types
3653\layout Subsection
3654
3655The IA5String type
3656\layout Standard
3657
3658This is essentially the ASCII, with 128 character codes available (7 lower
3659 bits of an 8-bit byte).
3660\layout Subsection
3661
3662The UTF8String type
3663\layout Standard
3664
3665This is the character string which encodes the full Unicode range (4 bytes)
3666 using multibyte character sequences.
3667\layout Subsection
3668
3669The NumericString type
3670\layout Standard
3671
3672This type represents the character string with the alphabet consisting of
3673 numbers (
3674\begin_inset Quotes sld
3675\end_inset
3676
36770
3678\begin_inset Quotes srd
3679\end_inset
3680
3681 to
3682\begin_inset Quotes sld
3683\end_inset
3684
36859
3686\begin_inset Quotes srd
3687\end_inset
3688
3689) and a space.
3690\layout Subsection
3691
3692The PrintableString type
3693\layout Standard
3694
3695The character string with the following alphabet: space,
3696\begin_inset Quotes sld
3697\end_inset
3698
3699
3700\series bold
3701'
3702\series default
3703
3704\begin_inset Quotes srd
3705\end_inset
3706
3707 (single quote),
3708\begin_inset Quotes sld
3709\end_inset
3710
3711
3712\series bold
3713(
3714\series default
3715
3716\begin_inset Quotes sld
3717\end_inset
3718
3719,
3720\begin_inset Quotes sld
3721\end_inset
3722
3723
3724\series bold
3725)
3726\series default
3727
3728\begin_inset Quotes srd
3729\end_inset
3730
3731,
3732\begin_inset Quotes sld
3733\end_inset
3734
3735
3736\series bold
3737+
3738\series default
3739
3740\begin_inset Quotes srd
3741\end_inset
3742
3743,
3744\begin_inset Quotes sld
3745\end_inset
3746
3747
3748\series bold
3749,
3750\series default
3751
3752\begin_inset Quotes srd
3753\end_inset
3754
3755 (comma),
3756\begin_inset Quotes sld
3757\end_inset
3758
3759
3760\series bold
3761-
3762\series default
3763
3764\begin_inset Quotes srd
3765\end_inset
3766
3767,
3768\begin_inset Quotes sld
3769\end_inset
3770
3771
3772\series bold
3773.
3774\series default
3775
3776\begin_inset Quotes srd
3777\end_inset
3778
3779,
3780\begin_inset Quotes sld
3781\end_inset
3782
3783
3784\series bold
3785/
3786\series default
3787
3788\begin_inset Quotes srd
3789\end_inset
3790
3791, digits (
3792\begin_inset Quotes sld
3793\end_inset
3794
37950
3796\begin_inset Quotes srd
3797\end_inset
3798
3799 to
3800\begin_inset Quotes sld
3801\end_inset
3802
38039
3804\begin_inset Quotes srd
3805\end_inset
3806
3807),
3808\begin_inset Quotes sld
3809\end_inset
3810
3811
3812\series bold
3813:
3814\series default
3815
3816\begin_inset Quotes srd
3817\end_inset
3818
3819,
3820\begin_inset Quotes sld
3821\end_inset
3822
3823
3824\series bold
3825=
3826\series default
3827
3828\begin_inset Quotes srd
3829\end_inset
3830
3831,
3832\begin_inset Quotes sld
3833\end_inset
3834
3835
3836\series bold
3837?
3838\series default
3839
3840\begin_inset Quotes srd
3841\end_inset
3842
3843, upper-case and lower-case letters (
3844\begin_inset Quotes sld
3845\end_inset
3846
3847A
3848\begin_inset Quotes srd
3849\end_inset
3850
3851 to
3852\begin_inset Quotes sld
3853\end_inset
3854
3855Z
3856\begin_inset Quotes srd
3857\end_inset
3858
3859 and
3860\begin_inset Quotes sld
3861\end_inset
3862
3863a
3864\begin_inset Quotes srd
3865\end_inset
3866
3867 to
3868\begin_inset Quotes sld
3869\end_inset
3870
3871z
3872\begin_inset Quotes srd
3873\end_inset
3874
3875).
3876\layout Subsection
3877
3878The VisibleString type
3879\layout Standard
3880
3881The character string with the alphabet which is more or less a subset of
3882 ASCII between the space and the
3883\begin_inset Quotes sld
3884\end_inset
3885
3886
3887\series bold
3888~
3889\series default
3890
3891\begin_inset Quotes srd
3892\end_inset
3893
3894 symbol (tilde).
3895\layout Standard
3896
3897Alternatively, the alphabet may be described as the PrintableString alphabet
3898 presented earlier, plus the following characters:
3899\begin_inset Quotes sld
3900\end_inset
3901
3902
3903\series bold
3904!
3905\series default
3906
3907\begin_inset Quotes srd
3908\end_inset
3909
3910,
3911\begin_inset Quotes sld
3912\end_inset
3913
3914
3915\series bold
3916
3917\begin_inset Quotes srd
3918\end_inset
3919
3920
3921\series default
3922
3923\begin_inset Quotes srd
3924\end_inset
3925
3926,
3927\begin_inset Quotes sld
3928\end_inset
3929
3930
3931\series bold
3932#
3933\series default
3934
3935\begin_inset Quotes srd
3936\end_inset
3937
3938,
3939\begin_inset Quotes sld
3940\end_inset
3941
3942
3943\series bold
3944$
3945\series default
3946
3947\begin_inset Quotes srd
3948\end_inset
3949
3950,
3951\begin_inset Quotes sld
3952\end_inset
3953
3954
3955\series bold
3956%
3957\series default
3958
3959\begin_inset Quotes srd
3960\end_inset
3961
3962,
3963\begin_inset Quotes sld
3964\end_inset
3965
3966
3967\series bold
3968&
3969\series default
3970
3971\begin_inset Quotes srd
3972\end_inset
3973
3974,
3975\begin_inset Quotes sld
3976\end_inset
3977
3978
3979\series bold
3980*
3981\series default
3982
3983\begin_inset Quotes srd
3984\end_inset
3985
3986,
3987\begin_inset Quotes sld
3988\end_inset
3989
3990
3991\series bold
3992;
3993\series default
3994
3995\begin_inset Quotes srd
3996\end_inset
3997
3998,
3999\begin_inset Quotes sld
4000\end_inset
4001
4002
4003\series bold
4004<
4005\series default
4006
4007\begin_inset Quotes srd
4008\end_inset
4009
4010,
4011\begin_inset Quotes sld
4012\end_inset
4013
4014
4015\series bold
4016>
4017\series default
4018
4019\begin_inset Quotes srd
4020\end_inset
4021
4022,
4023\begin_inset Quotes sld
4024\end_inset
4025
4026
4027\series bold
4028[
4029\series default
4030
4031\begin_inset Quotes srd
4032\end_inset
4033
4034,
4035\begin_inset Quotes sld
4036\end_inset
4037
4038
4039\series bold
4040
4041\backslash
4042
4043\series default
4044
4045\begin_inset Quotes srd
4046\end_inset
4047
4048,
4049\begin_inset Quotes sld
4050\end_inset
4051
4052
4053\series bold
4054]
4055\series default
4056
4057\begin_inset Quotes srd
4058\end_inset
4059
4060,
4061\begin_inset Quotes sld
4062\end_inset
4063
4064
4065\series bold
4066^
4067\series default
4068
4069\begin_inset Quotes srd
4070\end_inset
4071
4072,
4073\begin_inset Quotes sld
4074\end_inset
4075
4076
4077\series bold
4078_
4079\series default
4080
4081\begin_inset Quotes srd
4082\end_inset
4083
4084,
4085\begin_inset Quotes sld
4086\end_inset
4087
4088
4089\series bold
4090`
4091\series default
4092
4093\begin_inset Quotes srd
4094\end_inset
4095
4096 (single left quote),
4097\begin_inset Quotes sld
4098\end_inset
4099
4100
4101\series bold
4102{
4103\series default
4104
4105\begin_inset Quotes srd
4106\end_inset
4107
4108,
4109\begin_inset Quotes sld
4110\end_inset
4111
4112
4113\series bold
4114|
4115\series default
4116
4117\begin_inset Quotes srd
4118\end_inset
4119
4120,
4121\begin_inset Quotes sld
4122\end_inset
4123
4124
4125\series bold
4126}
4127\series default
4128
4129\begin_inset Quotes srd
4130\end_inset
4131
4132,
4133\begin_inset Quotes sld
4134\end_inset
4135
4136
4137\series bold
4138~
4139\series default
4140
4141\begin_inset Quotes srd
4142\end_inset
4143
4144.
4145\layout Section
4146
4147ASN.1 Constructed Types
4148\layout Subsection
4149
4150The SEQUENCE type
4151\layout Standard
4152
4153This is an ordered collection of other simple or constructed types.
4154 The SEQUENCE constructed type resembles the C
4155\begin_inset Quotes sld
4156\end_inset
4157
4158struct
4159\begin_inset Quotes srd
4160\end_inset
4161
4162 statement.
4163\layout LyX-Code
4164
4165Address ::= SEQUENCE {
4166\layout LyX-Code
4167
4168 -- The apartment number may be omitted
4169\layout LyX-Code
4170
4171 apartmentNumber NumericString OPTIONAL,
4172\layout LyX-Code
4173
4174 streetName PrintableString,
4175\layout LyX-Code
4176
4177 cityName PrintableString,
4178\layout LyX-Code
4179
4180 stateName PrintableString,
4181\layout LyX-Code
4182
4183 -- This one may be omitted too
4184\layout LyX-Code
4185
4186 zipNo NumericString OPTIONAL
4187\layout LyX-Code
4188
4189}
4190\layout Subsection
4191
4192The SET type
4193\layout Standard
4194
4195This is a collection of other simple or constructed types.
4196 Ordering is not important.
4197 The data may arrive in the order which is different from the order of specifica
4198tion.
4199 Data is encoded in the order not necessarily corresponding to the order
4200 of specification.
4201\layout Subsection
4202
4203The CHOICE type
4204\layout Standard
4205
4206This type is just a choice between the subtypes specified in it.
4207 The CHOICE type contains at most one of the subtypes specified, and it
4208 is always implicitly known which choice is being decoded or encoded.
4209 This one resembles the C
4210\begin_inset Quotes sld
4211\end_inset
4212
4213union
4214\begin_inset Quotes srd
4215\end_inset
4216
4217 statement.
4218\layout Standard
4219
4220The following type defines a response code, which may be either an integer
4221 code or a boolean
4222\begin_inset Quotes sld
4223\end_inset
4224
4225true
4226\begin_inset Quotes srd
4227\end_inset
4228
4229/
4230\begin_inset Quotes srd
4231\end_inset
4232
4233false
4234\begin_inset Quotes srd
4235\end_inset
4236
4237 code.
4238\layout LyX-Code
4239
4240ResponseCode ::= CHOICE {
4241\layout LyX-Code
4242
4243 intCode INTEGER,
4244\layout LyX-Code
4245
4246 boolCode BOOLEAN
4247\layout LyX-Code
4248
4249}
4250\layout LyX-Code
4251
4252\layout Subsection
4253
4254The SEQUENCE OF type
4255\layout Standard
4256
4257This one is the list (array) of simple or constructed types:
4258\layout LyX-Code
4259
4260-- Example 1
4261\layout LyX-Code
4262
4263ManyIntegers ::= SEQUENCE OF INTEGER
4264\layout LyX-Code
4265
4266
4267\layout LyX-Code
4268
4269-- Example 2
4270\layout LyX-Code
4271
4272ManyRectangles ::= SEQUENCE OF Rectangle
4273\layout LyX-Code
4274
4275
4276\layout LyX-Code
4277
4278-- More complex example:
4279\layout LyX-Code
4280
4281-- an array of structures defined in place.
4282\layout LyX-Code
4283
4284ManyCircles ::= SEQUENCE OF SEQUENCE {
4285\layout LyX-Code
4286
4287 radius INTEGER
4288\layout LyX-Code
4289
4290 }
4291\layout Subsection
4292
4293The SET OF type
4294\layout Standard
4295
4296The SET OF type models the bag of structures.
4297 It resembles the SEQUENCE OF type, but the order is not important: i.e.
4298 the elements may arrive in the order which is not necessarily the same
4299 as the in-memory order on the remote machines.
4300\layout LyX-Code
4301
4302-- A set of structures defined elsewhere
4303\layout LyX-Code
4304
4305SetOfApples :: SET OF Apple
4306\layout LyX-Code
4307
4308
4309\layout LyX-Code
4310
4311-- Set of integers encoding the kind of a fruit
4312\layout LyX-Code
4313
4314FruitBag ::= SET OF ENUMERATED { apple, orange }
Lev Walkin84291e02004-06-03 03:49:45 +00004315\layout Bibliography
Lev Walkin26587ab2004-08-23 15:12:04 +00004316\bibitem [ASN1C]{ASN1C}
4317
Lev Walkindee61782005-02-02 09:53:46 +00004318The Open Source ASN.1 Compiler.
Lev Walkin26587ab2004-08-23 15:12:04 +00004319
Lev Walkindee61782005-02-02 09:53:46 +00004320\begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c}
Lev Walkin26587ab2004-08-23 15:12:04 +00004321
4322\end_inset
4323
4324
4325\layout Bibliography
Lev Walkindba8ca02005-01-14 11:38:49 +00004326\bibitem [AONL]{AONL}
4327
4328Online ASN.1 Compiler.
4329
4330\begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c/asn1c.cgi}
4331
4332\end_inset
4333
4334
4335\layout Bibliography
Lev Walkin84291e02004-06-03 03:49:45 +00004336\bibitem [Dub00]{Dub00}
4337
Lev Walkina646ccb2004-10-20 15:48:55 +00004338Olivier Dubuisson ---
Lev Walkin84291e02004-06-03 03:49:45 +00004339\emph on
4340ASN.1 Communication between heterogeneous systems
4341\emph default
Lev Walkina646ccb2004-10-20 15:48:55 +00004342 --- Morgan Kaufmann Publishers, 2000.
Lev Walkin84291e02004-06-03 03:49:45 +00004343
4344\begin_inset LatexCommand \htmlurl{http://asn1.elibel.tm.fr/en/book/}
4345
4346\end_inset
4347
4348.
4349 ISBN:0-12-6333361-0.
4350\layout Bibliography
4351\bibitem [ITU-T/ASN.1]{ITU-T/ASN.1}
4352
4353ITU-T Study Group 17 -- Languages for Telecommunication Systems
4354\begin_inset LatexCommand \url{http://www.itu.int/ITU-T/studygroups/com17/languages/}
4355
4356\end_inset
4357
4358
4359\the_end