blob: 865d08b5977abc29ea1de6d609b04c7256f7bd06 [file] [log] [blame]
vlme18adea2004-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
vlmfcec8e52004-08-23 15:12:04 +00004\begin_preamble
5%\fancyhf{}
6%\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1\ sdf}{}}
7%\renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{\thesection.\ #1}}}
8%\fancyhead[LE,RO]{\thepage}
9%\fancyhead[LO]{\rightmark}
10%\fancyhead[RE]]{\leftmark}
11\usepackage{extramarks}
12\lhead{\firstxmark}
13\rfoot{\lastxmark}
14\end_preamble
vlme18adea2004-06-03 03:49:45 +000015\language english
16\inputencoding latin1
vlmfcec8e52004-08-23 15:12:04 +000017\fontscheme times
vlme18adea2004-06-03 03:49:45 +000018\graphics default
19\paperfontsize default
20\spacing single
21\papersize Default
22\paperpackage a4
23\use_geometry 0
24\use_amsmath 0
25\use_natbib 0
26\use_numerical_citations 0
27\paperorientation portrait
28\secnumdepth 3
29\tocdepth 3
30\paragraph_separation indent
31\defskip medskip
32\quotes_language swedish
33\quotes_times 2
34\papercolumns 1
vlmfcec8e52004-08-23 15:12:04 +000035\papersides 2
36\paperpagestyle fancy
vlme18adea2004-06-03 03:49:45 +000037
38\layout Title
39
vlm89d219b2004-09-08 03:01:06 +000040Using the Open ASN.1 Compiler
vlme18adea2004-06-03 03:49:45 +000041\layout Author
42
43Lev Walkin <
44\begin_inset LatexCommand \url{vlm@lionet.info}
45
46\end_inset
47
48>
49\layout Standard
50
51
vlmfcec8e52004-08-23 15:12:04 +000052\begin_inset ERT
53status Open
54
55\layout Standard
56
57\backslash
vlm68d43e92004-09-24 20:56:07 +000058extramarks{$Revision$ -- describes asn1c-0.9.6}{}
vlmfcec8e52004-08-23 15:12:04 +000059\end_inset
60
61
62\layout Standard
63
64
vlme18adea2004-06-03 03:49:45 +000065\begin_inset LatexCommand \tableofcontents{}
66
67\end_inset
68
69
vlmfcec8e52004-08-23 15:12:04 +000070\layout Standard
71
72
73\begin_inset ERT
74status Collapsed
75
76\layout Standard
77
78\backslash
79pagestyle{headings}
80\end_inset
81
82
vlmcaba97b2004-08-07 05:00:07 +000083\layout Part
84
85ASN.1 Basics
vlme18adea2004-06-03 03:49:45 +000086\layout Chapter
87
vlmcaba97b2004-08-07 05:00:07 +000088Abstract Syntax Notation: ASN.1
vlme18adea2004-06-03 03:49:45 +000089\layout Standard
90
91
92\emph on
93This chapter defines some basic ASN.1 concepts and describes several most
94 widely used types.
95 It is by no means an authoritative or complete reference.
96 For more complete ASN.1 description, please refer to Olivier Dubuisson's
97 book
98\begin_inset LatexCommand \cite{Dub00}
99
100\end_inset
101
vlmcaba97b2004-08-07 05:00:07 +0000102 or the ASN.1 body of standards itself
vlme18adea2004-06-03 03:49:45 +0000103\begin_inset LatexCommand \cite{ITU-T/ASN.1}
104
105\end_inset
106
107.
108\layout Standard
109
110The Abstract Syntax Notation One is used to formally describe the semantics
111 of data transmitted across the network.
112 Two communicating parties may have different formats of their native data
113 types (i.e.
114 number of bits in the integer type), thus it is important to have a way
115 to describe the data in a manner which is independent from the particular
116 machine's representation.
117 The ASN.1 specifications is used to achieve one or more of the following:
118\layout Itemize
119
120The specification expressed in the ASN.1 notation is a formal and precise
121 way to communicate the data semantics to human readers;
122\layout Itemize
123
124The ASN.1 specifications may be used as input for automatic compilers which
125 produce the code for some target language (C, C++, Java, etc) to encode
126 and decode the data according to some encoding rules (which are also defined
127 by the ASN.1 standard).
128\layout Standard
129
130Consider the following example:
131\layout LyX-Code
132
133Rectangle ::= SEQUENCE {
134\layout LyX-Code
135
136 height INTEGER,
137\layout LyX-Code
138
139 width INTEGER
140\layout LyX-Code
141
142}
143\layout Standard
144
145This ASN.1 specification describes a constructed type,
146\emph on
147Rectangle
148\emph default
149, containing two integer fields.
150 This specification may tell the reader that there is this kind of data
151 structure and that some entity may be prepared to send or receive it.
152 The question on
153\emph on
154how
155\emph default
156 that entity is going to send or receive the
157\emph on
158encoded data
159\emph default
160 is outside the scope of ASN.1.
161 For example, this data structure may be encoded according to some encoding
162 rules and sent to the destination using the TCP protocol.
163 The ASN.1 specifies several ways of encoding (or
164\begin_inset Quotes sld
165\end_inset
166
167serializing
168\begin_inset Quotes srd
169\end_inset
170
171, or
172\begin_inset Quotes sld
173\end_inset
174
175marshaling
176\begin_inset Quotes srd
177\end_inset
178
179) the data: BER, CER, DER and XER, some of them which will be described
180 later.
181\layout Standard
182
183The complete specification must be wrapped in a module, which looks like
184 this:
185\layout LyX-Code
186
187UsageExampleModule1
188\layout LyX-Code
189
190 { iso org(3) dod(6) internet(1) private(4)
191\layout LyX-Code
192
193 enterprise(1) spelio(9363) software(1)
194\layout LyX-Code
195
196 asn1c(5) docs(2) usage(1) 1 }
197\layout LyX-Code
198
vlmfcec8e52004-08-23 15:12:04 +0000199 DEFINITIONS AUTOMATIC TAGS ::=
vlme18adea2004-06-03 03:49:45 +0000200\layout LyX-Code
201
202BEGIN
203\layout LyX-Code
204
205
206\layout LyX-Code
207
208-- This is a comment which describes nothing.
209\layout LyX-Code
210
211Rectangle ::= SEQUENCE {
212\layout LyX-Code
213
214 height INTEGER, -- Height of the rectangle
215\layout LyX-Code
216
vlmfcec8e52004-08-23 15:12:04 +0000217 width INTEGER -- Width of the rectangle
vlme18adea2004-06-03 03:49:45 +0000218\layout LyX-Code
219
220}
221\layout LyX-Code
222
223
224\layout LyX-Code
225
226END
227\layout Standard
228
229The module header consists of module name (UsageExampleModule1), the module
vlmfcec8e52004-08-23 15:12:04 +0000230 object identifier ({...}), a keyword
vlme18adea2004-06-03 03:49:45 +0000231\begin_inset Quotes sld
232\end_inset
233
vlmfcec8e52004-08-23 15:12:04 +0000234DEFINITIONS
235\begin_inset Quotes srd
236\end_inset
237
238, a set of module flags (AUTOMATIC TAGS) and
239\begin_inset Quotes sld
240\end_inset
241
242::= BEGIN
vlme18adea2004-06-03 03:49:45 +0000243\begin_inset Quotes srd
244\end_inset
245
246.
247 The module ends with an
248\begin_inset Quotes sld
249\end_inset
250
251END
252\begin_inset Quotes srd
253\end_inset
254
255 statement.
256\layout Section
257
258Some of the ASN.1 Basic Types
259\layout Subsection
260
261The BOOLEAN type
262\layout Standard
263
264The BOOLEAN type models the simple binary TRUE/FALSE, YES/NO, ON/OFF or
265 a similar kind of two-way choice.
266\layout Subsection
267
268The INTEGER type
269\layout Standard
270
271The INTEGER type is a signed natural number type without any restrictions
272 on its size.
273 If the automatic checking on INTEGER value bounds are necessary, the subtype
274 constraints must be used.
275\layout LyX-Code
276
277SimpleInteger ::= INTEGER
278\layout LyX-Code
279
vlmfcec8e52004-08-23 15:12:04 +0000280
281\layout LyX-Code
282
vlme18adea2004-06-03 03:49:45 +0000283-- An integer with a very limited range
284\layout LyX-Code
285
vlmba56d852004-09-29 13:29:17 +0000286SmallPositiveInt ::= INTEGER (0..127)
vlme18adea2004-06-03 03:49:45 +0000287\layout LyX-Code
288
vlmfcec8e52004-08-23 15:12:04 +0000289
290\layout LyX-Code
291
vlme18adea2004-06-03 03:49:45 +0000292-- Integer, negative
293\layout LyX-Code
294
295NegativeInt ::= INTEGER (MIN..0)
296\layout Subsection
297
298The ENUMERATED type
299\layout Standard
300
301The ENUMERATED type is semantically equivalent to the INTEGER type with
302 some integer values explicitly named.
303\layout LyX-Code
304
305FruitId ::= ENUMERATED { apple(1), orange(2) }
306\layout LyX-Code
307
vlmfcec8e52004-08-23 15:12:04 +0000308
309\layout LyX-Code
310
vlme18adea2004-06-03 03:49:45 +0000311-- The numbers in braces are optional,
312\layout LyX-Code
313
vlmfcec8e52004-08-23 15:12:04 +0000314-- the enumeration can be performed
vlme18adea2004-06-03 03:49:45 +0000315\layout LyX-Code
316
317-- automatically by the compiler
318\layout LyX-Code
319
320ComputerOSType ::= ENUMERATED {
321\layout LyX-Code
322
323 FreeBSD, -- will be 0
324\layout LyX-Code
325
326 Windows, -- will be 1
327\layout LyX-Code
328
329 Solaris(5), -- will remain 5
330\layout LyX-Code
331
332 Linux, -- will be 6
333\layout LyX-Code
334
335 MacOS -- will be 7
336\layout LyX-Code
337
338}
339\layout Subsection
340
341The OCTET STRING type
342\layout Standard
343
344This type models the sequence of 8-bit bytes.
345 This may be used to transmit some opaque data or data serialized by other
346 types of encoders (i.e.
347 video file, photo picture, etc).
348\layout Subsection
349
350The OBJECT IDENTIFIER type
351\layout Standard
352
353The OBJECT IDENTIFIER is used to represent the unique identifier of any
354 object, starting from the very root of the registration tree.
355 If your organization needs to uniquely identify something (a router, a
356 room, a person, a standard, or whatever), you are encouraged to get your
357 own identification subtree at
358\begin_inset LatexCommand \htmlurl{http://www.iana.org/protocols/forms.htm}
359
360\end_inset
361
362.
363\layout Standard
364
365For example, the very first ASN.1 module in this document has the following
366 OBJECT IDENTIFIER: 1 3 6 1 4 1 9363 1 5 2 1 1.
367\layout LyX-Code
368
369ExampleOID ::= OBJECT IDENTIFIER
370\layout LyX-Code
371
vlmfcec8e52004-08-23 15:12:04 +0000372
373\layout LyX-Code
374
vlme18adea2004-06-03 03:49:45 +0000375usageExampleModule1-oid ExampleOID
376\layout LyX-Code
377
378 ::= { 1 3 6 1 4 1 9363 1 5 2 1 1 }
379\layout LyX-Code
380
vlmfcec8e52004-08-23 15:12:04 +0000381
382\layout LyX-Code
383
vlme18adea2004-06-03 03:49:45 +0000384-- An identifier of the Internet.
385\layout LyX-Code
386
387internet-id OBJECT IDENTIFIER
388\layout LyX-Code
389
390 ::= { iso(1) identified-organization(3)
391\layout LyX-Code
392
393 dod(6) internet(1) }
394\layout Standard
395
396As you see, names are optional.
397\layout Subsection
398
399The RELATIVE-OID type
400\layout Standard
401
402The RELATIVE-OID type has the semantics of a subtree of an OBJECT IDENTIFIER.
403 There may be no need to repeat the whole sequence of numbers from the root
404 of the registration tree where the only thing of interest is some of the
405 tree's subsequence.
406\layout LyX-Code
407
408this-document RELATIVE-OID ::= { docs(2) usage(1) }
409\layout LyX-Code
410
vlmfcec8e52004-08-23 15:12:04 +0000411
412\layout LyX-Code
413
vlme18adea2004-06-03 03:49:45 +0000414this-example RELATIVE-OID ::= {
415\layout LyX-Code
416
417 this-document assorted-examples(0) this-example(1) }
418\layout Section
419
420Some of the ASN.1 String Types
421\layout Subsection
422
423The IA5String type
424\layout Standard
425
426This is essentially the ASCII, with 128 character codes available (7 lower
vlmfcec8e52004-08-23 15:12:04 +0000427 bits of an 8-bit byte).
vlme18adea2004-06-03 03:49:45 +0000428\layout Subsection
429
430The UTF8String type
431\layout Standard
432
433This is the character string which encodes the full Unicode range (4 bytes)
434 using multibyte character sequences.
435\layout Subsection
436
437The NumericString type
438\layout Standard
439
440This type represents the character string with the alphabet consisting of
441 numbers (
442\begin_inset Quotes sld
443\end_inset
444
4450
446\begin_inset Quotes srd
447\end_inset
448
449 to
450\begin_inset Quotes sld
451\end_inset
452
4539
454\begin_inset Quotes srd
455\end_inset
456
457) and a space.
458\layout Subsection
459
460The PrintableString type
461\layout Standard
462
463The character string with the following alphabet: space,
464\begin_inset Quotes sld
465\end_inset
466
467
468\series bold
469'
470\series default
471
472\begin_inset Quotes srd
473\end_inset
474
475 (single quote),
476\begin_inset Quotes sld
477\end_inset
478
479
480\series bold
481(
482\series default
483
484\begin_inset Quotes sld
485\end_inset
486
487,
488\begin_inset Quotes sld
489\end_inset
490
491
492\series bold
493)
494\series default
495
496\begin_inset Quotes srd
497\end_inset
498
499,
500\begin_inset Quotes sld
501\end_inset
502
503
504\series bold
505+
506\series default
507
508\begin_inset Quotes srd
509\end_inset
510
511,
512\begin_inset Quotes sld
513\end_inset
514
vlmba56d852004-09-29 13:29:17 +0000515
516\series bold
vlme18adea2004-06-03 03:49:45 +0000517,
vlmba56d852004-09-29 13:29:17 +0000518\series default
519
vlme18adea2004-06-03 03:49:45 +0000520\begin_inset Quotes srd
521\end_inset
522
523 (comma),
524\begin_inset Quotes sld
525\end_inset
526
527
528\series bold
529-
530\series default
531
532\begin_inset Quotes srd
533\end_inset
534
535,
536\begin_inset Quotes sld
537\end_inset
538
539
540\series bold
541.
542\series default
543
544\begin_inset Quotes srd
545\end_inset
546
547,
548\begin_inset Quotes sld
549\end_inset
550
551
552\series bold
553/
554\series default
555
556\begin_inset Quotes srd
557\end_inset
558
559, digits (
560\begin_inset Quotes sld
561\end_inset
562
5630
564\begin_inset Quotes srd
565\end_inset
566
567 to
568\begin_inset Quotes sld
569\end_inset
570
5719
572\begin_inset Quotes srd
573\end_inset
574
575),
576\begin_inset Quotes sld
577\end_inset
578
579
580\series bold
581:
582\series default
583
584\begin_inset Quotes srd
585\end_inset
586
587,
588\begin_inset Quotes sld
589\end_inset
590
591
592\series bold
593=
594\series default
595
596\begin_inset Quotes srd
597\end_inset
598
599,
600\begin_inset Quotes sld
601\end_inset
602
603
604\series bold
605?
606\series default
607
608\begin_inset Quotes srd
609\end_inset
610
611, upper-case and lower-case letters (
612\begin_inset Quotes sld
613\end_inset
614
615A
616\begin_inset Quotes srd
617\end_inset
618
619 to
620\begin_inset Quotes sld
621\end_inset
622
623Z
624\begin_inset Quotes srd
625\end_inset
626
627 and
628\begin_inset Quotes sld
629\end_inset
630
631a
632\begin_inset Quotes srd
633\end_inset
634
635 to
636\begin_inset Quotes sld
637\end_inset
638
639z
640\begin_inset Quotes srd
641\end_inset
642
vlmba56d852004-09-29 13:29:17 +0000643).
vlme18adea2004-06-03 03:49:45 +0000644\layout Subsection
645
646The VisibleString type
647\layout Standard
648
649The character string with the alphabet which is more or less a subset of
vlmba56d852004-09-29 13:29:17 +0000650 ASCII between the space and the
vlme18adea2004-06-03 03:49:45 +0000651\begin_inset Quotes sld
652\end_inset
653
vlmfcec8e52004-08-23 15:12:04 +0000654
655\series bold
vlme18adea2004-06-03 03:49:45 +0000656~
vlmfcec8e52004-08-23 15:12:04 +0000657\series default
658
vlme18adea2004-06-03 03:49:45 +0000659\begin_inset Quotes srd
660\end_inset
661
vlmba56d852004-09-29 13:29:17 +0000662 symbol (tilde).
663\layout Standard
664
665Alternatively, the alphabet may be described as the PrintableString alphabet
vlmfcec8e52004-08-23 15:12:04 +0000666 presented earlier, plus the following characters:
vlme18adea2004-06-03 03:49:45 +0000667\begin_inset Quotes sld
668\end_inset
669
670
671\series bold
672!
673\series default
674
675\begin_inset Quotes srd
676\end_inset
677
678,
679\begin_inset Quotes sld
680\end_inset
681
682
683\series bold
684
685\begin_inset Quotes srd
686\end_inset
687
688
689\series default
690
691\begin_inset Quotes srd
692\end_inset
693
694,
695\begin_inset Quotes sld
696\end_inset
697
698
699\series bold
700#
701\series default
702
703\begin_inset Quotes srd
704\end_inset
705
706,
707\begin_inset Quotes sld
708\end_inset
709
710
711\series bold
712$
713\series default
714
715\begin_inset Quotes srd
716\end_inset
717
718,
719\begin_inset Quotes sld
720\end_inset
721
722
723\series bold
724%
725\series default
726
727\begin_inset Quotes srd
728\end_inset
729
730,
731\begin_inset Quotes sld
732\end_inset
733
734
735\series bold
736&
737\series default
738
739\begin_inset Quotes srd
740\end_inset
741
742,
743\begin_inset Quotes sld
744\end_inset
745
746
747\series bold
748*
749\series default
750
751\begin_inset Quotes srd
752\end_inset
753
754,
755\begin_inset Quotes sld
756\end_inset
757
758
759\series bold
760;
761\series default
762
763\begin_inset Quotes srd
764\end_inset
765
766,
767\begin_inset Quotes sld
768\end_inset
769
770
771\series bold
772<
773\series default
774
775\begin_inset Quotes srd
776\end_inset
777
778,
779\begin_inset Quotes sld
780\end_inset
781
782
783\series bold
784>
785\series default
786
787\begin_inset Quotes srd
788\end_inset
789
790,
791\begin_inset Quotes sld
792\end_inset
793
794
795\series bold
796[
797\series default
798
799\begin_inset Quotes srd
800\end_inset
801
802,
803\begin_inset Quotes sld
804\end_inset
805
806
807\series bold
808
809\backslash
810
811\series default
812
813\begin_inset Quotes srd
814\end_inset
815
816,
817\begin_inset Quotes sld
818\end_inset
819
820
821\series bold
822]
823\series default
824
825\begin_inset Quotes srd
826\end_inset
827
828,
829\begin_inset Quotes sld
830\end_inset
831
832
833\series bold
834^
835\series default
836
837\begin_inset Quotes srd
838\end_inset
839
840,
841\begin_inset Quotes sld
842\end_inset
843
844
845\series bold
846_
847\series default
848
849\begin_inset Quotes srd
850\end_inset
851
852,
853\begin_inset Quotes sld
854\end_inset
855
856
857\series bold
858`
859\series default
860
861\begin_inset Quotes srd
862\end_inset
863
864 (single left quote),
865\begin_inset Quotes sld
866\end_inset
867
868
869\series bold
870{
871\series default
872
873\begin_inset Quotes srd
874\end_inset
875
876,
877\begin_inset Quotes sld
878\end_inset
879
880
881\series bold
882|
883\series default
884
885\begin_inset Quotes srd
886\end_inset
887
888,
889\begin_inset Quotes sld
890\end_inset
891
892
893\series bold
894}
895\series default
896
897\begin_inset Quotes srd
898\end_inset
899
900,
901\begin_inset Quotes sld
902\end_inset
903
vlmfcec8e52004-08-23 15:12:04 +0000904
905\series bold
vlme18adea2004-06-03 03:49:45 +0000906~
vlmfcec8e52004-08-23 15:12:04 +0000907\series default
908
vlme18adea2004-06-03 03:49:45 +0000909\begin_inset Quotes srd
910\end_inset
911
912.
913\layout Section
914
915ASN.1 Constructed Types
916\layout Subsection
917
918The SEQUENCE type
919\layout Standard
920
921This is an ordered collection of other simple or constructed types.
922 The SEQUENCE constructed type resembles the C
923\begin_inset Quotes sld
924\end_inset
925
926struct
927\begin_inset Quotes srd
928\end_inset
929
930 statement.
931\layout LyX-Code
932
933Address ::= SEQUENCE {
934\layout LyX-Code
935
936 -- The apartment number may be omitted
937\layout LyX-Code
938
939 apartmentNumber NumericString OPTIONAL,
940\layout LyX-Code
941
942 streetName PrintableString,
943\layout LyX-Code
944
945 cityName PrintableString,
946\layout LyX-Code
947
948 stateName PrintableString,
949\layout LyX-Code
950
951 -- This one may be omitted too
952\layout LyX-Code
953
954 zipNo NumericString OPTIONAL
955\layout LyX-Code
956
957}
958\layout Subsection
959
960The SET type
961\layout Standard
962
963This is a collection of other simple or constructed types.
964 Ordering is not important.
965 The data may arrive in the order which is different from the order of specifica
966tion.
967 Data is encoded in the order not necessarily corresponding to the order
968 of specification.
969\layout Subsection
970
971The CHOICE type
972\layout Standard
973
974This type is just a choice between the subtypes specified in it.
975 The CHOICE type contains at most one of the subtypes specified, and it
976 is always implicitly known which choice is being decoded or encoded.
977 This one resembles the C
978\begin_inset Quotes sld
979\end_inset
980
981union
982\begin_inset Quotes srd
983\end_inset
984
985 statement.
986\layout Standard
987
988The following type defines a response code, which may be either an integer
989 code or a boolean
990\begin_inset Quotes sld
991\end_inset
992
993true
994\begin_inset Quotes srd
995\end_inset
996
997/
998\begin_inset Quotes srd
999\end_inset
1000
1001false
1002\begin_inset Quotes srd
1003\end_inset
1004
1005 code.
1006\layout LyX-Code
1007
1008ResponseCode ::= CHOICE {
1009\layout LyX-Code
1010
1011 intCode INTEGER,
1012\layout LyX-Code
1013
1014 boolCode BOOLEAN
1015\layout LyX-Code
1016
1017}
1018\layout LyX-Code
1019
1020\layout Subsection
1021
1022The SEQUENCE OF type
1023\layout Standard
1024
1025This one is the list (array) of simple or constructed types:
1026\layout LyX-Code
1027
1028-- Example 1
1029\layout LyX-Code
1030
1031ManyIntegers ::= SEQUENCE OF INTEGER
1032\layout LyX-Code
1033
vlmfcec8e52004-08-23 15:12:04 +00001034
1035\layout LyX-Code
1036
vlme18adea2004-06-03 03:49:45 +00001037-- Example 2
1038\layout LyX-Code
1039
1040ManyRectangles ::= SEQUENCE OF Rectangle
1041\layout LyX-Code
1042
vlmfcec8e52004-08-23 15:12:04 +00001043
1044\layout LyX-Code
1045
vlme18adea2004-06-03 03:49:45 +00001046-- More complex example:
1047\layout LyX-Code
1048
1049-- an array of structures defined in place.
1050\layout LyX-Code
1051
1052ManyCircles ::= SEQUENCE OF SEQUENCE {
1053\layout LyX-Code
1054
1055 radius INTEGER
1056\layout LyX-Code
1057
1058 }
1059\layout Subsection
1060
1061The SET OF type
1062\layout Standard
1063
1064The SET OF type models the bag of structures.
1065 It resembles the SEQUENCE OF type, but the order is not important: i.e.
1066 the elements may arrive in the order which is not necessarily the same
1067 as the in-memory order on the remote machines.
1068\layout LyX-Code
1069
1070-- A set of structures defined elsewhere
1071\layout LyX-Code
1072
1073SetOfApples :: SET OF Apple
1074\layout LyX-Code
1075
vlmfcec8e52004-08-23 15:12:04 +00001076
1077\layout LyX-Code
1078
vlme18adea2004-06-03 03:49:45 +00001079-- Set of integers encoding the kind of a fruit
1080\layout LyX-Code
1081
1082FruitBag ::= SET OF ENUMERATED { apple, orange }
vlmcaba97b2004-08-07 05:00:07 +00001083\layout Part
1084
1085Using the ASN.1 Compiler
vlme18adea2004-06-03 03:49:45 +00001086\layout Chapter
1087
vlmcaba97b2004-08-07 05:00:07 +00001088Introduction to the ASN.1 Compiler
vlme18adea2004-06-03 03:49:45 +00001089\layout Standard
1090
1091The purpose of the ASN.1 compiler, of which this document is part, is to
1092 convert the ASN.1 specifications to some other target language (currently,
1093 only C is supported
1094\begin_inset Foot
1095collapsed false
1096
1097\layout Standard
1098
1099C++ is
1100\begin_inset Quotes sld
1101\end_inset
1102
1103supported
1104\begin_inset Quotes srd
1105\end_inset
1106
vlmfcec8e52004-08-23 15:12:04 +00001107 too, as long as an class-based approach is not a definitive factor.
vlme18adea2004-06-03 03:49:45 +00001108\end_inset
1109
1110).
1111 The compiler reads the specification and emits a series of target language
1112 structures and surrounding maintenance code.
1113 For example, the C structure which may be created by compiler to represent
1114 the simple
1115\emph on
1116Rectangle
1117\emph default
1118 specification defined earlier in this document, may look like this
1119\begin_inset Foot
1120collapsed false
1121
1122\layout Standard
1123
1124
1125\emph on
vlm03af0f02004-09-14 12:48:17 +00001126-fnative-types
vlme18adea2004-06-03 03:49:45 +00001127\emph default
1128 compiler option is used to produce basic C
1129\emph on
1130int
1131\emph default
vlmfcec8e52004-08-23 15:12:04 +00001132 types instead of infinite width INTEGER_t structures.
1133 See Table
1134\begin_inset LatexCommand \vref{cap:asn1c-cmdopts}
1135
1136\end_inset
1137
1138.
vlme18adea2004-06-03 03:49:45 +00001139\end_inset
1140
1141:
1142\layout LyX-Code
1143
1144typedef struct Rectangle_s {
1145\layout LyX-Code
1146
1147 int height;
1148\layout LyX-Code
1149
1150 int width;
1151\layout LyX-Code
1152
1153} Rectangle_t;
1154\layout Standard
1155
1156This would not be of much value for such a simple specification, so the
1157 compiler goes further and actually produces the code which fills in this
vlmfcec8e52004-08-23 15:12:04 +00001158 structure by parsing the opaque binary
vlme18adea2004-06-03 03:49:45 +00001159\begin_inset Foot
vlmfcec8e52004-08-23 15:12:04 +00001160collapsed true
vlme18adea2004-06-03 03:49:45 +00001161
1162\layout Standard
1163
1164BER, CER and DER encodings are binary.
1165 However, the XER encoding is text (XML) based.
1166\end_inset
1167
1168 data provided in some buffer.
1169 It also produces the code that takes this structure as an argument and
1170 performs structure serialization by emitting a series of bytes.
vlmfcec8e52004-08-23 15:12:04 +00001171\layout Chapter
vlme18adea2004-06-03 03:49:45 +00001172
1173Quick start
1174\layout Standard
1175
vlmfcec8e52004-08-23 15:12:04 +00001176After building and installing the compiler, the
1177\emph on
1178asn1c
1179\begin_inset Foot
1180collapsed false
1181
1182\layout Standard
1183
1184The 1 symbol in asn
1185\series bold
11861
1187\series default
1188c is a digit, not an
1189\begin_inset Quotes sld
1190\end_inset
1191
1192ell
1193\begin_inset Quotes srd
1194\end_inset
1195
1196 letter.
1197\end_inset
1198
1199
1200\emph default
1201 command may be used to compile the ASN.1 specification
vlme18adea2004-06-03 03:49:45 +00001202\begin_inset Foot
1203collapsed false
1204
1205\layout Standard
1206
1207This is probably
1208\series bold
1209not
1210\series default
1211 what you want to try out right now -- read through the rest of this chapter
vlmfcec8e52004-08-23 15:12:04 +00001212 to find out about
1213\series bold
1214-P
1215\series default
1216 and
1217\series bold
1218-R
1219\series default
1220 options.
vlme18adea2004-06-03 03:49:45 +00001221\end_inset
1222
1223:
1224\layout LyX-Code
1225
1226asn1c
1227\emph on
1228<spec.asn1>
1229\layout Standard
1230
vlmfcec8e52004-08-23 15:12:04 +00001231If several specifications contain interdependencies, all of the files must
1232 be specified altogether:
vlme18adea2004-06-03 03:49:45 +00001233\layout LyX-Code
1234
1235asn1c
1236\emph on
1237<spec1.asn1> <spec2.asn1> ...
1238\layout Standard
1239
vlmfcec8e52004-08-23 15:12:04 +00001240The compiler
1241\series bold
1242-E
1243\series default
1244 and
1245\series bold
1246-EF
1247\series default
1248 options are used for testing the parser and the semantic fixer, respectively.
1249 These options will instruct the compiler to dump out the parsed (and fixed,
1250 if
1251\series bold
1252-F
1253\series default
1254 is involved) ASN.1 specification as it was "understood" by the compiler.
1255 It might be useful to check whether a particular syntactic construction
vlme18adea2004-06-03 03:49:45 +00001256 is properly supported by the compiler.
1257\layout LyX-Code
1258
vlmfcec8e52004-08-23 15:12:04 +00001259asn1c
1260\series bold
1261-EF
1262\series default
1263
vlme18adea2004-06-03 03:49:45 +00001264\emph on
1265<spec-to-test.asn1>
1266\layout Standard
1267
vlmfcec8e52004-08-23 15:12:04 +00001268The
1269\series bold
1270-P
1271\series default
1272 option is used to dump the compiled output on the screen instead of creating
1273 a bunch of .c and .h files on disk in the current directory.
1274 You would probably want to start with
1275\series bold
1276-P
1277\series default
1278 option instead of creating a mess in your current directory.
1279 Another option,
1280\series bold
1281-R
1282\series default
1283, asks compiler to only generate the files which need to be generated, and
1284 supress linking in the numerous support files.
1285\layout Standard
1286
1287Print the compiled output instead of creating multiple source files:
1288\layout LyX-Code
1289
1290asn1c
1291\series bold
1292-P
1293\series default
1294
1295\emph on
1296<spec-to-compile-and-print.asn1>
1297\layout LyX-Code
1298
1299\layout Chapter
1300
1301Using the ASN.1 Compiler
vlme18adea2004-06-03 03:49:45 +00001302\layout Section
1303
vlmfcec8e52004-08-23 15:12:04 +00001304Command-line options
1305\layout Standard
1306
1307The Table
1308\begin_inset LatexCommand \vref{cap:asn1c-cmdopts}
1309
1310\end_inset
1311
1312 summarizes various options affecting the compiler's behavior.
1313\layout Standard
1314
1315
1316\begin_inset Float table
1317wide false
vlm12c8f692004-09-06 08:07:29 +00001318collapsed false
vlmfcec8e52004-08-23 15:12:04 +00001319
1320\layout Standard
1321
1322
1323\begin_inset Tabular
vlmbfc49bd2004-09-26 13:13:13 +00001324<lyxtabular version="3" rows="21" columns="2">
vlmfcec8e52004-08-23 15:12:04 +00001325<features>
1326<column alignment="left" valignment="top" leftline="true" width="0">
1327<column alignment="block" valignment="top" leftline="true" rightline="true" width="3in">
1328<row topline="true" bottomline="true">
1329<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1330\begin_inset Text
1331
1332\layout Standard
1333
1334
1335\series bold
1336Overall Options
1337\end_inset
1338</cell>
1339<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1340\begin_inset Text
1341
1342\layout Standard
1343
1344
1345\series bold
1346Description
1347\end_inset
1348</cell>
1349</row>
1350<row topline="true">
1351<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1352\begin_inset Text
1353
1354\layout Standard
1355
1356-E
1357\end_inset
1358</cell>
1359<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1360\begin_inset Text
1361
1362\layout Standard
1363
1364
1365\size small
1366Stop after the parsing stage and print the reconstructed ASN.1 specification
1367 code to the standard output.
1368\end_inset
1369</cell>
1370</row>
1371<row topline="true">
1372<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1373\begin_inset Text
1374
1375\layout Standard
1376
1377-F
1378\end_inset
1379</cell>
1380<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1381\begin_inset Text
1382
1383\layout Standard
1384
1385
1386\size small
1387Used together with -E, instructs the compiler to stop after the ASN.1 syntax
1388 tree fixing stage and dump the reconstructed ASN.1 specification to the
1389 standard output.
1390\end_inset
1391</cell>
1392</row>
1393<row topline="true">
1394<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1395\begin_inset Text
1396
1397\layout Standard
1398
1399-P
1400\end_inset
1401</cell>
1402<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1403\begin_inset Text
1404
1405\layout Standard
1406
1407
1408\size small
1409Dump the compiled output to the standard output instead of cre- ating the
1410 target language files on disk.
1411\end_inset
1412</cell>
1413</row>
1414<row topline="true">
1415<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1416\begin_inset Text
1417
1418\layout Standard
1419
1420-R
1421\end_inset
1422</cell>
1423<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1424\begin_inset Text
1425
1426\layout Standard
1427
1428
1429\size small
1430Restrict the compiler to generate only the ASN.1 tables, omit- ting the usual
1431 support code.
1432\end_inset
1433</cell>
1434</row>
vlm68d43e92004-09-24 20:56:07 +00001435<row topline="true" bottomline="true">
vlmfcec8e52004-08-23 15:12:04 +00001436<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1437\begin_inset Text
1438
1439\layout Standard
1440
1441-S
1442\emph on
1443<directory>
1444\end_inset
1445</cell>
1446<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1447\begin_inset Text
1448
1449\layout Standard
1450
1451
1452\size small
1453Use the specified directory with ASN.1 skeleton files.
1454\end_inset
1455</cell>
1456</row>
vlmfcec8e52004-08-23 15:12:04 +00001457<row topline="true">
1458<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1459\begin_inset Text
1460
1461\layout Standard
1462
1463
1464\series bold
1465Warning Options
1466\end_inset
1467</cell>
1468<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1469\begin_inset Text
1470
1471\layout Standard
1472
1473
1474\series bold
1475Description
1476\end_inset
1477</cell>
1478</row>
1479<row topline="true">
1480<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1481\begin_inset Text
1482
1483\layout Standard
1484
1485-Werror
1486\end_inset
1487</cell>
1488<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1489\begin_inset Text
1490
1491\layout Standard
1492
1493
1494\size small
1495Treat warnings as errors; abort if any warning is produced.
1496\end_inset
1497</cell>
1498</row>
1499<row topline="true">
1500<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1501\begin_inset Text
1502
1503\layout Standard
1504
1505-Wdebug-lexer
1506\end_inset
1507</cell>
1508<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1509\begin_inset Text
1510
1511\layout Standard
1512
1513
1514\size small
1515Enable lexer debugging during the ASN.1 parsing stage.
1516\end_inset
1517</cell>
1518</row>
1519<row topline="true">
1520<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1521\begin_inset Text
1522
1523\layout Standard
1524
1525-Wdebug-fixer
1526\end_inset
1527</cell>
1528<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1529\begin_inset Text
1530
1531\layout Standard
1532
1533
1534\size small
1535 Enable ASN.1 syntax tree fixer debugging during the fixing stage.
1536\end_inset
1537</cell>
1538</row>
1539<row topline="true" bottomline="true">
1540<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1541\begin_inset Text
1542
1543\layout Standard
1544
1545-Wdebug-compiler
1546\end_inset
1547</cell>
1548<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1549\begin_inset Text
1550
1551\layout Standard
1552
1553
1554\size small
1555Enable debugging during the actual compile time.
1556\end_inset
1557</cell>
1558</row>
1559<row topline="true">
1560<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1561\begin_inset Text
1562
1563\layout Standard
1564
1565
1566\series bold
1567Language Options
1568\end_inset
1569</cell>
1570<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1571\begin_inset Text
1572
1573\layout Standard
1574
1575
1576\series bold
1577Description
1578\end_inset
1579</cell>
1580</row>
1581<row topline="true">
1582<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1583\begin_inset Text
1584
1585\layout Standard
1586
vlm12c8f692004-09-06 08:07:29 +00001587-fall-defs-global
1588\end_inset
1589</cell>
1590<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1591\begin_inset Text
1592
1593\layout Standard
1594
vlmba56d852004-09-29 13:29:17 +00001595Normally the compiler hides the definitions (asn_DEF_xxx) of the inner structure
1596 elements (members of SEQUENCE, SET and other types).
vlm12c8f692004-09-06 08:07:29 +00001597 This option makes all such definitions global.
vlmba56d852004-09-29 13:29:17 +00001598 Enabling this option may pollute the namespace by making lots of asn_DEF_xxx
vlm12c8f692004-09-06 08:07:29 +00001599 structures globally visible, but will allow you to manipulate (encode and
1600 decode) the individual members of any complex ASN.1 structure.
1601\end_inset
1602</cell>
1603</row>
1604<row topline="true">
1605<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1606\begin_inset Text
1607
1608\layout Standard
1609
vlmfcec8e52004-08-23 15:12:04 +00001610-fbless-SIZE
1611\end_inset
1612</cell>
1613<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1614\begin_inset Text
1615
1616\layout Standard
1617
1618
1619\size small
1620Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which
1621 this constraint is normally prohibited by the standard.
1622 This is a violation of an ASN.1 standard and compiler may fail to produce
1623 the meaningful code.
1624\end_inset
1625</cell>
1626</row>
1627<row topline="true">
1628<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1629\begin_inset Text
1630
1631\layout Standard
1632
vlm03af0f02004-09-14 12:48:17 +00001633-fnative-types
vlmfcec8e52004-08-23 15:12:04 +00001634\end_inset
1635</cell>
1636<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1637\begin_inset Text
1638
1639\layout Standard
1640
1641
1642\size small
vlm03af0f02004-09-14 12:48:17 +00001643Use the native machine's data types (int, double) whenever possible, instead
1644 of the compound ASN.1 INTEGER_t, ENUMERATED_t and REAL_t types.
vlmfcec8e52004-08-23 15:12:04 +00001645
1646\end_inset
1647</cell>
1648</row>
1649<row topline="true">
1650<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651\begin_inset Text
1652
1653\layout Standard
1654
vlmbfc49bd2004-09-26 13:13:13 +00001655-fno-constraints
1656\end_inset
1657</cell>
1658<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1659\begin_inset Text
1660
1661\layout Standard
1662
1663Do not generate ASN.1 subtype constraint checking code.
1664 This may make a shorter executable.
1665\end_inset
1666</cell>
1667</row>
1668<row topline="true">
1669<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1670\begin_inset Text
1671
1672\layout Standard
1673
vlmfcec8e52004-08-23 15:12:04 +00001674-funnamed-unions
1675\end_inset
1676</cell>
1677<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1678\begin_inset Text
1679
1680\layout Standard
1681
1682
1683\size small
1684Enable unnamed unions in the definitions of target language's structures.
1685\end_inset
1686</cell>
1687</row>
1688<row topline="true" bottomline="true">
1689<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1690\begin_inset Text
1691
1692\layout Standard
1693
1694-ftypes88
1695\end_inset
1696</cell>
1697<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1698\begin_inset Text
1699
1700\layout Standard
1701
1702
1703\size small
1704Use only ASN.1:1988 embedded types.
1705\end_inset
1706</cell>
1707</row>
1708<row topline="true">
1709<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710\begin_inset Text
1711
1712\layout Standard
1713
1714
1715\series bold
1716Output Options
1717\end_inset
1718</cell>
1719<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1720\begin_inset Text
1721
1722\layout Standard
1723
1724
1725\series bold
1726Description
1727\end_inset
1728</cell>
1729</row>
1730<row topline="true">
1731<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1732\begin_inset Text
1733
1734\layout Standard
1735
1736-print-constraints
1737\end_inset
1738</cell>
1739<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1740\begin_inset Text
1741
1742\layout Standard
1743
1744
1745\size small
1746When -EF are also specified, this option forces the compiler to explain
1747 its internal understanding of subtype constraints.
1748\end_inset
1749</cell>
1750</row>
1751<row topline="true" bottomline="true">
1752<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1753\begin_inset Text
1754
1755\layout Standard
1756
1757-print-lines
1758\end_inset
1759</cell>
1760<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1761\begin_inset Text
1762
1763\layout Standard
1764
1765
1766\size small
1767Generate "-- #line" comments in -E output.
1768\end_inset
1769</cell>
1770</row>
1771</lyxtabular>
1772
1773\end_inset
1774
1775
1776\layout Caption
1777
1778
1779\begin_inset LatexCommand \label{cap:asn1c-cmdopts}
1780
1781\end_inset
1782
1783The list of asn1c command line options
1784\end_inset
1785
1786
1787\layout Section
vlme18adea2004-06-03 03:49:45 +00001788
1789Recognizing compiler output
1790\layout Standard
1791
1792After compiling, the following entities will be created in your current
1793 directory:
1794\layout Itemize
1795
1796A set of .c and .h files, generally a single pair for each type defined in
1797 the ASN.1 specifications.
1798 These files will be named similarly to the ASN.1 types (
1799\emph on
1800Rectangle.c
1801\emph default
1802 and
1803\emph on
1804Rectangle.h
1805\emph default
1806 for the specification defined in the beginning of this document).
1807\layout Itemize
1808
1809A set of helper .c and .h files which contain generic encoders, decoders and
1810 other useful routines.
vlmfcec8e52004-08-23 15:12:04 +00001811 There will be quite a few of them, some of them even are not always necessary,
1812 but the overall amount of code after compiling will be rather small anyway.
vlme18adea2004-06-03 03:49:45 +00001813\layout Standard
1814
1815It is your responsibility to create .c file with the
1816\emph on
1817 int main()
1818\emph default
1819 routine and the Makefile (if needed).
1820 Compiler helps you with the latter by creating the Makefile.am.sample, containing
1821 the skeleton definition for the automake, should you want to use autotools.
1822\layout Standard
1823
1824In other words, after compiling the Rectangle module, you have the following
1825 set of files: { Makefile.am.sample, Rectangle.c, Rectangle.h,
1826\series bold
1827\SpecialChar \ldots{}
1828
1829\series default
1830 }, where
1831\series bold
1832
1833\begin_inset Quotes sld
1834\end_inset
1835
1836\SpecialChar \ldots{}
1837
1838\begin_inset Quotes srd
1839\end_inset
1840
1841
1842\series default
1843 stands for the set of additional
1844\begin_inset Quotes sld
1845\end_inset
1846
1847helper
1848\begin_inset Quotes srd
1849\end_inset
1850
1851 files created by the compiler.
1852 If you add the simple file with the
1853\emph on
1854int main()
1855\emph default
1856 routine, it would even be possible to compile everything with the single
1857 instruction:
1858\layout LyX-Code
1859
1860cc -o rectangle *.c # It could be
1861\emph on
1862that
1863\emph default
1864 simple
1865\begin_inset Foot
1866collapsed false
1867
1868\layout Standard
1869
1870Provided that you've also created a .c file with the
1871\emph on
1872int main()
1873\emph default
1874 routine.
1875\end_inset
1876
1877
vlmfcec8e52004-08-23 15:12:04 +00001878\layout Section
vlme18adea2004-06-03 03:49:45 +00001879
1880Invoking the ASN.1 helper code from the application
1881\layout Standard
1882
vlmfcec8e52004-08-23 15:12:04 +00001883First of all, you should to include one or more header files into your applicati
1884on.
1885 For our Rectangle module, including the Rectangle.h file is enough:
vlme18adea2004-06-03 03:49:45 +00001886\layout LyX-Code
1887
1888#include <Rectangle.h>
1889\layout Standard
1890
1891The header files defines the C structure corresponding to the ASN.1 definition
1892 of a rectangle and the declaration of the ASN.1 type descriptor, which is
1893 used as an argument to most of the functions provided by the ASN.1 module.
1894 For example, here is the code which frees the Rectangle_t structure:
1895\layout LyX-Code
1896
vlmfcec8e52004-08-23 15:12:04 +00001897Rectangle_t *rect = ...;
1898\layout LyX-Code
1899
1900
vlme18adea2004-06-03 03:49:45 +00001901\layout LyX-Code
1902
vlmba56d852004-09-29 13:29:17 +00001903asn_DEF_Rectangle->free_struct(&asn_DEF_Rectangle,
vlme18adea2004-06-03 03:49:45 +00001904\layout LyX-Code
1905
1906 rect, 0);
1907\layout Standard
1908
1909This code defines a
1910\emph on
1911rect
1912\emph default
1913 pointer which points to the Rectangle_t structure which needs to be freed.
1914 The second line invokes the generic free_struct routine created specifically
1915 for this Rectangle_t structure.
1916 The
1917\emph on
vlmba56d852004-09-29 13:29:17 +00001918asn_DEF_Rectangle
vlme18adea2004-06-03 03:49:45 +00001919\emph default
1920 is the type descriptor, which holds a collection of generic routines to
1921 deal with the Rectangle_t structure.
1922\layout Standard
1923
1924There are several generic functions available:
1925\layout Description
1926
vlme18adea2004-06-03 03:49:45 +00001927ber_decoder This is the generic
1928\emph on
1929restartable
1930\begin_inset Foot
1931collapsed false
1932
1933\layout Standard
1934
1935Restartable means that if the decoder encounters the end of the buffer,
1936 it will fail, but may later be invoked again with the rest of the buffer
1937 to continue decoding.
1938\end_inset
1939
1940
1941\emph default
1942BER decoder (Basic Encoding Rules).
1943 This decoder would create and/or fill the target structure for you.
1944 Please refer to Section
1945\begin_inset LatexCommand \ref{sub:Decoding-BER}
1946
1947\end_inset
1948
1949.
1950\layout Description
1951
1952der_encoder This is the generic DER encoder (Distinguished Encoding Rules).
vlm68d43e92004-09-24 20:56:07 +00001953 This encoder will take the target structure and encode it into a series
vlme18adea2004-06-03 03:49:45 +00001954 of bytes.
1955 Please refer to Section
1956\begin_inset LatexCommand \ref{sub:Encoding-DER}
1957
1958\end_inset
1959
1960.
1961\layout Description
1962
vlm68d43e92004-09-24 20:56:07 +00001963xer_encoder This is the generic XER encoder (XML Encoding Rules).
1964 This encoder will take the target structure and represent it as an XML
1965 (text) document.
1966 Please refer to Section
1967\begin_inset LatexCommand \ref{sub:Encoding-XER}
1968
1969\end_inset
1970
1971.
1972\layout Description
1973
1974check_constraints Check that the contents of the target structure are semantical
1975ly valid and constrained to appropriate implicit or explicit subtype constraints.
1976 Please refer to Section
1977\begin_inset LatexCommand \vref{sub:Validating-the-target}
1978
1979\end_inset
1980
1981.
1982\layout Description
1983
vlme18adea2004-06-03 03:49:45 +00001984print_struct This function convert the contents of the passed target structure
1985 into human readable form.
1986 This form is not formal and cannot be converted back into the structure,
1987 but it may turn out to be useful for debugging or quick-n-dirty printing.
1988 Please refer to Section
1989\begin_inset LatexCommand \ref{sub:Printing-the-target}
1990
1991\end_inset
1992
1993.
1994\layout Description
1995
1996free_struct This is a generic disposal which frees the target structure.
1997 Please refer to Section
1998\begin_inset LatexCommand \ref{sub:Freeing-the-target}
1999
2000\end_inset
2001
2002.
2003\layout Standard
2004
vlm68d43e92004-09-24 20:56:07 +00002005check_constraints Check that the contents of the target structure are semantical
2006ly valid and constrained to appropriate implicit or explicit subtype constraints.
2007 Please refer to Section
2008\begin_inset LatexCommand \vref{sub:Validating-the-target}
2009
2010\end_inset
2011
2012.
2013\layout Standard
2014
vlme18adea2004-06-03 03:49:45 +00002015Each of the above function takes the type descriptor (
2016\emph on
vlmba56d852004-09-29 13:29:17 +00002017asn_DEF_\SpecialChar \ldots{}
vlme18adea2004-06-03 03:49:45 +00002018
2019\emph default
2020) and the target structure (
2021\emph on
2022rect
2023\emph default
2024, in the above example).
2025 The target structure is typically created by the generic BER decoder or
2026 by the application itself.
2027\layout Standard
2028
2029Here is how the buffer can be deserialized into the structure:
2030\layout LyX-Code
2031
2032Rectangle_t *
2033\layout LyX-Code
2034
vlmfcec8e52004-08-23 15:12:04 +00002035simple_deserializer(const void *buffer, size_t buf_size) {
vlme18adea2004-06-03 03:49:45 +00002036\layout LyX-Code
2037
2038 Rectangle_t *rect = 0; /* Note this 0! */
2039\layout LyX-Code
2040
2041 ber_dec_rval_t rval;
2042\layout LyX-Code
2043
2044
2045\layout LyX-Code
2046
vlmba56d852004-09-29 13:29:17 +00002047 rval = asn_DEF_Rectangle->ber_decoder(0,
vlme18adea2004-06-03 03:49:45 +00002048\layout LyX-Code
2049
vlmba56d852004-09-29 13:29:17 +00002050 &asn_DEF_Rectangle,
vlme18adea2004-06-03 03:49:45 +00002051\layout LyX-Code
2052
2053 (void **)&rect,
2054\layout LyX-Code
2055
2056 buffer, buf_size,
2057\layout LyX-Code
2058
2059 0);
2060\layout LyX-Code
2061
2062
2063\layout LyX-Code
2064
2065 if(rval
2066\series bold
2067.code
2068\series default
2069 == RC_OK) {
2070\layout LyX-Code
2071
2072 return rect; /* Decoding succeeded */
2073\layout LyX-Code
2074
2075 } else {
2076\layout LyX-Code
2077
vlmfcec8e52004-08-23 15:12:04 +00002078 /* Free partially decoded rect */
2079\layout LyX-Code
2080
vlmba56d852004-09-29 13:29:17 +00002081 asn_DEF_Rectangle->free_struct(
vlme18adea2004-06-03 03:49:45 +00002082\layout LyX-Code
2083
vlmba56d852004-09-29 13:29:17 +00002084 &asn_DEF_Rectangle, rect, 0);
vlme18adea2004-06-03 03:49:45 +00002085\layout LyX-Code
2086
2087 return 0;
2088\layout LyX-Code
2089
2090 }
2091\layout LyX-Code
2092
2093}
2094\layout Standard
2095
2096The code above defines a function,
2097\emph on
2098simple_deserializer
2099\emph default
2100, which takes a buffer and its length and expected to return a pointer to
2101 the Rectangle_t structure.
2102 Inside, it tries to convert the bytes passed into the target structure
2103 (rect) using the generic BER decoder and returns the rect pointer afterwards.
2104 If the structure cannot be deserialized, it frees the memory which might
2105 be left allocated by the unfinished
2106\emph on
2107ber_decoder
2108\emph default
2109 routine and returns NULL.
2110
2111\series bold
2112This freeing is necessary
2113\series default
2114 because the ber_decoder is a restartable procedure, and may fail just because
2115 there is more data needs to be provided before decoding could be finalized.
2116 The code above obviously does not take into account the way the
2117\emph on
2118ber_decoder
2119\emph default
2120 failed, so the freeing is necessary because the part of the buffer may
2121 already be decoded into the structure by the time something goes wrong.
2122\layout Standard
2123
2124Restartable decoding is a little bit trickier: you need to provide the old
2125 target structure pointer (which might be already half-decoded) and react
2126 on RC_WMORE return code.
2127 This will be explained later in Section
2128\begin_inset LatexCommand \vref{sub:Decoding-BER}
2129
2130\end_inset
2131
2132
vlmfcec8e52004-08-23 15:12:04 +00002133\layout Subsection
vlme18adea2004-06-03 03:49:45 +00002134
2135
2136\begin_inset LatexCommand \label{sub:Decoding-BER}
2137
2138\end_inset
2139
2140Decoding BER
2141\layout Standard
2142
2143The Basic Encoding Rules describe the basic way how the structure can be
2144 encoded and decoded.
2145 Several other encoding rules (CER, DER) define a more restrictive versions
2146 of BER, so the generic BER parser is also capable of decoding the data
2147 encoded by CER and DER encoders.
2148 The opposite is not true.
2149\layout Standard
2150
2151The ASN.1 compiler provides the generic BER decoder which is implicitly capable
2152 of decoding BER, CER and DER encoded data.
2153\layout Standard
2154
2155The decoder is restartable (stream-oriented), which means that in case the
2156 buffer has less data than it is expected, the decoder will process whatever
2157 it is available and ask for more data to be provided.
2158 Please note that the decoder may actually process less data than it is
2159 given in the buffer, which means that you should be able to make the next
2160 buffer contain the unprocessed part of the previous buffer.
2161\layout Standard
2162
2163Suppose, you have two buffers of encoded data: 100 bytes and 200 bytes.
2164\layout Itemize
2165
2166You may concatenate these buffers and feed the BER decoder with 300 bytes
2167 of data, or
2168\layout Itemize
2169
2170You may feed it the first buffer of 100 bytes of data, realize that the
2171 ber_decoder consumed only 95 bytes from it and later feed the decoder with
2172 205 bytes buffer which consists of 5 unprocessed bytes from the first buffer
2173 and the latter 200 bytes from the second buffer.
2174\layout Standard
2175
2176This is not as convenient as it could be (like, the BER encoder would consume
2177 the whole 100 bytes and keep these 5 bytes in some temporary storage),
2178 but in case of stream-based processing it might actually be OK.
2179 Suggestions are welcome.
2180\layout Standard
2181
2182There are two ways to invoke a BER decoder.
2183 The first one is a direct reference of the type-specific decoder.
2184 This way was shown in the previous example of
2185\emph on
2186simple_deserializer
2187\emph default
2188 function.
2189 The second way is to invoke a
2190\emph on
2191ber_decode
2192\emph default
2193 function, which is just a simple wrapper of the former approach into a
2194 less wordy notation:
2195\layout LyX-Code
2196
vlmba56d852004-09-29 13:29:17 +00002197rval = ber_decode(0, &asn_DEF_Rectangle, (void **)&rect,
vlme18adea2004-06-03 03:49:45 +00002198\layout LyX-Code
2199
2200 buffer, buf_size);
2201\layout Standard
2202
vlmba56d852004-09-29 13:29:17 +00002203Note that the initial (asn_DEF_Rectangle->ber_decoder) reference is gone,
vlme18adea2004-06-03 03:49:45 +00002204 and also the last argument (0) is no longer necessary.
2205\layout Standard
2206
2207These two ways of invocations are fully equivalent.
2208\layout Standard
2209
2210The BER de
2211\emph on
2212coder
2213\emph default
vlmba56d852004-09-29 13:29:17 +00002214 may fail because of (
vlme18adea2004-06-03 03:49:45 +00002215\emph on
2216the following RC_\SpecialChar \ldots{}
2217 codes are defined in ber_decoder.h
2218\emph default
2219):
2220\layout Itemize
2221
2222RC_WMORE: There is more data expected than it is provided (stream mode continuat
2223ion feature);
2224\layout Itemize
2225
2226RC_FAIL: General failure to decode the buffer;
2227\layout Itemize
2228
2229\SpecialChar \ldots{}
2230 other codes may be defined as well.
2231\layout Standard
2232
2233Together with the return code (.code) the ber_dec_rval_t type contains the
2234 number of bytes which is consumed from the buffer.
2235 In the previous hypothetical example of two buffers (of 100 and 200 bytes),
2236 the first call to ber_decode() would return with .code = RC_WMORE and .consumed
2237 = 95.
2238 The .consumed field of the BER decoder return value is
2239\series bold
2240always
2241\series default
2242 valid, even if the decoder succeeds or fails with any other return code.
2243\layout Standard
2244
2245Please look into ber_decoder.h for the precise definition of ber_decode()
2246 and related types.
vlmfcec8e52004-08-23 15:12:04 +00002247\layout Subsection
vlme18adea2004-06-03 03:49:45 +00002248
2249
2250\begin_inset LatexCommand \label{sub:Encoding-DER}
2251
2252\end_inset
2253
2254Encoding DER
2255\layout Standard
2256
vlm68d43e92004-09-24 20:56:07 +00002257The Distinguished Encoding Rules is the
2258\emph on
2259canonical
2260\emph default
2261 variant of BER encoding rules.
2262 The DER is best suited to encode the structures where all the lengths are
2263 known beforehand.
vlme18adea2004-06-03 03:49:45 +00002264 This is probably exactly how you want to encode: either after a BER decoding
2265 or after a manual fill-up, the target structure contains the data which
2266 size is implicitly known before encoding.
2267 The DER encoding is used, for example, to encode X.509 certificates.
2268\layout Standard
2269
2270As with BER decoder, the DER encoder may be invoked either directly from
vlmba56d852004-09-29 13:29:17 +00002271 the ASN.1 type descriptor (asn_DEF_Rectangle) or from the stand-alone function,
vlme18adea2004-06-03 03:49:45 +00002272 which is somewhat simpler:
2273\layout LyX-Code
2274
2275/*
2276\layout LyX-Code
2277
2278 * This is a custom function which writes the
2279\layout LyX-Code
2280
2281 * encoded output into some FILE stream.
2282\layout LyX-Code
2283
2284 */
2285\layout LyX-Code
2286
vlmfcec8e52004-08-23 15:12:04 +00002287static int
2288\layout LyX-Code
2289
2290write_stream(const void *buffer, size_t size, void *app_key) {
vlme18adea2004-06-03 03:49:45 +00002291\layout LyX-Code
2292
2293 FILE *ostream = app_key;
2294\layout LyX-Code
2295
2296 size_t wrote;
2297\layout LyX-Code
2298
2299
2300\layout LyX-Code
2301
2302 wrote = fwrite(buffer, 1, size, ostream);
2303\layout LyX-Code
2304
2305
2306\layout LyX-Code
2307
2308 return (wrote == size) ? 0 : -1;
2309\layout LyX-Code
2310
2311}
2312\layout LyX-Code
2313
2314
2315\layout LyX-Code
2316
2317/*
2318\layout LyX-Code
2319
2320 * This is the serializer itself,
2321\layout LyX-Code
2322
2323 * it supplies the DER encoder with the
2324\layout LyX-Code
2325
2326 * pointer to the custom output function.
2327\layout LyX-Code
2328
2329 */
2330\layout LyX-Code
2331
2332ssize_t
2333\layout LyX-Code
2334
2335simple_serializer(FILE *ostream, Rectangle_t *rect) {
2336\layout LyX-Code
2337
vlm68d43e92004-09-24 20:56:07 +00002338 asn_enc_rval_t er; /* Encoder return value */
vlme18adea2004-06-03 03:49:45 +00002339\layout LyX-Code
2340
2341
2342\layout LyX-Code
2343
vlmba56d852004-09-29 13:29:17 +00002344 er = der_encode(&asn_DEF_Rect, rect,
vlme18adea2004-06-03 03:49:45 +00002345\layout LyX-Code
2346
vlmfcec8e52004-08-23 15:12:04 +00002347 write_stream, ostream);
vlme18adea2004-06-03 03:49:45 +00002348\layout LyX-Code
2349
vlm68d43e92004-09-24 20:56:07 +00002350 if(er.
vlme18adea2004-06-03 03:49:45 +00002351\series bold
vlm68d43e92004-09-24 20:56:07 +00002352encoded
vlme18adea2004-06-03 03:49:45 +00002353\series default
2354 == -1) {
2355\layout LyX-Code
2356
2357 /*
2358\layout LyX-Code
2359
vlm68d43e92004-09-24 20:56:07 +00002360 * Failed to encode the rectangle data.
vlme18adea2004-06-03 03:49:45 +00002361\layout LyX-Code
2362
2363 */
2364\layout LyX-Code
2365
2366 fprintf(stderr,
2367\begin_inset Quotes sld
2368\end_inset
2369
2370Cannot encode %s: %s
2371\backslash
2372n
2373\begin_inset Quotes srd
2374\end_inset
2375
2376,
2377\layout LyX-Code
2378
vlm68d43e92004-09-24 20:56:07 +00002379 er.
vlme18adea2004-06-03 03:49:45 +00002380\series bold
vlm68d43e92004-09-24 20:56:07 +00002381failed_type
vlme18adea2004-06-03 03:49:45 +00002382\series default
2383->name,
2384\layout LyX-Code
2385
2386 strerror(errno));
2387\layout LyX-Code
2388
2389 return -1;
2390\layout LyX-Code
2391
2392 } else {
2393\layout LyX-Code
2394
2395 /* Return the number of bytes */
2396\layout LyX-Code
2397
vlm68d43e92004-09-24 20:56:07 +00002398 return er.encoded;
vlme18adea2004-06-03 03:49:45 +00002399\layout LyX-Code
2400
2401 }
2402\layout LyX-Code
2403
2404}
2405\layout Standard
2406
2407As you see, the DER encoder does not write into some sort of buffer or something.
2408 It just invokes the custom function (possible, multiple times) which would
2409 save the data into appropriate storage.
2410 The optional argument
2411\emph on
2412app_key
2413\emph default
2414 is opaque for the DER encoder code and just used by
2415\emph on
2416_write_stream()
2417\emph default
2418 as the pointer to the appropriate output stream to be used.
2419\layout Standard
2420
2421If the custom write function is not given (passed as 0), then the DER encoder
2422 will essentially do the same thing (i.e., encode the data) but no callbacks
2423 will be invoked (so the data goes nowhere).
2424 It may prove useful to determine the size of the structure's encoding before
2425 actually doing the encoding
2426\begin_inset Foot
2427collapsed false
2428
2429\layout Standard
2430
2431It is actually faster too: the encoder might skip over some computations
2432 which aren't important for the size determination.
2433\end_inset
2434
2435.
2436\layout Standard
2437
2438Please look into der_encoder.h for the precise definition of der_encode()
2439 and related types.
vlmfcec8e52004-08-23 15:12:04 +00002440\layout Subsection
vlme18adea2004-06-03 03:49:45 +00002441
2442
vlm68d43e92004-09-24 20:56:07 +00002443\begin_inset LatexCommand \label{sub:Encoding-XER}
2444
2445\end_inset
2446
2447Encoding XER
2448\layout Standard
2449
2450The XER stands for XML Encoding Rules, where XML, in turn, is eXtensible
2451 Markup Language, a text-based format for information exchange.
2452 The encoder routine API comes in two flavors: stdio-based and callback-based.
2453 With the callback-based encoder, the encoding process is very similar to
2454 the DER one, described in Section
2455\begin_inset LatexCommand \vref{sub:Encoding-DER}
2456
2457\end_inset
2458
2459.
2460 The following example uses the definition of write_stream() from up there.
2461\layout LyX-Code
2462
2463/*
2464\layout LyX-Code
2465
2466 * This procedure generates the XML document
2467\layout LyX-Code
2468
2469 * by invoking the XER encoder.
2470\layout LyX-Code
2471
2472 * NOTE: Do not copy this code verbatim!
2473\layout LyX-Code
2474
2475 * If the stdio output is necessary,
2476\layout LyX-Code
2477
2478 * use the xer_fprint() procedure instead.
2479\layout LyX-Code
2480
2481 * See Section
2482\begin_inset LatexCommand \vref{sub:Printing-the-target}
2483
2484\end_inset
2485
2486.
2487\layout LyX-Code
2488
2489 */
2490\layout LyX-Code
2491
2492int
2493\layout LyX-Code
2494
2495print_as_XML(FILE *ostream, Rectangle_t *rect) {
2496\layout LyX-Code
2497
2498 asn_enc_rval_t er; /* Encoder return value */
2499\layout LyX-Code
2500
2501
2502\layout LyX-Code
2503
vlmba56d852004-09-29 13:29:17 +00002504 er = xer_encode(&asn_DEF_Rect, rect,
vlm68d43e92004-09-24 20:56:07 +00002505\layout LyX-Code
2506
2507 XER_F_BASIC, /* BASIC-XER or CANONICAL-XER */
2508\layout LyX-Code
2509
2510 write_stream, ostream);
2511\layout LyX-Code
2512
2513
2514\layout LyX-Code
2515
2516 return (er.encoded == -1) ? -1 : 0;
2517\layout LyX-Code
2518
2519}
2520\layout Standard
2521
2522Please look into xer_encoder.h for the precise definition of xer_encode()
2523 and related types.
2524\layout Standard
2525
2526See Section
2527\begin_inset LatexCommand \ref{sub:Printing-the-target}
2528
2529\end_inset
2530
2531 for the example of stdio-based XML encoder and other pretty-printing suggestion
2532s.
2533\layout Subsection
2534
2535
vlme18adea2004-06-03 03:49:45 +00002536\begin_inset LatexCommand \label{sub:Validating-the-target}
2537
2538\end_inset
2539
2540Validating the target structure
2541\layout Standard
2542
2543Sometimes the target structure needs to be validated.
2544 For example, if the structure was created by the application (as opposed
2545 to being decoded from some external source), some important information
2546 required by the ASN.1 specification might be missing.
2547 On the other hand, the successful decoding of the data from some external
2548 source does not necessarily mean that the data is fully valid either.
2549 It might well be the case that the specification describes some subtype
2550 constraints that were not taken into account during decoding, and it would
2551 actually be useful to perform the last check when the data is ready to
2552 be encoded or when the data has just been decoded to ensure its validity
2553 according to some stricter rules.
2554\layout Standard
2555
2556The asn_check_constraints() function checks the type for various implicit
2557 and explicit constraints.
2558 It is recommended to use asn_check_constraints() function after each decoding
2559 and before each encoding.
2560\layout Standard
2561
2562Please look into constraints.h for the precise definition of asn_check_constraint
2563s() and related types.
vlmfcec8e52004-08-23 15:12:04 +00002564\layout Subsection
vlme18adea2004-06-03 03:49:45 +00002565
2566
2567\begin_inset LatexCommand \label{sub:Printing-the-target}
2568
2569\end_inset
2570
2571Printing the target structure
2572\layout Standard
2573
2574There are two ways to print the target structure: either invoke the print_struct
2575 member of the ASN.1 type descriptor, or using the asn_fprint() function,
2576 which is a simpler wrapper of the former:
2577\layout LyX-Code
2578
vlmba56d852004-09-29 13:29:17 +00002579asn_fprint(stdout, &asn_DEF_Rectangle, rect);
vlme18adea2004-06-03 03:49:45 +00002580\layout Standard
2581
2582Please look into constr_TYPE.h for the precise definition of asn_fprint()
2583 and related types.
vlm68d43e92004-09-24 20:56:07 +00002584\layout Standard
2585
2586Another practical alternative to this custom format printing would be to
2587 invoke XER encoder.
2588 The default BASIC-XER encoder performs reasonable formatting for the output
2589 to be useful and human readable.
2590 To invoke the XER decoder in a manner similar to asn_fprint(), use the
2591 xer_fprint() call:
2592\layout LyX-Code
2593
vlmba56d852004-09-29 13:29:17 +00002594xer_fprint(stdout, &asn_DEF_Rectangle, rect);
vlm68d43e92004-09-24 20:56:07 +00002595\layout Standard
2596
2597See Section
2598\begin_inset LatexCommand \vref{sub:Encoding-XER}
2599
2600\end_inset
2601
2602 for XML-related details.
vlmfcec8e52004-08-23 15:12:04 +00002603\layout Subsection
vlme18adea2004-06-03 03:49:45 +00002604
2605
2606\begin_inset LatexCommand \label{sub:Freeing-the-target}
2607
2608\end_inset
2609
2610Freeing the target structure
2611\layout Standard
2612
2613Freeing the structure is slightly more complex than it may seem to.
2614 When the ASN.1 structure is freed, all the members of the structure and
2615 their submembers etc etc are recursively freed too.
2616 But it might not be feasible to free the structure itself.
2617 Consider the following case:
2618\layout LyX-Code
2619
2620struct my_figure { /* The custom structure */
2621\layout LyX-Code
2622
2623 int flags; /* <some custom member> */
2624\layout LyX-Code
2625
2626 /* The type is generated by the ASN.1 compiler */
2627\layout LyX-Code
2628
2629
2630\emph on
2631Rectangle_t rect;
2632\layout LyX-Code
2633
2634 /* other members of the structure */
2635\layout LyX-Code
2636
2637};
2638\layout Standard
2639
2640In this example, the application programmer defined a custom structure with
2641 one ASN.1-derived member (rect).
2642 This member is not a reference to the Rectangle_t, but an in-place inclusion
2643 of the Rectangle_t structure.
2644 If the freeing is necessary, the usual procedure of freeing everything
2645 must not be applied to the &rect pointer itself, because it does not point
2646 to the memory block directly allocated by memory allocation routine, but
2647 instead lies within such a block allocated for my_figure structure.
2648\layout Standard
2649
2650To solve this problem, the free_struct routine has the additional argument
2651 (besides the intuitive type descriptor and target structure pointers),
2652 which is the flag specifying whether the outer pointer itself must be freed
2653 (0, default) or it should be left intact (non-zero value).
2654\layout LyX-Code
2655
2656/* Rectangle_t is defined within my_figure */
2657\layout LyX-Code
2658
2659struct my_figure *mf =
2660\series bold
2661...
2662\series default
2663;
2664\layout LyX-Code
2665
2666/*
2667\layout LyX-Code
2668
2669 * Freeing the Rectangle_td
2670\layout LyX-Code
2671
2672 * without freeing the mf->rect pointer
2673\layout LyX-Code
2674
2675 */
2676\layout LyX-Code
2677
vlmba56d852004-09-29 13:29:17 +00002678asn_DEF_Rectangle->free_struct(
vlme18adea2004-06-03 03:49:45 +00002679\layout LyX-Code
2680
vlmba56d852004-09-29 13:29:17 +00002681 &asn_DEF_Rectangle, &mf->rect,
vlme18adea2004-06-03 03:49:45 +00002682\emph on
26831
2684\emph default
2685 /* !free */);
2686\layout LyX-Code
2687
2688
2689\layout LyX-Code
2690
2691/* Rectangle_t is a stand-alone pointer */
2692\layout LyX-Code
2693
2694Rectangle_t *rect =
2695\series bold
2696...
2697\series default
2698;
2699\layout LyX-Code
2700
2701/*
2702\layout LyX-Code
2703
2704 * Freeing the Rectangle_t
2705\layout LyX-Code
2706
2707 * and freeing the rect pointer
2708\layout LyX-Code
2709
2710 */
2711\layout LyX-Code
2712
vlmba56d852004-09-29 13:29:17 +00002713asn_DEF_Rectangle->free_struct(
vlme18adea2004-06-03 03:49:45 +00002714\layout LyX-Code
2715
vlmba56d852004-09-29 13:29:17 +00002716 &asn_DEF_Rectangle, rect,
vlme18adea2004-06-03 03:49:45 +00002717\emph on
27180
2719\emph default
2720 /* free the pointer too */);
2721\layout Standard
2722
2723It is safe to invoke the
2724\emph on
2725free_struct
2726\emph default
2727 function with the target structure pointer set to 0 (NULL), the function
2728 will do nothing.
2729\layout Bibliography
vlmfcec8e52004-08-23 15:12:04 +00002730\bibitem [ASN1C]{ASN1C}
2731
vlm89d219b2004-09-08 03:01:06 +00002732The OpenSource ASN.1 Compiler.
vlmfcec8e52004-08-23 15:12:04 +00002733
2734\begin_inset LatexCommand \htmlurl{http://lionet.info/asn1/}
2735
2736\end_inset
2737
2738
2739\layout Bibliography
vlme18adea2004-06-03 03:49:45 +00002740\bibitem [Dub00]{Dub00}
2741
2742Olivier Dubuisson --
2743\emph on
2744ASN.1 Communication between heterogeneous systems
2745\emph default
2746 -- Morgan Kaufmann Publishers, 2000.
2747
2748\begin_inset LatexCommand \htmlurl{http://asn1.elibel.tm.fr/en/book/}
2749
2750\end_inset
2751
2752.
2753 ISBN:0-12-6333361-0.
2754\layout Bibliography
2755\bibitem [ITU-T/ASN.1]{ITU-T/ASN.1}
2756
2757ITU-T Study Group 17 -- Languages for Telecommunication Systems
2758\begin_inset LatexCommand \url{http://www.itu.int/ITU-T/studygroups/com17/languages/}
2759
2760\end_inset
2761
2762
2763\the_end