vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1 | #LyX 1.3 created this file. For more info see http://www.lyx.org/ |
| 2 | \lyxformat 221 |
| 3 | \textclass book |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 4 | \begin_preamble |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 5 | \usepackage{extramarks} |
| 6 | \lhead{\firstxmark} |
| 7 | \rfoot{\lastxmark} |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 8 | \usepackage{color} |
| 9 | \definecolor{gray40}{gray}{.4} |
| 10 | \definecolor{urlblue}{rgb}{0,0,.6} |
| 11 | \usepackage[colorlinks=true, |
| 12 | linkcolor={gray40}, |
| 13 | urlcolor={urlblue}, |
| 14 | pdfauthor={Lev Walkin}, |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 15 | pdftitle={Using the Open Source ASN.1 Compiler}, |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 16 | pdfkeywords={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} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 23 | \end_preamble |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 24 | \language english |
| 25 | \inputencoding latin1 |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 26 | \fontscheme times |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 27 | \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 |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 37 | \secnumdepth 2 |
| 38 | \tocdepth 2 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 39 | \paragraph_separation indent |
| 40 | \defskip medskip |
| 41 | \quotes_language swedish |
| 42 | \quotes_times 2 |
| 43 | \papercolumns 1 |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 44 | \papersides 2 |
| 45 | \paperpagestyle fancy |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 46 | |
| 47 | \layout Title |
| 48 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 49 | Using the Open Source ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 50 | \layout Author |
| 51 | |
| 52 | Lev Walkin < |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 53 | \begin_inset ERT |
| 54 | status Collapsed |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 55 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 56 | \layout Standard |
| 57 | |
| 58 | \backslash |
| 59 | href{mailto:vlm@lionet.info?Subject=asn1c}{vlm@lionet.info} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 60 | \end_inset |
| 61 | |
| 62 | > |
| 63 | \layout Standard |
| 64 | |
| 65 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 66 | \begin_inset ERT |
| 67 | status Open |
| 68 | |
| 69 | \layout Standard |
| 70 | |
| 71 | \backslash |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 72 | lhead{This document describes |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 73 | \backslash |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 74 | href{http://lionet.info/asn1c}{asn1c-0.9.11}} |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 75 | \layout Standard |
| 76 | |
| 77 | \backslash |
| 78 | rhead{$Revision$} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 79 | \end_inset |
| 80 | |
| 81 | |
| 82 | \layout Standard |
| 83 | |
| 84 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 85 | \begin_inset LatexCommand \tableofcontents{} |
| 86 | |
| 87 | \end_inset |
| 88 | |
| 89 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 90 | \layout Standard |
| 91 | |
| 92 | |
| 93 | \begin_inset ERT |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 94 | status Open |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 95 | |
| 96 | \layout Standard |
| 97 | |
| 98 | \backslash |
| 99 | pagestyle{headings} |
| 100 | \end_inset |
| 101 | |
| 102 | |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 103 | \layout Part |
| 104 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 105 | Using the ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 106 | \layout Chapter |
| 107 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 108 | Introduction to the ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 109 | \layout Standard |
| 110 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 111 | The purpose of the ASN.1 compiler, of which this document is part, is to |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 112 | convert the specifications in ASN.1 notation into some other language. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 113 | At this moment, only C and C++ target languages are supported, the latter |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 114 | is in upward compatibility mode. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 115 | \layout Standard |
| 116 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 117 | The 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. |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 120 | 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). |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 123 | \layout Standard |
| 124 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 125 | For example, suppose the following ASN.1 module is given |
| 126 | \begin_inset Foot |
| 127 | collapsed true |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 128 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 129 | \layout Standard |
| 130 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 131 | Please look into Part |
| 132 | \begin_inset LatexCommand \vref{par:ASN.1-Basics} |
| 133 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 134 | \end_inset |
| 135 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 136 | for a quick reference on how to understand the ASN.1 notation. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 137 | \end_inset |
| 138 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 139 | : |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 140 | \layout LyX-Code |
| 141 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 142 | RectangleTest DEFINITIONS ::= |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 143 | \layout LyX-Code |
| 144 | |
| 145 | BEGIN |
| 146 | \layout LyX-Code |
| 147 | |
| 148 | |
| 149 | \layout LyX-Code |
| 150 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 151 | Rectangle ::= SEQUENCE { |
| 152 | \layout LyX-Code |
| 153 | |
| 154 | height INTEGER, -- Height of the rectangle |
| 155 | \layout LyX-Code |
| 156 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 157 | width INTEGER -- Width of the rectangle |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 158 | \layout LyX-Code |
| 159 | |
| 160 | } |
| 161 | \layout LyX-Code |
| 162 | |
| 163 | |
| 164 | \layout LyX-Code |
| 165 | |
| 166 | END |
| 167 | \layout Standard |
| 168 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 169 | The compiler would read this ASN.1 definition and produce the following C |
| 170 | type |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 171 | \begin_inset Foot |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 172 | collapsed true |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 173 | |
| 174 | \layout Standard |
| 175 | |
| 176 | |
| 177 | \emph on |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 178 | -fnative-types |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 179 | \emph default |
| 180 | compiler option is used to produce basic C |
| 181 | \emph on |
| 182 | int |
| 183 | \emph default |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 184 | types instead of infinite width INTEGER_t structures. |
| 185 | See Table |
| 186 | \begin_inset LatexCommand \vref{cap:asn1c-cmdopts} |
| 187 | |
| 188 | \end_inset |
| 189 | |
| 190 | . |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 191 | \end_inset |
| 192 | |
| 193 | : |
| 194 | \layout LyX-Code |
| 195 | |
| 196 | typedef 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 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 208 | It would also create the code for converting this structure into platform-indepe |
| 209 | ndent 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 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 212 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 213 | Quick start with asn1c |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 214 | \layout Standard |
| 215 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 216 | After building and installing the compiler, the |
| 217 | \emph on |
| 218 | asn1c |
| 219 | \begin_inset Foot |
| 220 | collapsed false |
| 221 | |
| 222 | \layout Standard |
| 223 | |
| 224 | The 1 symbol in asn |
| 225 | \series bold |
| 226 | 1 |
| 227 | \series default |
| 228 | c is a digit, not an |
| 229 | \begin_inset Quotes sld |
| 230 | \end_inset |
| 231 | |
| 232 | ell |
| 233 | \begin_inset Quotes srd |
| 234 | \end_inset |
| 235 | |
| 236 | letter. |
| 237 | \end_inset |
| 238 | |
| 239 | |
| 240 | \emph default |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 241 | command may be used to compile the ASN.1 module |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 242 | \begin_inset Foot |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 243 | collapsed true |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 244 | |
| 245 | \layout Standard |
| 246 | |
| 247 | This is probably |
| 248 | \series bold |
| 249 | not |
| 250 | \series default |
| 251 | what you want to try out right now -- read through the rest of this chapter |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 252 | and check the Table |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 253 | \begin_inset LatexCommand \vref{cap:asn1c-cmdopts} |
| 254 | |
| 255 | \end_inset |
| 256 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 257 | to find out about |
| 258 | \series bold |
| 259 | -P |
| 260 | \series default |
| 261 | and |
| 262 | \series bold |
| 263 | -R |
| 264 | \series default |
| 265 | options. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 266 | \end_inset |
| 267 | |
| 268 | : |
| 269 | \layout LyX-Code |
| 270 | |
| 271 | asn1c |
| 272 | \emph on |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 273 | <module.asn1> |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 274 | \layout Standard |
| 275 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 276 | If several ASN.1 modules contain interdependencies, all of the files must |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 277 | be specified altogether: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 278 | \layout LyX-Code |
| 279 | |
| 280 | asn1c |
| 281 | \emph on |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 282 | <module1.asn1> <module2.asn1> ... |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 283 | \layout Standard |
| 284 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 285 | The 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 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 301 | is properly supported by the compiler. |
| 302 | \layout LyX-Code |
| 303 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 304 | asn1c |
| 305 | \series bold |
| 306 | -EF |
| 307 | \series default |
| 308 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 309 | \emph on |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 310 | <module-to-test.asn1> |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 311 | \layout Standard |
| 312 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 313 | The |
| 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 | |
| 332 | Print the compiled output instead of creating multiple source files: |
| 333 | \layout LyX-Code |
| 334 | |
| 335 | asn1c |
| 336 | \series bold |
| 337 | -P |
| 338 | \series default |
| 339 | |
| 340 | \emph on |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 341 | <module-to-compile-and-print.asn1> |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 342 | \layout Section |
| 343 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 344 | Recognizing compiler output |
| 345 | \layout Standard |
| 346 | |
| 347 | After compiling, the following entities will be created in your current |
| 348 | directory: |
| 349 | \layout Itemize |
| 350 | |
| 351 | A 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 |
| 355 | Rectangle.c |
| 356 | \emph default |
| 357 | and |
| 358 | \emph on |
| 359 | Rectangle.h |
| 360 | \emph default |
| 361 | for the RectangleTest ASN.1 module defined in the beginning of this document). |
| 362 | \layout Itemize |
| 363 | |
| 364 | A 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 | |
| 370 | A |
| 371 | \emph on |
| 372 | Makefile.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 | |
| 378 | It is your responsibility to create .c file with the |
| 379 | \emph on |
| 380 | int main() |
| 381 | \emph default |
| 382 | routine. |
| 383 | \layout Standard |
| 384 | |
| 385 | In 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 | |
| 408 | helper |
| 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 |
| 415 | int main() |
| 416 | \emph default |
| 417 | routine, it would even be possible to compile everything with the single |
| 418 | instruction: |
| 419 | \layout LyX-Code |
| 420 | |
| 421 | cc -I. |
| 422 | -o rectangle.exe *.c # It could be |
| 423 | \emph on |
| 424 | that |
| 425 | \emph default |
| 426 | simple |
| 427 | \layout Standard |
| 428 | |
| 429 | Refer 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 |
| 436 | int main() |
| 437 | \emph default |
| 438 | routine. |
| 439 | \layout Section |
| 440 | |
| 441 | Command line options |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 442 | \layout Standard |
| 443 | |
| 444 | The Table |
| 445 | \begin_inset LatexCommand \vref{cap:asn1c-cmdopts} |
| 446 | |
| 447 | \end_inset |
| 448 | |
| 449 | summarizes various options affecting the compiler's behavior. |
| 450 | \layout Standard |
| 451 | |
| 452 | |
| 453 | \begin_inset Float table |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 454 | placement h |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 455 | wide false |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 456 | collapsed false |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 457 | |
| 458 | \layout Standard |
| 459 | |
| 460 | |
| 461 | \begin_inset Tabular |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 462 | <lyxtabular version="3" rows="24" columns="2"> |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 463 | <features islongtable="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 464 | <column alignment="left" valignment="top" leftline="true" width="0"> |
| 465 | <column alignment="block" valignment="top" leftline="true" rightline="true" width="3in"> |
| 466 | <row topline="true" bottomline="true"> |
| 467 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 468 | \begin_inset Text |
| 469 | |
| 470 | \layout Standard |
| 471 | |
| 472 | |
| 473 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 474 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 475 | Overall Options |
| 476 | \end_inset |
| 477 | </cell> |
| 478 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 479 | \begin_inset Text |
| 480 | |
| 481 | \layout Standard |
| 482 | |
| 483 | |
| 484 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 485 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 486 | Description |
| 487 | \end_inset |
| 488 | </cell> |
| 489 | </row> |
| 490 | <row topline="true"> |
| 491 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 492 | \begin_inset Text |
| 493 | |
| 494 | \layout Standard |
| 495 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 496 | |
| 497 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 498 | -E |
| 499 | \end_inset |
| 500 | </cell> |
| 501 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 502 | \begin_inset Text |
| 503 | |
| 504 | \layout Standard |
| 505 | |
| 506 | |
| 507 | \size small |
| 508 | Stop after the parsing stage and print the reconstructed ASN.1 specification |
| 509 | code to the standard output. |
| 510 | \end_inset |
| 511 | </cell> |
| 512 | </row> |
| 513 | <row topline="true"> |
| 514 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 515 | \begin_inset Text |
| 516 | |
| 517 | \layout Standard |
| 518 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 519 | |
| 520 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 521 | -F |
| 522 | \end_inset |
| 523 | </cell> |
| 524 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 525 | \begin_inset Text |
| 526 | |
| 527 | \layout Standard |
| 528 | |
| 529 | |
| 530 | \size small |
| 531 | Used together with -E, instructs the compiler to stop after the ASN.1 syntax |
| 532 | tree fixing stage and dump the reconstructed ASN.1 specification to the |
| 533 | standard output. |
| 534 | \end_inset |
| 535 | </cell> |
| 536 | </row> |
| 537 | <row topline="true"> |
| 538 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 539 | \begin_inset Text |
| 540 | |
| 541 | \layout Standard |
| 542 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 543 | |
| 544 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 545 | -P |
| 546 | \end_inset |
| 547 | </cell> |
| 548 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 549 | \begin_inset Text |
| 550 | |
| 551 | \layout Standard |
| 552 | |
| 553 | |
| 554 | \size small |
| 555 | Dump the compiled output to the standard output instead of cre- ating the |
| 556 | target language files on disk. |
| 557 | \end_inset |
| 558 | </cell> |
| 559 | </row> |
| 560 | <row topline="true"> |
| 561 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 562 | \begin_inset Text |
| 563 | |
| 564 | \layout Standard |
| 565 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 566 | |
| 567 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 568 | -R |
| 569 | \end_inset |
| 570 | </cell> |
| 571 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 572 | \begin_inset Text |
| 573 | |
| 574 | \layout Standard |
| 575 | |
| 576 | |
| 577 | \size small |
| 578 | Restrict the compiler to generate only the ASN.1 tables, omit- ting the usual |
| 579 | support code. |
| 580 | \end_inset |
| 581 | </cell> |
| 582 | </row> |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 583 | <row topline="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 584 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 585 | \begin_inset Text |
| 586 | |
| 587 | \layout Standard |
| 588 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 589 | |
| 590 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 591 | -S |
| 592 | \emph on |
| 593 | <directory> |
| 594 | \end_inset |
| 595 | </cell> |
| 596 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 597 | \begin_inset Text |
| 598 | |
| 599 | \layout Standard |
| 600 | |
| 601 | |
| 602 | \size small |
| 603 | Use the specified directory with ASN.1 skeleton files. |
| 604 | \end_inset |
| 605 | </cell> |
| 606 | </row> |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 607 | <row topline="true" bottomline="true"> |
| 608 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 609 | \begin_inset Text |
| 610 | |
| 611 | \layout Standard |
| 612 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 613 | |
| 614 | \size small |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 615 | -X |
| 616 | \end_inset |
| 617 | </cell> |
| 618 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 619 | \begin_inset Text |
| 620 | |
| 621 | \layout Standard |
| 622 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 623 | |
| 624 | \size small |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 625 | Generate the XML DTD for the specified ASN.1 modules. |
| 626 | \end_inset |
| 627 | </cell> |
| 628 | </row> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 629 | <row topline="true"> |
| 630 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 631 | \begin_inset Text |
| 632 | |
| 633 | \layout Standard |
| 634 | |
| 635 | |
| 636 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 637 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 638 | Warning Options |
| 639 | \end_inset |
| 640 | </cell> |
| 641 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 642 | \begin_inset Text |
| 643 | |
| 644 | \layout Standard |
| 645 | |
| 646 | |
| 647 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 648 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 649 | Description |
| 650 | \end_inset |
| 651 | </cell> |
| 652 | </row> |
| 653 | <row topline="true"> |
| 654 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 655 | \begin_inset Text |
| 656 | |
| 657 | \layout Standard |
| 658 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 659 | |
| 660 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 661 | -Werror |
| 662 | \end_inset |
| 663 | </cell> |
| 664 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 665 | \begin_inset Text |
| 666 | |
| 667 | \layout Standard |
| 668 | |
| 669 | |
| 670 | \size small |
| 671 | Treat warnings as errors; abort if any warning is produced. |
| 672 | \end_inset |
| 673 | </cell> |
| 674 | </row> |
| 675 | <row topline="true"> |
| 676 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 677 | \begin_inset Text |
| 678 | |
| 679 | \layout Standard |
| 680 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 681 | |
| 682 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 683 | -Wdebug-lexer |
| 684 | \end_inset |
| 685 | </cell> |
| 686 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 687 | \begin_inset Text |
| 688 | |
| 689 | \layout Standard |
| 690 | |
| 691 | |
| 692 | \size small |
| 693 | Enable lexer debugging during the ASN.1 parsing stage. |
| 694 | \end_inset |
| 695 | </cell> |
| 696 | </row> |
| 697 | <row topline="true"> |
| 698 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 699 | \begin_inset Text |
| 700 | |
| 701 | \layout Standard |
| 702 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 703 | |
| 704 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 705 | -Wdebug-fixer |
| 706 | \end_inset |
| 707 | </cell> |
| 708 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 709 | \begin_inset Text |
| 710 | |
| 711 | \layout Standard |
| 712 | |
| 713 | |
| 714 | \size small |
| 715 | Enable ASN.1 syntax tree fixer debugging during the fixing stage. |
| 716 | \end_inset |
| 717 | </cell> |
| 718 | </row> |
| 719 | <row topline="true" bottomline="true"> |
| 720 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 721 | \begin_inset Text |
| 722 | |
| 723 | \layout Standard |
| 724 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 725 | |
| 726 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 727 | -Wdebug-compiler |
| 728 | \end_inset |
| 729 | </cell> |
| 730 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 731 | \begin_inset Text |
| 732 | |
| 733 | \layout Standard |
| 734 | |
| 735 | |
| 736 | \size small |
| 737 | Enable debugging during the actual compile time. |
| 738 | \end_inset |
| 739 | </cell> |
| 740 | </row> |
| 741 | <row topline="true"> |
| 742 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 743 | \begin_inset Text |
| 744 | |
| 745 | \layout Standard |
| 746 | |
| 747 | |
| 748 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 749 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 750 | Language Options |
| 751 | \end_inset |
| 752 | </cell> |
| 753 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 754 | \begin_inset Text |
| 755 | |
| 756 | \layout Standard |
| 757 | |
| 758 | |
| 759 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 760 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 761 | Description |
| 762 | \end_inset |
| 763 | </cell> |
| 764 | </row> |
| 765 | <row topline="true"> |
| 766 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 767 | \begin_inset Text |
| 768 | |
| 769 | \layout Standard |
| 770 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 771 | |
| 772 | \size small |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 773 | -fall-defs-global |
| 774 | \end_inset |
| 775 | </cell> |
| 776 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 777 | \begin_inset Text |
| 778 | |
| 779 | \layout Standard |
| 780 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 781 | |
| 782 | \size small |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 783 | Normally the compiler hides the definitions (asn_DEF_xxx) of the inner structure |
| 784 | elements (members of SEQUENCE, SET and other types). |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 785 | This option makes all such definitions global. |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 786 | Enabling this option may pollute the namespace by making lots of asn_DEF_xxx |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 787 | structures globally visible, but will allow you to manipulate (encode and |
| 788 | decode) the individual members of any complex ASN.1 structure. |
| 789 | \end_inset |
| 790 | </cell> |
| 791 | </row> |
| 792 | <row topline="true"> |
| 793 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 794 | \begin_inset Text |
| 795 | |
| 796 | \layout Standard |
| 797 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 798 | |
| 799 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 800 | -fbless-SIZE |
| 801 | \end_inset |
| 802 | </cell> |
| 803 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 804 | \begin_inset Text |
| 805 | |
| 806 | \layout Standard |
| 807 | |
| 808 | |
| 809 | \size small |
| 810 | Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which |
| 811 | this constraint is normally prohibited by the standard. |
| 812 | This is a violation of an ASN.1 standard and compiler may fail to produce |
| 813 | the meaningful code. |
| 814 | \end_inset |
| 815 | </cell> |
| 816 | </row> |
| 817 | <row topline="true"> |
| 818 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 819 | \begin_inset Text |
| 820 | |
| 821 | \layout Standard |
| 822 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 823 | |
| 824 | \size small |
| 825 | -fcompound-names |
| 826 | \end_inset |
| 827 | </cell> |
| 828 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 829 | \begin_inset Text |
| 830 | |
| 831 | \layout Standard |
| 832 | |
| 833 | |
| 834 | \size small |
| 835 | Use complex names for C structures. |
| 836 | Using complex names prevents name clashes in case the module reuses the |
| 837 | same identifiers in multiple contexts. |
| 838 | \end_inset |
| 839 | </cell> |
| 840 | </row> |
| 841 | <row topline="true"> |
| 842 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 843 | \begin_inset Text |
| 844 | |
| 845 | \layout Standard |
| 846 | |
| 847 | |
| 848 | \size small |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 849 | -fnative-types |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 850 | \end_inset |
| 851 | </cell> |
| 852 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 853 | \begin_inset Text |
| 854 | |
| 855 | \layout Standard |
| 856 | |
| 857 | |
| 858 | \size small |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 859 | Use the native machine's data types (int, double) whenever possible, instead |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 860 | of the compound INTEGER_t, ENUMERATED_t and REAL_t types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 861 | |
| 862 | \end_inset |
| 863 | </cell> |
| 864 | </row> |
| 865 | <row topline="true"> |
| 866 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 867 | \begin_inset Text |
| 868 | |
| 869 | \layout Standard |
| 870 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 871 | |
| 872 | \size small |
vlm | bfc49bd | 2004-09-26 13:13:13 +0000 | [diff] [blame] | 873 | -fno-constraints |
| 874 | \end_inset |
| 875 | </cell> |
| 876 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 877 | \begin_inset Text |
| 878 | |
| 879 | \layout Standard |
| 880 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 881 | |
| 882 | \size small |
vlm | bfc49bd | 2004-09-26 13:13:13 +0000 | [diff] [blame] | 883 | Do not generate ASN.1 subtype constraint checking code. |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 884 | This may produce a shorter executable. |
vlm | bfc49bd | 2004-09-26 13:13:13 +0000 | [diff] [blame] | 885 | \end_inset |
| 886 | </cell> |
| 887 | </row> |
| 888 | <row topline="true"> |
| 889 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 890 | \begin_inset Text |
| 891 | |
| 892 | \layout Standard |
| 893 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 894 | |
| 895 | \size small |
| 896 | -fno-include-deps |
| 897 | \end_inset |
| 898 | </cell> |
| 899 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 900 | \begin_inset Text |
| 901 | |
| 902 | \layout Standard |
| 903 | |
| 904 | |
| 905 | \size small |
| 906 | Do not generate courtesy #include lines for non-critical dependencies. |
| 907 | \end_inset |
| 908 | </cell> |
| 909 | </row> |
| 910 | <row topline="true"> |
| 911 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 912 | \begin_inset Text |
| 913 | |
| 914 | \layout Standard |
| 915 | |
| 916 | |
| 917 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 918 | -funnamed-unions |
| 919 | \end_inset |
| 920 | </cell> |
| 921 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 922 | \begin_inset Text |
| 923 | |
| 924 | \layout Standard |
| 925 | |
| 926 | |
| 927 | \size small |
| 928 | Enable unnamed unions in the definitions of target language's structures. |
| 929 | \end_inset |
| 930 | </cell> |
| 931 | </row> |
| 932 | <row topline="true" bottomline="true"> |
| 933 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 934 | \begin_inset Text |
| 935 | |
| 936 | \layout Standard |
| 937 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 938 | |
| 939 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 940 | -ftypes88 |
| 941 | \end_inset |
| 942 | </cell> |
| 943 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 944 | \begin_inset Text |
| 945 | |
| 946 | \layout Standard |
| 947 | |
| 948 | |
| 949 | \size small |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 950 | Pretend to support only ASN.1:1988 embedded types. |
| 951 | Certain reserved words, such as UniversalString and BMPString, become ordinary |
| 952 | type references and may be redefined by the specification. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 953 | \end_inset |
| 954 | </cell> |
| 955 | </row> |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 956 | <row topline="true" newpage="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 957 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 958 | \begin_inset Text |
| 959 | |
| 960 | \layout Standard |
| 961 | |
| 962 | |
| 963 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 964 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 965 | Output Options |
| 966 | \end_inset |
| 967 | </cell> |
| 968 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 969 | \begin_inset Text |
| 970 | |
| 971 | \layout Standard |
| 972 | |
| 973 | |
| 974 | \series bold |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 975 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 976 | Description |
| 977 | \end_inset |
| 978 | </cell> |
| 979 | </row> |
| 980 | <row topline="true"> |
| 981 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 982 | \begin_inset Text |
| 983 | |
| 984 | \layout Standard |
| 985 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 986 | |
| 987 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 988 | -print-constraints |
| 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 |
| 998 | When -EF are also specified, this option forces the compiler to explain |
| 999 | its internal understanding of subtype constraints. |
| 1000 | \end_inset |
| 1001 | </cell> |
| 1002 | </row> |
| 1003 | <row topline="true" bottomline="true"> |
| 1004 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1005 | \begin_inset Text |
| 1006 | |
| 1007 | \layout Standard |
| 1008 | |
vlm | 37d47c0 | 2005-03-05 01:07:04 +0000 | [diff] [blame] | 1009 | |
| 1010 | \size small |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1011 | -print-lines |
| 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 | \size small |
| 1021 | Generate "-- #line" comments in -E output. |
| 1022 | \end_inset |
| 1023 | </cell> |
| 1024 | </row> |
| 1025 | </lyxtabular> |
| 1026 | |
| 1027 | \end_inset |
| 1028 | |
| 1029 | |
| 1030 | \layout Caption |
| 1031 | |
| 1032 | |
| 1033 | \begin_inset LatexCommand \label{cap:asn1c-cmdopts} |
| 1034 | |
| 1035 | \end_inset |
| 1036 | |
| 1037 | The list of asn1c command line options |
| 1038 | \end_inset |
| 1039 | |
| 1040 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1041 | \layout Chapter |
| 1042 | |
| 1043 | Using the ASN.1 Compiler |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1044 | \layout Section |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1045 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1046 | Invoking the ASN.1 helper code |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1047 | \begin_inset OptArg |
| 1048 | collapsed true |
| 1049 | |
| 1050 | \layout Standard |
| 1051 | |
| 1052 | Invoking the helper code |
| 1053 | \end_inset |
| 1054 | |
| 1055 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1056 | \layout Standard |
| 1057 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1058 | First of all, you should include one or more header files into your application. |
| 1059 | Typically, it is enough to include the header file of the main PDU type. |
| 1060 | For our Rectangle module, including the Rectangle.h file is sufficient: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1061 | \layout LyX-Code |
| 1062 | |
| 1063 | #include <Rectangle.h> |
| 1064 | \layout Standard |
| 1065 | |
| 1066 | The header files defines the C structure corresponding to the ASN.1 definition |
| 1067 | of a rectangle and the declaration of the ASN.1 type descriptor, which is |
| 1068 | used as an argument to most of the functions provided by the ASN.1 module. |
| 1069 | For example, here is the code which frees the Rectangle_t structure: |
| 1070 | \layout LyX-Code |
| 1071 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1072 | Rectangle_t *rect = ...; |
| 1073 | \layout LyX-Code |
| 1074 | |
| 1075 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1076 | \layout LyX-Code |
| 1077 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1078 | asn_DEF_Rectangle->free_struct(&asn_DEF_Rectangle, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1079 | \layout LyX-Code |
| 1080 | |
| 1081 | rect, 0); |
| 1082 | \layout Standard |
| 1083 | |
| 1084 | This code defines a |
| 1085 | \emph on |
| 1086 | rect |
| 1087 | \emph default |
| 1088 | pointer which points to the Rectangle_t structure which needs to be freed. |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1089 | The second line invokes the generic |
| 1090 | \emph on |
| 1091 | free_struct() |
| 1092 | \emph default |
| 1093 | routine created specifically for this Rectangle_t structure. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1094 | The |
| 1095 | \emph on |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1096 | asn_DEF_Rectangle |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1097 | \emph default |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1098 | is the type descriptor, which holds a collection of routines to deal with |
| 1099 | the Rectangle_t structure. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1100 | \layout Standard |
| 1101 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1102 | The following member functions of the asn_DEF_Rectangle type descriptor |
| 1103 | are of interest: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1104 | \layout Description |
| 1105 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1106 | ber_decoder This is the generic |
| 1107 | \emph on |
| 1108 | restartable |
| 1109 | \begin_inset Foot |
| 1110 | collapsed false |
| 1111 | |
| 1112 | \layout Standard |
| 1113 | |
| 1114 | Restartable means that if the decoder encounters the end of the buffer, |
| 1115 | it will fail, but may later be invoked again with the rest of the buffer |
| 1116 | to continue decoding. |
| 1117 | \end_inset |
| 1118 | |
| 1119 | |
| 1120 | \emph default |
| 1121 | BER decoder (Basic Encoding Rules). |
| 1122 | This decoder would create and/or fill the target structure for you. |
| 1123 | Please refer to Section |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1124 | \begin_inset LatexCommand \vref{sub:Decoding-BER} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1125 | |
| 1126 | \end_inset |
| 1127 | |
| 1128 | . |
| 1129 | \layout Description |
| 1130 | |
| 1131 | der_encoder This is the generic DER encoder (Distinguished Encoding Rules). |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1132 | This encoder will take the target structure and encode it into a series |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1133 | of bytes. |
| 1134 | Please refer to Section |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1135 | \begin_inset LatexCommand \vref{sub:Encoding-DER} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1136 | |
| 1137 | \end_inset |
| 1138 | |
| 1139 | . |
| 1140 | \layout Description |
| 1141 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1142 | xer_encoder This is the XER encoder (XML Encoding Rules). |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1143 | This encoder will take the target structure and represent it as an XML |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1144 | (text) document using either BASIC-XER or CANONICAL-XER encoding rules. |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1145 | Please refer to Section |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1146 | \begin_inset LatexCommand \vref{sub:Encoding-XER} |
| 1147 | |
| 1148 | \end_inset |
| 1149 | |
| 1150 | . |
| 1151 | \layout Description |
| 1152 | |
| 1153 | xer_decoder This is the generic XER decoder. |
| 1154 | It takes both BASIC-XER or CANONICAL-XER encodings and deserializes the |
| 1155 | data into a local, machine-dependent representation. |
| 1156 | Please refer to Section |
| 1157 | \begin_inset LatexCommand \vref{sub:Decoding-XER} |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1158 | |
| 1159 | \end_inset |
| 1160 | |
| 1161 | . |
| 1162 | \layout Description |
| 1163 | |
| 1164 | check_constraints Check that the contents of the target structure are semantical |
| 1165 | ly valid and constrained to appropriate implicit or explicit subtype constraints. |
| 1166 | Please refer to Section |
| 1167 | \begin_inset LatexCommand \vref{sub:Validating-the-target} |
| 1168 | |
| 1169 | \end_inset |
| 1170 | |
| 1171 | . |
| 1172 | \layout Description |
| 1173 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1174 | print_struct This function convert the contents of the passed target structure |
| 1175 | into human readable form. |
| 1176 | This form is not formal and cannot be converted back into the structure, |
| 1177 | but it may turn out to be useful for debugging or quick-n-dirty printing. |
| 1178 | Please refer to Section |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1179 | \begin_inset LatexCommand \vref{sub:Printing-the-target} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1180 | |
| 1181 | \end_inset |
| 1182 | |
| 1183 | . |
| 1184 | \layout Description |
| 1185 | |
| 1186 | free_struct This is a generic disposal which frees the target structure. |
| 1187 | Please refer to Section |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1188 | \begin_inset LatexCommand \vref{sub:Freeing-the-target} |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1189 | |
| 1190 | \end_inset |
| 1191 | |
| 1192 | . |
| 1193 | \layout Standard |
| 1194 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1195 | Each of the above function takes the type descriptor ( |
| 1196 | \emph on |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1197 | asn_DEF_\SpecialChar \ldots{} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1198 | |
| 1199 | \emph default |
| 1200 | ) and the target structure ( |
| 1201 | \emph on |
| 1202 | rect |
| 1203 | \emph default |
| 1204 | , in the above example). |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1205 | \layout Subsection |
| 1206 | |
| 1207 | |
| 1208 | \begin_inset LatexCommand \label{sub:Decoding-BER} |
| 1209 | |
| 1210 | \end_inset |
| 1211 | |
| 1212 | Decoding BER |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1213 | \layout Standard |
| 1214 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1215 | The Basic Encoding Rules describe the most widely used (by the ASN.1 community) |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1216 | way to encode and decode a given structure in a machine-independent way. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1217 | Several other encoding rules (CER, DER) define a more restrictive versions |
| 1218 | of BER, so the generic BER parser is also capable of decoding the data |
| 1219 | encoded by CER and DER encoders. |
| 1220 | The opposite is not true. |
| 1221 | \layout Standard |
| 1222 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1223 | |
| 1224 | \emph on |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1225 | The ASN.1 compiler provides the generic BER decoder which is implicitly capable |
| 1226 | of decoding BER, CER and DER encoded data. |
| 1227 | \layout Standard |
| 1228 | |
| 1229 | The decoder is restartable (stream-oriented), which means that in case the |
| 1230 | buffer has less data than it is expected, the decoder will process whatever |
| 1231 | there is available and ask for more data to be provided. |
| 1232 | Please note that the decoder may actually process less data than it was |
| 1233 | given in the buffer, which means that you must be able to make the next |
| 1234 | buffer contain the unprocessed part of the previous buffer. |
| 1235 | \layout Standard |
| 1236 | |
| 1237 | Suppose, you have two buffers of encoded data: 100 bytes and 200 bytes. |
| 1238 | \layout Itemize |
| 1239 | |
| 1240 | You may concatenate these buffers and feed the BER decoder with 300 bytes |
| 1241 | of data, or |
| 1242 | \layout Itemize |
| 1243 | |
| 1244 | You may feed it the first buffer of 100 bytes of data, realize that the |
| 1245 | ber_decoder consumed only 95 bytes from it and later feed the decoder with |
| 1246 | 205 bytes buffer which consists of 5 unprocessed bytes from the first buffer |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1247 | and the additional 200 bytes from the second buffer. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1248 | \layout Standard |
| 1249 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1250 | This is not as convenient as it could be (like, the BER encoder could consume |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1251 | the whole 100 bytes and keep these 5 bytes in some temporary storage), |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1252 | but in case of existing stream based processing it might actually fit well |
| 1253 | into existing algorithm. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1254 | Suggestions are welcome. |
| 1255 | \layout Standard |
| 1256 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1257 | Here is the simplest example of BER decoding. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1258 | \layout LyX-Code |
| 1259 | |
| 1260 | Rectangle_t * |
| 1261 | \layout LyX-Code |
| 1262 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1263 | simple_deserializer(const void *buffer, size_t buf_size) { |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1264 | \layout LyX-Code |
| 1265 | |
| 1266 | Rectangle_t *rect = 0; /* Note this 0! */ |
| 1267 | \layout LyX-Code |
| 1268 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 1269 | asn_dec_rval_t rval; |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1270 | \layout LyX-Code |
| 1271 | |
| 1272 | |
| 1273 | \layout LyX-Code |
| 1274 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1275 | rval = |
| 1276 | \series bold |
| 1277 | asn_DEF_Rectangle->ber_decoder |
| 1278 | \series default |
| 1279 | (0, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1280 | \layout LyX-Code |
| 1281 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1282 | &asn_DEF_Rectangle, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1283 | \layout LyX-Code |
| 1284 | |
| 1285 | (void **)&rect, |
| 1286 | \layout LyX-Code |
| 1287 | |
| 1288 | buffer, buf_size, |
| 1289 | \layout LyX-Code |
| 1290 | |
| 1291 | 0); |
| 1292 | \layout LyX-Code |
| 1293 | |
| 1294 | |
| 1295 | \layout LyX-Code |
| 1296 | |
| 1297 | if(rval |
| 1298 | \series bold |
| 1299 | .code |
| 1300 | \series default |
| 1301 | == RC_OK) { |
| 1302 | \layout LyX-Code |
| 1303 | |
| 1304 | return rect; /* Decoding succeeded */ |
| 1305 | \layout LyX-Code |
| 1306 | |
| 1307 | } else { |
| 1308 | \layout LyX-Code |
| 1309 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1310 | /* Free partially decoded rect */ |
| 1311 | \layout LyX-Code |
| 1312 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1313 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1314 | \layout LyX-Code |
| 1315 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1316 | &asn_DEF_Rectangle, rect, 0); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1317 | \layout LyX-Code |
| 1318 | |
| 1319 | return 0; |
| 1320 | \layout LyX-Code |
| 1321 | |
| 1322 | } |
| 1323 | \layout LyX-Code |
| 1324 | |
| 1325 | } |
| 1326 | \layout Standard |
| 1327 | |
| 1328 | The code above defines a function, |
| 1329 | \emph on |
| 1330 | simple_deserializer |
| 1331 | \emph default |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1332 | , which takes a buffer and its length and is expected to return a pointer |
| 1333 | to the Rectangle_t structure. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1334 | Inside, it tries to convert the bytes passed into the target structure |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1335 | (rect) using the BER decoder and returns the rect pointer afterwards. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1336 | If the structure cannot be deserialized, it frees the memory which might |
| 1337 | be left allocated by the unfinished |
| 1338 | \emph on |
| 1339 | ber_decoder |
| 1340 | \emph default |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1341 | routine and returns 0 (no data). |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1342 | (This |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1343 | \series bold |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1344 | freeing is necessary |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1345 | \series default |
| 1346 | because the ber_decoder is a restartable procedure, and may fail just because |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1347 | there is more data needs to be provided before decoding could be finalized). |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1348 | The code above obviously does not take into account the way the |
| 1349 | \emph on |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1350 | ber_decoder() |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1351 | \emph default |
| 1352 | failed, so the freeing is necessary because the part of the buffer may |
| 1353 | already be decoded into the structure by the time something goes wrong. |
| 1354 | \layout Standard |
| 1355 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1356 | A little less wordy would be to invoke a globally available |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1357 | \emph on |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1358 | ber_decode() |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1359 | \emph default |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1360 | function instead of dereferencing the asn_DEF_Rectangle type descriptor: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1361 | \layout LyX-Code |
| 1362 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1363 | rval = ber_decode(0, &asn_DEF_Rectangle, (void **)&rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1364 | \layout LyX-Code |
| 1365 | |
| 1366 | buffer, buf_size); |
| 1367 | \layout Standard |
| 1368 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1369 | Note that the initial (asn_DEF_Rectangle->ber_decoder) reference is gone, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1370 | and also the last argument (0) is no longer necessary. |
| 1371 | \layout Standard |
| 1372 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1373 | These two ways of BER decoder invocations are fully equivalent. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1374 | \layout Standard |
| 1375 | |
| 1376 | The BER de |
| 1377 | \emph on |
| 1378 | coder |
| 1379 | \emph default |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1380 | may fail because of ( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1381 | \emph on |
| 1382 | the following RC_\SpecialChar \ldots{} |
| 1383 | codes are defined in ber_decoder.h |
| 1384 | \emph default |
| 1385 | ): |
| 1386 | \layout Itemize |
| 1387 | |
| 1388 | RC_WMORE: There is more data expected than it is provided (stream mode continuat |
| 1389 | ion feature); |
| 1390 | \layout Itemize |
| 1391 | |
| 1392 | RC_FAIL: General failure to decode the buffer; |
| 1393 | \layout Itemize |
| 1394 | |
| 1395 | \SpecialChar \ldots{} |
| 1396 | other codes may be defined as well. |
| 1397 | \layout Standard |
| 1398 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 1399 | Together with the return code (.code) the asn_dec_rval_t type contains the |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1400 | number of bytes which is consumed from the buffer. |
| 1401 | In the previous hypothetical example of two buffers (of 100 and 200 bytes), |
| 1402 | the first call to ber_decode() would return with .code = RC_WMORE and .consumed |
| 1403 | = 95. |
| 1404 | The .consumed field of the BER decoder return value is |
| 1405 | \series bold |
| 1406 | always |
| 1407 | \series default |
| 1408 | valid, even if the decoder succeeds or fails with any other return code. |
| 1409 | \layout Standard |
| 1410 | |
| 1411 | Please look into ber_decoder.h for the precise definition of ber_decode() |
| 1412 | and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1413 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1414 | |
| 1415 | |
| 1416 | \begin_inset LatexCommand \label{sub:Encoding-DER} |
| 1417 | |
| 1418 | \end_inset |
| 1419 | |
| 1420 | Encoding DER |
| 1421 | \layout Standard |
| 1422 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1423 | The Distinguished Encoding Rules is the |
| 1424 | \emph on |
| 1425 | canonical |
| 1426 | \emph default |
| 1427 | variant of BER encoding rules. |
| 1428 | The DER is best suited to encode the structures where all the lengths are |
| 1429 | known beforehand. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1430 | This is probably exactly how you want to encode: either after a BER decoding |
| 1431 | or after a manual fill-up, the target structure contains the data which |
| 1432 | size is implicitly known before encoding. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1433 | Among other uses, the DER encoding is used to encode X.509 certificates. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1434 | \layout Standard |
| 1435 | |
| 1436 | As with BER decoder, the DER encoder may be invoked either directly from |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1437 | the ASN.1 type descriptor (asn_DEF_Rectangle) or from the stand-alone function, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1438 | which is somewhat simpler: |
| 1439 | \layout LyX-Code |
| 1440 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1441 | |
| 1442 | \layout LyX-Code |
| 1443 | |
| 1444 | /* |
| 1445 | \layout LyX-Code |
| 1446 | |
| 1447 | * This is the serializer itself, |
| 1448 | \layout LyX-Code |
| 1449 | |
| 1450 | * it supplies the DER encoder with the |
| 1451 | \layout LyX-Code |
| 1452 | |
| 1453 | * pointer to the custom output function. |
| 1454 | \layout LyX-Code |
| 1455 | |
| 1456 | */ |
| 1457 | \layout LyX-Code |
| 1458 | |
| 1459 | ssize_t |
| 1460 | \layout LyX-Code |
| 1461 | |
| 1462 | simple_serializer(FILE *ostream, Rectangle_t *rect) { |
| 1463 | \layout LyX-Code |
| 1464 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1465 | asn_enc_rval_t er; /* Encoder return value */ |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1466 | \layout LyX-Code |
| 1467 | |
| 1468 | |
| 1469 | \layout LyX-Code |
| 1470 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1471 | er = der_encode(&asn_DEF_Rect, rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1472 | \layout LyX-Code |
| 1473 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1474 | write_stream, ostream); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1475 | \layout LyX-Code |
| 1476 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1477 | if(er. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1478 | \series bold |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1479 | encoded |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1480 | \series default |
| 1481 | == -1) { |
| 1482 | \layout LyX-Code |
| 1483 | |
| 1484 | /* |
| 1485 | \layout LyX-Code |
| 1486 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1487 | * Failed to encode the rectangle data. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1488 | \layout LyX-Code |
| 1489 | |
| 1490 | */ |
| 1491 | \layout LyX-Code |
| 1492 | |
| 1493 | fprintf(stderr, |
| 1494 | \begin_inset Quotes sld |
| 1495 | \end_inset |
| 1496 | |
| 1497 | Cannot encode %s: %s |
| 1498 | \backslash |
| 1499 | n |
| 1500 | \begin_inset Quotes srd |
| 1501 | \end_inset |
| 1502 | |
| 1503 | , |
| 1504 | \layout LyX-Code |
| 1505 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1506 | er. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1507 | \series bold |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1508 | failed_type |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1509 | \series default |
| 1510 | ->name, |
| 1511 | \layout LyX-Code |
| 1512 | |
| 1513 | strerror(errno)); |
| 1514 | \layout LyX-Code |
| 1515 | |
| 1516 | return -1; |
| 1517 | \layout LyX-Code |
| 1518 | |
| 1519 | } else { |
| 1520 | \layout LyX-Code |
| 1521 | |
| 1522 | /* Return the number of bytes */ |
| 1523 | \layout LyX-Code |
| 1524 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1525 | return er.encoded; |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1526 | \layout LyX-Code |
| 1527 | |
| 1528 | } |
| 1529 | \layout LyX-Code |
| 1530 | |
| 1531 | } |
| 1532 | \layout Standard |
| 1533 | |
| 1534 | As you see, the DER encoder does not write into some sort of buffer or something. |
| 1535 | It just invokes the custom function (possible, multiple times) which would |
| 1536 | save the data into appropriate storage. |
| 1537 | The optional argument |
| 1538 | \emph on |
| 1539 | app_key |
| 1540 | \emph default |
| 1541 | is opaque for the DER encoder code and just used by |
| 1542 | \emph on |
| 1543 | _write_stream() |
| 1544 | \emph default |
| 1545 | as the pointer to the appropriate output stream to be used. |
| 1546 | \layout Standard |
| 1547 | |
| 1548 | If the custom write function is not given (passed as 0), then the DER encoder |
| 1549 | will essentially do the same thing (i.e., encode the data) but no callbacks |
| 1550 | will be invoked (so the data goes nowhere). |
| 1551 | It may prove useful to determine the size of the structure's encoding before |
| 1552 | actually doing the encoding |
| 1553 | \begin_inset Foot |
| 1554 | collapsed false |
| 1555 | |
| 1556 | \layout Standard |
| 1557 | |
| 1558 | It is actually faster too: the encoder might skip over some computations |
| 1559 | which aren't important for the size determination. |
| 1560 | \end_inset |
| 1561 | |
| 1562 | . |
| 1563 | \layout Standard |
| 1564 | |
| 1565 | Please look into der_encoder.h for the precise definition of der_encode() |
| 1566 | and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1567 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1568 | |
| 1569 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1570 | \begin_inset LatexCommand \label{sub:Encoding-XER} |
| 1571 | |
| 1572 | \end_inset |
| 1573 | |
| 1574 | Encoding XER |
| 1575 | \layout Standard |
| 1576 | |
| 1577 | The XER stands for XML Encoding Rules, where XML, in turn, is eXtensible |
| 1578 | Markup Language, a text-based format for information exchange. |
| 1579 | The encoder routine API comes in two flavors: stdio-based and callback-based. |
| 1580 | With the callback-based encoder, the encoding process is very similar to |
| 1581 | the DER one, described in Section |
| 1582 | \begin_inset LatexCommand \vref{sub:Encoding-DER} |
| 1583 | |
| 1584 | \end_inset |
| 1585 | |
| 1586 | . |
| 1587 | The following example uses the definition of write_stream() from up there. |
| 1588 | \layout LyX-Code |
| 1589 | |
| 1590 | /* |
| 1591 | \layout LyX-Code |
| 1592 | |
| 1593 | * This procedure generates the XML document |
| 1594 | \layout LyX-Code |
| 1595 | |
| 1596 | * by invoking the XER encoder. |
| 1597 | \layout LyX-Code |
| 1598 | |
| 1599 | * NOTE: Do not copy this code verbatim! |
| 1600 | \layout LyX-Code |
| 1601 | |
| 1602 | * If the stdio output is necessary, |
| 1603 | \layout LyX-Code |
| 1604 | |
| 1605 | * use the xer_fprint() procedure instead. |
| 1606 | \layout LyX-Code |
| 1607 | |
| 1608 | * See Section |
| 1609 | \begin_inset LatexCommand \vref{sub:Printing-the-target} |
| 1610 | |
| 1611 | \end_inset |
| 1612 | |
| 1613 | . |
| 1614 | \layout LyX-Code |
| 1615 | |
| 1616 | */ |
| 1617 | \layout LyX-Code |
| 1618 | |
| 1619 | int |
| 1620 | \layout LyX-Code |
| 1621 | |
| 1622 | print_as_XML(FILE *ostream, Rectangle_t *rect) { |
| 1623 | \layout LyX-Code |
| 1624 | |
| 1625 | asn_enc_rval_t er; /* Encoder return value */ |
| 1626 | \layout LyX-Code |
| 1627 | |
| 1628 | |
| 1629 | \layout LyX-Code |
| 1630 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1631 | er = xer_encode(&asn_DEF_Rectangle, rect, |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1632 | \layout LyX-Code |
| 1633 | |
| 1634 | XER_F_BASIC, /* BASIC-XER or CANONICAL-XER */ |
| 1635 | \layout LyX-Code |
| 1636 | |
| 1637 | write_stream, ostream); |
| 1638 | \layout LyX-Code |
| 1639 | |
| 1640 | |
| 1641 | \layout LyX-Code |
| 1642 | |
| 1643 | return (er.encoded == -1) ? -1 : 0; |
| 1644 | \layout LyX-Code |
| 1645 | |
| 1646 | } |
| 1647 | \layout Standard |
| 1648 | |
| 1649 | Please look into xer_encoder.h for the precise definition of xer_encode() |
| 1650 | and related types. |
| 1651 | \layout Standard |
| 1652 | |
| 1653 | See Section |
| 1654 | \begin_inset LatexCommand \ref{sub:Printing-the-target} |
| 1655 | |
| 1656 | \end_inset |
| 1657 | |
| 1658 | for the example of stdio-based XML encoder and other pretty-printing suggestion |
| 1659 | s. |
| 1660 | \layout Subsection |
| 1661 | |
| 1662 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1663 | \begin_inset LatexCommand \label{sub:Decoding-XER} |
| 1664 | |
| 1665 | \end_inset |
| 1666 | |
| 1667 | Decoding XER |
| 1668 | \layout Standard |
| 1669 | |
| 1670 | The data encoded using the XER rules can be subsequently decoded using the |
| 1671 | xer_decode() API call: |
| 1672 | \layout LyX-Code |
| 1673 | |
| 1674 | Rectangle_t * |
| 1675 | \layout LyX-Code |
| 1676 | |
| 1677 | XML_to_Rectangle(const void *buffer, size_t buf_size) { |
| 1678 | \layout LyX-Code |
| 1679 | |
| 1680 | Rectangle_t *rect = 0; /* Note this 0! */ |
| 1681 | \layout LyX-Code |
| 1682 | |
| 1683 | asn_dec_rval_t rval; |
| 1684 | \layout LyX-Code |
| 1685 | |
| 1686 | |
| 1687 | \layout LyX-Code |
| 1688 | |
| 1689 | rval = xer_decode(0, &asn_DEF_Rectangle, (void **)&rect, |
| 1690 | \layout LyX-Code |
| 1691 | |
| 1692 | buffer, buf_size); |
| 1693 | \layout LyX-Code |
| 1694 | |
| 1695 | if(rval |
| 1696 | \series bold |
| 1697 | .code |
| 1698 | \series default |
| 1699 | == RC_OK) { |
| 1700 | \layout LyX-Code |
| 1701 | |
| 1702 | return rect; /* Decoding succeeded */ |
| 1703 | \layout LyX-Code |
| 1704 | |
| 1705 | } else { |
| 1706 | \layout LyX-Code |
| 1707 | |
| 1708 | /* Free partially decoded rect */ |
| 1709 | \layout LyX-Code |
| 1710 | |
| 1711 | asn_DEF_Rectangle->free_struct( |
| 1712 | \layout LyX-Code |
| 1713 | |
| 1714 | &asn_DEF_Rectangle, rect, 0); |
| 1715 | \layout LyX-Code |
| 1716 | |
| 1717 | return 0; |
| 1718 | \layout LyX-Code |
| 1719 | |
| 1720 | } |
| 1721 | \layout LyX-Code |
| 1722 | |
| 1723 | } |
| 1724 | \layout Standard |
| 1725 | |
| 1726 | The decoder takes both BASIC-XER and CANONICAL-XER encodings. |
| 1727 | \layout Standard |
| 1728 | |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1729 | The decoder shares its data consumption properties with BER decoder; please |
| 1730 | read the Section |
| 1731 | \begin_inset LatexCommand \vref{sub:Decoding-BER} |
| 1732 | |
| 1733 | \end_inset |
| 1734 | |
| 1735 | to know more. |
| 1736 | \layout Standard |
| 1737 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1738 | Please look into xer_decoder.h for the precise definition of xer_decode() |
| 1739 | and related types. |
| 1740 | \layout Subsection |
| 1741 | |
| 1742 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1743 | \begin_inset LatexCommand \label{sub:Validating-the-target} |
| 1744 | |
| 1745 | \end_inset |
| 1746 | |
| 1747 | Validating the target structure |
| 1748 | \layout Standard |
| 1749 | |
| 1750 | Sometimes the target structure needs to be validated. |
| 1751 | For example, if the structure was created by the application (as opposed |
| 1752 | to being decoded from some external source), some important information |
| 1753 | required by the ASN.1 specification might be missing. |
| 1754 | On the other hand, the successful decoding of the data from some external |
| 1755 | source does not necessarily mean that the data is fully valid either. |
| 1756 | It might well be the case that the specification describes some subtype |
| 1757 | constraints that were not taken into account during decoding, and it would |
| 1758 | actually be useful to perform the last check when the data is ready to |
| 1759 | be encoded or when the data has just been decoded to ensure its validity |
| 1760 | according to some stricter rules. |
| 1761 | \layout Standard |
| 1762 | |
| 1763 | The asn_check_constraints() function checks the type for various implicit |
| 1764 | and explicit constraints. |
| 1765 | It is recommended to use asn_check_constraints() function after each decoding |
| 1766 | and before each encoding. |
| 1767 | \layout Standard |
| 1768 | |
| 1769 | Please look into constraints.h for the precise definition of asn_check_constraint |
| 1770 | s() and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1771 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1772 | |
| 1773 | |
| 1774 | \begin_inset LatexCommand \label{sub:Printing-the-target} |
| 1775 | |
| 1776 | \end_inset |
| 1777 | |
| 1778 | Printing the target structure |
| 1779 | \layout Standard |
| 1780 | |
| 1781 | There are two ways to print the target structure: either invoke the print_struct |
| 1782 | member of the ASN.1 type descriptor, or using the asn_fprint() function, |
| 1783 | which is a simpler wrapper of the former: |
| 1784 | \layout LyX-Code |
| 1785 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1786 | asn_fprint(stdout, &asn_DEF_Rectangle, rect); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1787 | \layout Standard |
| 1788 | |
| 1789 | Please look into constr_TYPE.h for the precise definition of asn_fprint() |
| 1790 | and related types. |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1791 | \layout Standard |
| 1792 | |
| 1793 | Another practical alternative to this custom format printing would be to |
| 1794 | invoke XER encoder. |
| 1795 | The default BASIC-XER encoder performs reasonable formatting for the output |
| 1796 | to be useful and human readable. |
| 1797 | To invoke the XER decoder in a manner similar to asn_fprint(), use the |
| 1798 | xer_fprint() call: |
| 1799 | \layout LyX-Code |
| 1800 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1801 | xer_fprint(stdout, &asn_DEF_Rectangle, rect); |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 1802 | \layout Standard |
| 1803 | |
| 1804 | See Section |
| 1805 | \begin_inset LatexCommand \vref{sub:Encoding-XER} |
| 1806 | |
| 1807 | \end_inset |
| 1808 | |
| 1809 | for XML-related details. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1810 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1811 | |
| 1812 | |
| 1813 | \begin_inset LatexCommand \label{sub:Freeing-the-target} |
| 1814 | |
| 1815 | \end_inset |
| 1816 | |
| 1817 | Freeing the target structure |
| 1818 | \layout Standard |
| 1819 | |
| 1820 | Freeing the structure is slightly more complex than it may seem to. |
| 1821 | When the ASN.1 structure is freed, all the members of the structure and |
| 1822 | their submembers etc etc are recursively freed too. |
| 1823 | But it might not be feasible to free the structure itself. |
| 1824 | Consider the following case: |
| 1825 | \layout LyX-Code |
| 1826 | |
| 1827 | struct my_figure { /* The custom structure */ |
| 1828 | \layout LyX-Code |
| 1829 | |
| 1830 | int flags; /* <some custom member> */ |
| 1831 | \layout LyX-Code |
| 1832 | |
| 1833 | /* The type is generated by the ASN.1 compiler */ |
| 1834 | \layout LyX-Code |
| 1835 | |
| 1836 | |
| 1837 | \emph on |
| 1838 | Rectangle_t rect; |
| 1839 | \layout LyX-Code |
| 1840 | |
| 1841 | /* other members of the structure */ |
| 1842 | \layout LyX-Code |
| 1843 | |
| 1844 | }; |
| 1845 | \layout Standard |
| 1846 | |
| 1847 | In this example, the application programmer defined a custom structure with |
| 1848 | one ASN.1-derived member (rect). |
| 1849 | This member is not a reference to the Rectangle_t, but an in-place inclusion |
| 1850 | of the Rectangle_t structure. |
| 1851 | If the freeing is necessary, the usual procedure of freeing everything |
| 1852 | must not be applied to the &rect pointer itself, because it does not point |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1853 | to the memory block directly allocated by the memory allocation routine, |
| 1854 | but instead lies within a block allocated for the my_figure structure. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1855 | \layout Standard |
| 1856 | |
| 1857 | To solve this problem, the free_struct routine has the additional argument |
vlm | 485123c | 2005-02-22 07:28:26 +0000 | [diff] [blame] | 1858 | (besides the obvious type descriptor and target structure pointers), which |
| 1859 | is the flag specifying whether the outer pointer itself must be freed (0, |
| 1860 | default) or it should be left intact (non-zero value). |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1861 | \layout LyX-Code |
| 1862 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1863 | |
| 1864 | \series bold |
| 1865 | /* 1. |
| 1866 | Rectangle_t is defined within my_figure */ |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1867 | \layout LyX-Code |
| 1868 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1869 | struct my_figure { |
| 1870 | \layout LyX-Code |
| 1871 | |
| 1872 | Rectangle_t rect; |
| 1873 | \layout LyX-Code |
| 1874 | |
| 1875 | } *mf = |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1876 | \series bold |
| 1877 | ... |
| 1878 | \series default |
| 1879 | ; |
| 1880 | \layout LyX-Code |
| 1881 | |
| 1882 | /* |
| 1883 | \layout LyX-Code |
| 1884 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1885 | * Freeing the Rectangle_t |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1886 | \layout LyX-Code |
| 1887 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1888 | * without freeing the mf->rect area |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1889 | \layout LyX-Code |
| 1890 | |
| 1891 | */ |
| 1892 | \layout LyX-Code |
| 1893 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1894 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1895 | \layout LyX-Code |
| 1896 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1897 | &asn_DEF_Rectangle, &mf->rect, |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1898 | \series bold |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1899 | 1 |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1900 | \emph on |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1901 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1902 | \emph default |
| 1903 | /* !free */ |
| 1904 | \series default |
| 1905 | ); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1906 | \layout LyX-Code |
| 1907 | |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1908 | |
| 1909 | \layout LyX-Code |
| 1910 | |
| 1911 | |
| 1912 | \layout LyX-Code |
| 1913 | |
| 1914 | |
| 1915 | \series bold |
| 1916 | /* 2. |
| 1917 | Rectangle_t is a stand-alone pointer */ |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1918 | \layout LyX-Code |
| 1919 | |
| 1920 | Rectangle_t *rect = |
| 1921 | \series bold |
| 1922 | ... |
| 1923 | \series default |
| 1924 | ; |
| 1925 | \layout LyX-Code |
| 1926 | |
| 1927 | /* |
| 1928 | \layout LyX-Code |
| 1929 | |
| 1930 | * Freeing the Rectangle_t |
| 1931 | \layout LyX-Code |
| 1932 | |
| 1933 | * and freeing the rect pointer |
| 1934 | \layout LyX-Code |
| 1935 | |
| 1936 | */ |
| 1937 | \layout LyX-Code |
| 1938 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1939 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1940 | \layout LyX-Code |
| 1941 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1942 | &asn_DEF_Rectangle, rect, |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1943 | \series bold |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1944 | 0 |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1945 | \emph on |
| 1946 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1947 | \emph default |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 1948 | /* free the pointer too */ |
| 1949 | \series default |
| 1950 | ); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1951 | \layout Standard |
| 1952 | |
| 1953 | It is safe to invoke the |
| 1954 | \emph on |
| 1955 | free_struct |
| 1956 | \emph default |
| 1957 | function with the target structure pointer set to 0 (NULL), the function |
| 1958 | will do nothing. |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 1959 | \layout Chapter |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 1960 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 1961 | |
| 1962 | \begin_inset LatexCommand \label{cha:Step-by-step-examples} |
| 1963 | |
| 1964 | \end_inset |
| 1965 | |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 1966 | Step by step examples |
| 1967 | \layout Section |
| 1968 | |
| 1969 | A |
| 1970 | \begin_inset Quotes sld |
| 1971 | \end_inset |
| 1972 | |
| 1973 | Rectangle |
| 1974 | \begin_inset Quotes srd |
| 1975 | \end_inset |
| 1976 | |
| 1977 | Encoder |
| 1978 | \layout Standard |
| 1979 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 1980 | This example will help you to create a simple BER and XER encoder of a |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 1981 | \begin_inset Quotes sld |
| 1982 | \end_inset |
| 1983 | |
| 1984 | Rectangle |
| 1985 | \begin_inset Quotes srd |
| 1986 | \end_inset |
| 1987 | |
| 1988 | type used throughout this document. |
| 1989 | \layout Enumerate |
| 1990 | |
| 1991 | Create a file named |
| 1992 | \series bold |
| 1993 | rectangle.asn1 |
| 1994 | \series default |
| 1995 | with the following contents: |
| 1996 | \begin_deeper |
| 1997 | \layout LyX-Code |
| 1998 | |
| 1999 | RectangleModule1 DEFINITIONS ::= |
| 2000 | \layout LyX-Code |
| 2001 | |
| 2002 | BEGIN |
| 2003 | \layout LyX-Code |
| 2004 | |
| 2005 | |
| 2006 | \layout LyX-Code |
| 2007 | |
| 2008 | Rectangle ::= SEQUENCE { |
| 2009 | \layout LyX-Code |
| 2010 | |
| 2011 | height INTEGER, |
| 2012 | \layout LyX-Code |
| 2013 | |
| 2014 | width INTEGER |
| 2015 | \layout LyX-Code |
| 2016 | |
| 2017 | } |
| 2018 | \layout LyX-Code |
| 2019 | |
| 2020 | |
| 2021 | \layout LyX-Code |
| 2022 | |
| 2023 | END |
| 2024 | \end_deeper |
| 2025 | \layout Enumerate |
| 2026 | |
| 2027 | Compile it into the set of .c and .h files using asn1c compiler |
| 2028 | \begin_inset LatexCommand \cite{ASN1C} |
| 2029 | |
| 2030 | \end_inset |
| 2031 | |
| 2032 | : |
| 2033 | \begin_deeper |
| 2034 | \layout LyX-Code |
| 2035 | |
| 2036 | |
| 2037 | \emph on |
| 2038 | asn1c -fnative-types |
| 2039 | \series bold |
| 2040 | \emph default |
| 2041 | rectangle.asn1 |
| 2042 | \end_deeper |
| 2043 | \layout Enumerate |
| 2044 | |
| 2045 | Alternatively, use the Online ASN.1 compiler |
| 2046 | \begin_inset LatexCommand \cite{AONL} |
| 2047 | |
| 2048 | \end_inset |
| 2049 | |
| 2050 | by uploading the |
| 2051 | \series bold |
| 2052 | rectangle.asn1 |
| 2053 | \series default |
| 2054 | file into the Web form and unpacking the produced archive on your computer. |
| 2055 | \layout Enumerate |
| 2056 | |
| 2057 | By this time, you should have gotten multiple files in the current directory, |
| 2058 | including the |
| 2059 | \series bold |
| 2060 | Rectangle.c |
| 2061 | \series default |
| 2062 | and |
| 2063 | \series bold |
| 2064 | Rectangle.h |
| 2065 | \series default |
| 2066 | . |
| 2067 | \layout Enumerate |
| 2068 | |
| 2069 | Create a main() routine which creates the Rectangle_t structure in memory |
| 2070 | and encodes it using BER and XER encoding rules. |
| 2071 | Let's name the file |
| 2072 | \series bold |
| 2073 | main.c |
| 2074 | \series default |
| 2075 | : |
| 2076 | \begin_inset ERT |
| 2077 | status Open |
| 2078 | |
| 2079 | \layout Standard |
| 2080 | |
| 2081 | \backslash |
| 2082 | clearpage{} |
| 2083 | \end_inset |
| 2084 | |
| 2085 | |
| 2086 | \begin_deeper |
| 2087 | \layout LyX-Code |
| 2088 | |
| 2089 | |
| 2090 | \size small |
| 2091 | #include <stdio.h> |
| 2092 | \layout LyX-Code |
| 2093 | |
| 2094 | |
| 2095 | \size small |
| 2096 | #include <sys/types.h> |
| 2097 | \layout LyX-Code |
| 2098 | |
| 2099 | |
| 2100 | \size small |
| 2101 | #include <Rectangle.h> /* Rectangle ASN.1 type */ |
| 2102 | \layout LyX-Code |
| 2103 | |
| 2104 | |
| 2105 | \layout LyX-Code |
| 2106 | |
| 2107 | |
| 2108 | \size small |
| 2109 | /* |
| 2110 | \layout LyX-Code |
| 2111 | |
| 2112 | |
| 2113 | \size small |
| 2114 | * This is a custom function which writes the |
| 2115 | \layout LyX-Code |
| 2116 | |
| 2117 | |
| 2118 | \size small |
| 2119 | * encoded output into some FILE stream. |
| 2120 | \layout LyX-Code |
| 2121 | |
| 2122 | |
| 2123 | \size small |
| 2124 | */ |
| 2125 | \layout LyX-Code |
| 2126 | |
| 2127 | |
| 2128 | \size small |
| 2129 | static int |
| 2130 | \layout LyX-Code |
| 2131 | |
| 2132 | |
| 2133 | \size small |
| 2134 | write_out(const void *buffer, size_t size, void *app_key) { |
| 2135 | \layout LyX-Code |
| 2136 | |
| 2137 | |
| 2138 | \size small |
| 2139 | FILE *out_fp = app_key; |
| 2140 | \layout LyX-Code |
| 2141 | |
| 2142 | |
| 2143 | \size small |
| 2144 | size_t wrote; |
| 2145 | \layout LyX-Code |
| 2146 | |
| 2147 | |
| 2148 | \size small |
| 2149 | |
| 2150 | \layout LyX-Code |
| 2151 | |
| 2152 | |
| 2153 | \size small |
| 2154 | wrote = fwrite(buffer, 1, size, out_fp); |
| 2155 | \layout LyX-Code |
| 2156 | |
| 2157 | |
| 2158 | \size small |
| 2159 | |
| 2160 | \layout LyX-Code |
| 2161 | |
| 2162 | |
| 2163 | \size small |
| 2164 | return (wrote == size) ? 0 : -1; |
| 2165 | \layout LyX-Code |
| 2166 | |
| 2167 | |
| 2168 | \size small |
| 2169 | } |
| 2170 | \layout LyX-Code |
| 2171 | |
| 2172 | |
| 2173 | \layout LyX-Code |
| 2174 | |
| 2175 | |
| 2176 | \size small |
vlm | 6c37dac | 2005-01-31 15:06:32 +0000 | [diff] [blame] | 2177 | int main(int ac, char **av) { |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2178 | \layout LyX-Code |
| 2179 | |
| 2180 | |
| 2181 | \size small |
| 2182 | Rectangle_t *rectangle; /* Type to encode */ |
| 2183 | \layout LyX-Code |
| 2184 | |
| 2185 | |
| 2186 | \size small |
| 2187 | asn_enc_rval_t ec; /* Encoder return value */ |
| 2188 | \layout LyX-Code |
| 2189 | |
| 2190 | |
| 2191 | \size small |
| 2192 | |
| 2193 | \layout LyX-Code |
| 2194 | |
| 2195 | |
| 2196 | \size small |
| 2197 | /* Allocate the Rectangle_t */ |
| 2198 | \layout LyX-Code |
| 2199 | |
| 2200 | |
| 2201 | \size small |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 2202 | rectangle = calloc(1, sizeof(Rectangle_t)); /* not malloc! */ |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2203 | \layout LyX-Code |
| 2204 | |
| 2205 | |
| 2206 | \size small |
| 2207 | if(!rectangle) { |
| 2208 | \layout LyX-Code |
| 2209 | |
| 2210 | |
| 2211 | \size small |
| 2212 | perror( |
| 2213 | \begin_inset Quotes sld |
| 2214 | \end_inset |
| 2215 | |
| 2216 | calloc() failed |
| 2217 | \begin_inset Quotes srd |
| 2218 | \end_inset |
| 2219 | |
| 2220 | ); |
| 2221 | \layout LyX-Code |
| 2222 | |
| 2223 | |
| 2224 | \size small |
| 2225 | exit(71); /* better, EX_OSERR */ |
| 2226 | \layout LyX-Code |
| 2227 | |
| 2228 | |
| 2229 | \size small |
| 2230 | } |
| 2231 | \layout LyX-Code |
| 2232 | |
| 2233 | |
| 2234 | \size small |
| 2235 | |
| 2236 | \layout LyX-Code |
| 2237 | |
| 2238 | |
| 2239 | \size small |
| 2240 | /* Initialize the Rectangle members */ |
| 2241 | \layout LyX-Code |
| 2242 | |
| 2243 | |
| 2244 | \size small |
| 2245 | rectangle->height = 42; /* any random value */ |
| 2246 | \layout LyX-Code |
| 2247 | |
| 2248 | |
| 2249 | \size small |
| 2250 | rectangle->width = 23; /* any random value */ |
| 2251 | \layout LyX-Code |
| 2252 | |
| 2253 | |
| 2254 | \size small |
| 2255 | |
| 2256 | \layout LyX-Code |
| 2257 | |
| 2258 | |
| 2259 | \size small |
| 2260 | /* BER encode the data if filename is given */ |
| 2261 | \layout LyX-Code |
| 2262 | |
| 2263 | |
| 2264 | \size small |
| 2265 | if(ac < 2) { |
| 2266 | \layout LyX-Code |
| 2267 | |
| 2268 | |
| 2269 | \size small |
| 2270 | fprintf(stderr, |
| 2271 | \begin_inset Quotes sld |
| 2272 | \end_inset |
| 2273 | |
| 2274 | Specify filename for BER output |
| 2275 | \backslash |
| 2276 | n |
| 2277 | \begin_inset Quotes srd |
| 2278 | \end_inset |
| 2279 | |
| 2280 | ); |
| 2281 | \layout LyX-Code |
| 2282 | |
| 2283 | |
| 2284 | \size small |
| 2285 | } else { |
| 2286 | \layout LyX-Code |
| 2287 | |
| 2288 | |
| 2289 | \size small |
| 2290 | const char *filename = av[1]; |
| 2291 | \layout LyX-Code |
| 2292 | |
| 2293 | |
| 2294 | \size small |
| 2295 | FILE *fp = fopen(filename, |
| 2296 | \begin_inset Quotes sld |
| 2297 | \end_inset |
| 2298 | |
vlm | dae8e61 | 2005-07-21 18:45:37 +0000 | [diff] [blame^] | 2299 | wb |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2300 | \begin_inset Quotes srd |
| 2301 | \end_inset |
| 2302 | |
| 2303 | ); /* for BER output */ |
| 2304 | \layout LyX-Code |
| 2305 | |
| 2306 | |
| 2307 | \layout LyX-Code |
| 2308 | |
| 2309 | |
| 2310 | \size small |
| 2311 | if(!fp) { |
| 2312 | \layout LyX-Code |
| 2313 | |
| 2314 | |
| 2315 | \size small |
| 2316 | perror(filename); |
| 2317 | \layout LyX-Code |
| 2318 | |
| 2319 | |
| 2320 | \size small |
| 2321 | exit(71); /* better, EX_OSERR */ |
| 2322 | \layout LyX-Code |
| 2323 | |
| 2324 | |
| 2325 | \size small |
| 2326 | } |
| 2327 | \layout LyX-Code |
| 2328 | |
| 2329 | |
| 2330 | \size small |
| 2331 | |
| 2332 | \layout LyX-Code |
| 2333 | |
| 2334 | |
| 2335 | \size small |
| 2336 | /* Encode the Rectangle type as BER (DER) */ |
| 2337 | \layout LyX-Code |
| 2338 | |
| 2339 | |
| 2340 | \size small |
| 2341 | ec = der_encode(&asn_DEF_Rectangle, |
| 2342 | \layout LyX-Code |
| 2343 | |
| 2344 | |
| 2345 | \size small |
vlm | 6c37dac | 2005-01-31 15:06:32 +0000 | [diff] [blame] | 2346 | rectangle, write_out, fp); |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2347 | \layout LyX-Code |
| 2348 | |
| 2349 | |
| 2350 | \size small |
| 2351 | fclose(fp); |
| 2352 | \layout LyX-Code |
| 2353 | |
| 2354 | |
| 2355 | \size small |
| 2356 | if(ec.encoded == -1) { |
| 2357 | \layout LyX-Code |
| 2358 | |
| 2359 | |
| 2360 | \size small |
| 2361 | fprintf(stderr, |
| 2362 | \layout LyX-Code |
| 2363 | |
| 2364 | |
| 2365 | \size small |
| 2366 | |
| 2367 | \begin_inset Quotes sld |
| 2368 | \end_inset |
| 2369 | |
| 2370 | Could not encode Rectangle (at %s) |
| 2371 | \backslash |
| 2372 | n |
| 2373 | \begin_inset Quotes srd |
| 2374 | \end_inset |
| 2375 | |
| 2376 | , |
| 2377 | \layout LyX-Code |
| 2378 | |
| 2379 | |
| 2380 | \size small |
| 2381 | ec.failed_type ? ec.failed_type->name : |
| 2382 | \begin_inset Quotes sld |
| 2383 | \end_inset |
| 2384 | |
| 2385 | unknown |
| 2386 | \begin_inset Quotes srd |
| 2387 | \end_inset |
| 2388 | |
| 2389 | ); |
| 2390 | \layout LyX-Code |
| 2391 | |
| 2392 | |
| 2393 | \size small |
| 2394 | exit(65); /* better, EX_DATAERR */ |
| 2395 | \layout LyX-Code |
| 2396 | |
| 2397 | |
| 2398 | \size small |
| 2399 | } else { |
| 2400 | \layout LyX-Code |
| 2401 | |
| 2402 | |
| 2403 | \size small |
| 2404 | fprintf(stderr, |
| 2405 | \begin_inset Quotes sld |
| 2406 | \end_inset |
| 2407 | |
| 2408 | Created %s with BER encoded Rectangle |
| 2409 | \backslash |
| 2410 | n |
| 2411 | \begin_inset Quotes srd |
| 2412 | \end_inset |
| 2413 | |
| 2414 | , |
| 2415 | \layout LyX-Code |
| 2416 | |
| 2417 | |
| 2418 | \size small |
| 2419 | filename); |
| 2420 | \layout LyX-Code |
| 2421 | |
| 2422 | |
| 2423 | \size small |
| 2424 | } |
| 2425 | \layout LyX-Code |
| 2426 | |
| 2427 | |
| 2428 | \size small |
| 2429 | } |
| 2430 | \layout LyX-Code |
| 2431 | |
| 2432 | |
| 2433 | \size small |
| 2434 | |
| 2435 | \layout LyX-Code |
| 2436 | |
| 2437 | |
| 2438 | \size small |
| 2439 | /* Also print the constructed Rectangle XER encoded (XML) */ |
| 2440 | \layout LyX-Code |
| 2441 | |
| 2442 | |
| 2443 | \size small |
| 2444 | xer_fprint(stdout, &asn_DEF_Rectangle, rectangle); |
| 2445 | \layout LyX-Code |
| 2446 | |
| 2447 | |
| 2448 | \size small |
| 2449 | |
| 2450 | \layout LyX-Code |
| 2451 | |
| 2452 | |
| 2453 | \size small |
| 2454 | return 0; /* Encoding finished successfully */ |
| 2455 | \layout LyX-Code |
| 2456 | |
| 2457 | |
| 2458 | \size small |
| 2459 | } |
| 2460 | \end_deeper |
| 2461 | \layout Enumerate |
| 2462 | |
| 2463 | Compile all files together using C compiler (varies by platform): |
| 2464 | \begin_deeper |
| 2465 | \layout LyX-Code |
| 2466 | |
| 2467 | |
| 2468 | \emph on |
| 2469 | cc -I. |
| 2470 | -o |
| 2471 | \series bold |
| 2472 | rencode |
| 2473 | \series default |
| 2474 | *.c |
| 2475 | \end_deeper |
| 2476 | \layout Enumerate |
| 2477 | |
| 2478 | Voila! You have just created the BER and XER encoder of a Rectangle type, |
| 2479 | named |
| 2480 | \series bold |
| 2481 | rencode |
| 2482 | \series default |
| 2483 | ! |
| 2484 | \layout Standard |
| 2485 | |
| 2486 | |
| 2487 | \begin_inset ERT |
| 2488 | status Collapsed |
| 2489 | |
| 2490 | \layout Standard |
| 2491 | |
| 2492 | \backslash |
| 2493 | clearpage{} |
| 2494 | \end_inset |
| 2495 | |
| 2496 | |
| 2497 | \layout Section |
| 2498 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 2499 | |
| 2500 | \begin_inset LatexCommand \label{sec:A-Rectangle-Decoder} |
| 2501 | |
| 2502 | \end_inset |
| 2503 | |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2504 | A |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2505 | \begin_inset Quotes sld |
| 2506 | \end_inset |
| 2507 | |
| 2508 | Rectangle |
| 2509 | \begin_inset Quotes srd |
| 2510 | \end_inset |
| 2511 | |
| 2512 | Decoder |
| 2513 | \layout Standard |
| 2514 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 2515 | This example will help you to create a simple BER decoder of a simple |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2516 | \begin_inset Quotes sld |
| 2517 | \end_inset |
| 2518 | |
| 2519 | Rectangle |
| 2520 | \begin_inset Quotes srd |
| 2521 | \end_inset |
| 2522 | |
| 2523 | type used throughout this document. |
| 2524 | \layout Enumerate |
| 2525 | |
| 2526 | Create a file named |
| 2527 | \series bold |
| 2528 | rectangle.asn1 |
| 2529 | \series default |
| 2530 | with the following contents: |
| 2531 | \begin_deeper |
| 2532 | \layout LyX-Code |
| 2533 | |
| 2534 | RectangleModule1 DEFINITIONS ::= |
| 2535 | \layout LyX-Code |
| 2536 | |
| 2537 | BEGIN |
| 2538 | \layout LyX-Code |
| 2539 | |
| 2540 | |
| 2541 | \layout LyX-Code |
| 2542 | |
| 2543 | Rectangle ::= SEQUENCE { |
| 2544 | \layout LyX-Code |
| 2545 | |
| 2546 | height INTEGER, |
| 2547 | \layout LyX-Code |
| 2548 | |
| 2549 | width INTEGER |
| 2550 | \layout LyX-Code |
| 2551 | |
| 2552 | } |
| 2553 | \layout LyX-Code |
| 2554 | |
| 2555 | |
| 2556 | \layout LyX-Code |
| 2557 | |
| 2558 | END |
| 2559 | \end_deeper |
| 2560 | \layout Enumerate |
| 2561 | |
| 2562 | Compile it into the set of .c and .h files using asn1c compiler |
| 2563 | \begin_inset LatexCommand \cite{ASN1C} |
| 2564 | |
| 2565 | \end_inset |
| 2566 | |
| 2567 | : |
| 2568 | \begin_deeper |
| 2569 | \layout LyX-Code |
| 2570 | |
| 2571 | |
| 2572 | \emph on |
| 2573 | asn1c -fnative-types |
| 2574 | \series bold |
| 2575 | \emph default |
| 2576 | rectangle.asn1 |
| 2577 | \end_deeper |
| 2578 | \layout Enumerate |
| 2579 | |
| 2580 | Alternatively, use the Online ASN.1 compiler |
| 2581 | \begin_inset LatexCommand \cite{AONL} |
| 2582 | |
| 2583 | \end_inset |
| 2584 | |
| 2585 | by uploading the |
| 2586 | \series bold |
| 2587 | rectangle.asn1 |
| 2588 | \series default |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2589 | file into the Web form and unpacking the produced archive on your computer. |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2590 | \layout Enumerate |
| 2591 | |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2592 | By this time, you should have gotten multiple files in the current directory, |
| 2593 | including the |
| 2594 | \series bold |
| 2595 | Rectangle.c |
| 2596 | \series default |
| 2597 | and |
| 2598 | \series bold |
| 2599 | Rectangle.h |
| 2600 | \series default |
| 2601 | . |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2602 | \layout Enumerate |
| 2603 | |
| 2604 | Create a main() routine which takes the binary input file, decodes it as |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2605 | it were a BER-encoded Rectangle type, and prints out the text (XML) representat |
| 2606 | ion of the Rectangle type. |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2607 | Let's name the file |
| 2608 | \series bold |
| 2609 | main.c |
| 2610 | \series default |
| 2611 | : |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2612 | \begin_inset ERT |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 2613 | status Collapsed |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2614 | |
| 2615 | \layout Standard |
| 2616 | |
| 2617 | \backslash |
| 2618 | clearpage{} |
| 2619 | \end_inset |
| 2620 | |
| 2621 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2622 | \begin_deeper |
| 2623 | \layout LyX-Code |
| 2624 | |
| 2625 | |
| 2626 | \size small |
| 2627 | #include <stdio.h> |
| 2628 | \layout LyX-Code |
| 2629 | |
| 2630 | |
| 2631 | \size small |
| 2632 | #include <sys/types.h> |
| 2633 | \layout LyX-Code |
| 2634 | |
| 2635 | |
| 2636 | \size small |
| 2637 | #include <Rectangle.h> /* Rectangle ASN.1 type */ |
| 2638 | \layout LyX-Code |
| 2639 | |
| 2640 | |
| 2641 | \size small |
| 2642 | |
| 2643 | \layout LyX-Code |
| 2644 | |
| 2645 | |
| 2646 | \size small |
| 2647 | int main(int ac, char **av) { |
| 2648 | \layout LyX-Code |
| 2649 | |
| 2650 | |
| 2651 | \size small |
| 2652 | char buf[1024]; /* Temporary buffer */ |
| 2653 | \layout LyX-Code |
| 2654 | |
| 2655 | |
| 2656 | \size small |
| 2657 | Rectangle_t *rectangle = 0; /* Type to decode */ |
| 2658 | \layout LyX-Code |
| 2659 | |
| 2660 | |
| 2661 | \size small |
| 2662 | asn_dec_rval_t rval; /* Decoder return value */ |
| 2663 | \layout LyX-Code |
| 2664 | |
| 2665 | |
| 2666 | \size small |
| 2667 | FILE *fp; /* Input file handler */ |
| 2668 | \layout LyX-Code |
| 2669 | |
| 2670 | |
| 2671 | \size small |
| 2672 | size_t size; /* Number of bytes read */ |
| 2673 | \layout LyX-Code |
| 2674 | |
| 2675 | |
| 2676 | \size small |
| 2677 | char *filename; /* Input file name */ |
| 2678 | \layout LyX-Code |
| 2679 | |
| 2680 | |
| 2681 | \size small |
| 2682 | |
| 2683 | \layout LyX-Code |
| 2684 | |
| 2685 | |
| 2686 | \size small |
| 2687 | /* Require a single filename argument */ |
| 2688 | \layout LyX-Code |
| 2689 | |
| 2690 | |
| 2691 | \size small |
| 2692 | if(ac != 2) { |
| 2693 | \layout LyX-Code |
| 2694 | |
| 2695 | |
| 2696 | \size small |
| 2697 | fprintf(stderr, |
| 2698 | \begin_inset Quotes sld |
| 2699 | \end_inset |
| 2700 | |
| 2701 | Usage: %s <file.ber> |
| 2702 | \backslash |
| 2703 | n |
| 2704 | \begin_inset Quotes srd |
| 2705 | \end_inset |
| 2706 | |
| 2707 | , av[0]); |
| 2708 | \layout LyX-Code |
| 2709 | |
| 2710 | |
| 2711 | \size small |
| 2712 | exit(64); /* better, EX_USAGE */ |
| 2713 | \layout LyX-Code |
| 2714 | |
| 2715 | |
| 2716 | \size small |
| 2717 | } else { |
| 2718 | \layout LyX-Code |
| 2719 | |
| 2720 | |
| 2721 | \size small |
| 2722 | filename = av[1]; |
| 2723 | \layout LyX-Code |
| 2724 | |
| 2725 | |
| 2726 | \size small |
| 2727 | } |
| 2728 | \layout LyX-Code |
| 2729 | |
| 2730 | |
| 2731 | \size small |
| 2732 | |
| 2733 | \layout LyX-Code |
| 2734 | |
| 2735 | |
| 2736 | \size small |
| 2737 | /* Open input file as read-only binary */ |
| 2738 | \layout LyX-Code |
| 2739 | |
| 2740 | |
| 2741 | \size small |
| 2742 | fp = fopen(filename, |
| 2743 | \begin_inset Quotes sld |
| 2744 | \end_inset |
| 2745 | |
| 2746 | rb |
| 2747 | \begin_inset Quotes srd |
| 2748 | \end_inset |
| 2749 | |
| 2750 | ); |
| 2751 | \layout LyX-Code |
| 2752 | |
| 2753 | |
| 2754 | \size small |
| 2755 | if(!fp) { |
| 2756 | \layout LyX-Code |
| 2757 | |
| 2758 | |
| 2759 | \size small |
| 2760 | perror(filename); |
| 2761 | \layout LyX-Code |
| 2762 | |
| 2763 | |
| 2764 | \size small |
| 2765 | exit(66); /* better, EX_NOINPUT */ |
| 2766 | \layout LyX-Code |
| 2767 | |
| 2768 | |
| 2769 | \size small |
| 2770 | } |
| 2771 | \layout LyX-Code |
| 2772 | |
| 2773 | |
| 2774 | \size small |
| 2775 | |
| 2776 | \layout LyX-Code |
| 2777 | |
| 2778 | |
| 2779 | \size small |
| 2780 | /* Read up to the buffer size */ |
| 2781 | \layout LyX-Code |
| 2782 | |
| 2783 | |
| 2784 | \size small |
| 2785 | size = fread(buf, 1, sizeof(buf), fp); |
| 2786 | \layout LyX-Code |
| 2787 | |
| 2788 | |
| 2789 | \size small |
| 2790 | fclose(fp); |
| 2791 | \layout LyX-Code |
| 2792 | |
| 2793 | |
| 2794 | \size small |
| 2795 | if(!size) { |
| 2796 | \layout LyX-Code |
| 2797 | |
| 2798 | |
| 2799 | \size small |
| 2800 | fprintf(stderr, |
| 2801 | \begin_inset Quotes sld |
| 2802 | \end_inset |
| 2803 | |
| 2804 | %s: Empty or broken |
| 2805 | \backslash |
| 2806 | n |
| 2807 | \begin_inset Quotes srd |
| 2808 | \end_inset |
| 2809 | |
| 2810 | , filename); |
| 2811 | \layout LyX-Code |
| 2812 | |
| 2813 | |
| 2814 | \size small |
| 2815 | exit(65); /* better, EX_DATAERR */ |
| 2816 | \layout LyX-Code |
| 2817 | |
| 2818 | |
| 2819 | \size small |
| 2820 | } |
| 2821 | \layout LyX-Code |
| 2822 | |
| 2823 | |
| 2824 | \size small |
| 2825 | |
| 2826 | \layout LyX-Code |
| 2827 | |
| 2828 | |
| 2829 | \size small |
| 2830 | /* Decode the input buffer as Rectangle type */ |
| 2831 | \layout LyX-Code |
| 2832 | |
| 2833 | |
| 2834 | \size small |
| 2835 | rval = ber_decode(0, &asn_DEF_Rectangle, |
| 2836 | \layout LyX-Code |
| 2837 | |
| 2838 | |
| 2839 | \size small |
| 2840 | (void **)&rectangle, buf, size); |
| 2841 | \layout LyX-Code |
| 2842 | |
| 2843 | |
| 2844 | \size small |
| 2845 | if(rval.code != RC_OK) { |
| 2846 | \layout LyX-Code |
| 2847 | |
| 2848 | |
| 2849 | \size small |
| 2850 | fprintf(stderr, |
| 2851 | \layout LyX-Code |
| 2852 | |
| 2853 | |
| 2854 | \size small |
| 2855 | |
| 2856 | \begin_inset Quotes sld |
| 2857 | \end_inset |
| 2858 | |
| 2859 | %s: Broken Rectangle encoding at byte %ld |
| 2860 | \backslash |
| 2861 | n |
| 2862 | \begin_inset Quotes srd |
| 2863 | \end_inset |
| 2864 | |
| 2865 | , |
| 2866 | \layout LyX-Code |
| 2867 | |
| 2868 | |
| 2869 | \size small |
| 2870 | filename, (long)rval.consumed); |
| 2871 | \layout LyX-Code |
| 2872 | |
| 2873 | |
| 2874 | \size small |
| 2875 | exit(65); /* better, EX_DATAERR */ |
| 2876 | \layout LyX-Code |
| 2877 | |
| 2878 | |
| 2879 | \size small |
| 2880 | } |
| 2881 | \layout LyX-Code |
| 2882 | |
| 2883 | |
| 2884 | \size small |
| 2885 | |
| 2886 | \layout LyX-Code |
| 2887 | |
| 2888 | |
| 2889 | \size small |
| 2890 | /* Print the decoded Rectangle type as XML */ |
| 2891 | \layout LyX-Code |
| 2892 | |
| 2893 | |
| 2894 | \size small |
| 2895 | xer_fprint(stdout, &asn_DEF_Rectangle, rectangle); |
| 2896 | \layout LyX-Code |
| 2897 | |
| 2898 | |
| 2899 | \size small |
| 2900 | |
| 2901 | \layout LyX-Code |
| 2902 | |
| 2903 | |
| 2904 | \size small |
| 2905 | return 0; /* Decoding finished successfully */ |
| 2906 | \layout LyX-Code |
| 2907 | |
| 2908 | |
| 2909 | \size small |
| 2910 | } |
| 2911 | \end_deeper |
| 2912 | \layout Enumerate |
| 2913 | |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2914 | Compile all files together using C compiler (varies by platform): |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2915 | \begin_deeper |
| 2916 | \layout LyX-Code |
| 2917 | |
| 2918 | |
| 2919 | \emph on |
| 2920 | cc -I. |
vlm | abd51e2 | 2005-01-17 11:05:04 +0000 | [diff] [blame] | 2921 | -o |
| 2922 | \series bold |
| 2923 | rdecode |
| 2924 | \series default |
| 2925 | *.c |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2926 | \end_deeper |
| 2927 | \layout Enumerate |
| 2928 | |
vlm | a1fd7f9 | 2005-01-31 10:10:04 +0000 | [diff] [blame] | 2929 | Voila! You have just created the BER decoder of a Rectangle type, named |
| 2930 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 2931 | \series bold |
| 2932 | rdecode |
| 2933 | \series default |
| 2934 | ! |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 2935 | \layout Chapter |
| 2936 | |
| 2937 | Constraint validation examples |
| 2938 | \layout Standard |
| 2939 | |
| 2940 | This chapter shows how to define ASN.1 constraints and use the generated |
| 2941 | validation code. |
| 2942 | \layout Section |
| 2943 | |
| 2944 | Adding constraints into |
| 2945 | \begin_inset Quotes sld |
| 2946 | \end_inset |
| 2947 | |
| 2948 | Rectangle |
| 2949 | \begin_inset Quotes srd |
| 2950 | \end_inset |
| 2951 | |
| 2952 | type |
| 2953 | \layout Standard |
| 2954 | |
| 2955 | This example shows how to add basic constraints to the ASN.1 specification |
| 2956 | and how to invoke the constraints validation code in your application. |
| 2957 | \layout Enumerate |
| 2958 | |
| 2959 | Create a file named |
| 2960 | \series bold |
| 2961 | rectangle.asn1 |
| 2962 | \series default |
| 2963 | with the following contents: |
| 2964 | \begin_deeper |
| 2965 | \layout LyX-Code |
| 2966 | |
| 2967 | RectangleModuleWithConstraints DEFINITIONS ::= |
| 2968 | \layout LyX-Code |
| 2969 | |
| 2970 | BEGIN |
| 2971 | \layout LyX-Code |
| 2972 | |
| 2973 | |
| 2974 | \layout LyX-Code |
| 2975 | |
| 2976 | Rectangle ::= SEQUENCE { |
| 2977 | \layout LyX-Code |
| 2978 | |
| 2979 | height INTEGER (0..100), -- Value range constraint |
| 2980 | \layout LyX-Code |
| 2981 | |
| 2982 | width INTEGER (0..MAX) -- Makes width non-negative |
| 2983 | \layout LyX-Code |
| 2984 | |
| 2985 | } |
| 2986 | \layout LyX-Code |
| 2987 | |
| 2988 | |
| 2989 | \layout LyX-Code |
| 2990 | |
| 2991 | END |
| 2992 | \end_deeper |
| 2993 | \layout Enumerate |
| 2994 | |
| 2995 | Compile the file according to procedures shown in the previous chapter. |
| 2996 | \layout Enumerate |
| 2997 | |
| 2998 | Modify the Rectangle type processing routine (you can start with the main() |
| 2999 | routine shown in the Section |
| 3000 | \begin_inset LatexCommand \vref{sec:A-Rectangle-Decoder} |
| 3001 | |
| 3002 | \end_inset |
| 3003 | |
| 3004 | ) by placing the following snippet of code |
| 3005 | \emph on |
| 3006 | before |
| 3007 | \emph default |
| 3008 | encoding and/or |
| 3009 | \emph on |
| 3010 | after |
| 3011 | \emph default |
| 3012 | decoding the Rectangle type |
| 3013 | \begin_inset Foot |
| 3014 | collapsed true |
| 3015 | |
| 3016 | \layout Standard |
| 3017 | |
| 3018 | Placing the constraint checking code |
| 3019 | \emph on |
| 3020 | before |
| 3021 | \emph default |
| 3022 | encoding helps to make sure you know the data is correct and within constraints |
| 3023 | before sharing the data with anyone else. |
| 3024 | \layout Standard |
| 3025 | |
| 3026 | Placing the constraint checking code |
| 3027 | \emph on |
| 3028 | after |
| 3029 | \emph default |
| 3030 | decoding, but before any further action depending on the decoded data, |
| 3031 | helps to make sure the application got the valid contents before making |
| 3032 | use of it. |
| 3033 | \end_inset |
| 3034 | |
| 3035 | : |
| 3036 | \begin_inset ERT |
| 3037 | status Collapsed |
| 3038 | |
| 3039 | \layout Standard |
| 3040 | |
| 3041 | \backslash |
| 3042 | clearpage{} |
| 3043 | \end_inset |
| 3044 | |
| 3045 | |
| 3046 | \begin_deeper |
| 3047 | \layout LyX-Code |
| 3048 | |
| 3049 | |
| 3050 | \size small |
| 3051 | int ret; /* Return value */ |
| 3052 | \layout LyX-Code |
| 3053 | |
| 3054 | |
| 3055 | \size small |
| 3056 | char errbuf[128]; /* Buffer for error message */ |
| 3057 | \layout LyX-Code |
| 3058 | |
| 3059 | |
| 3060 | \size small |
| 3061 | size_t errlen = sizeof(errbuf); /* Size of the buffer */ |
| 3062 | \layout LyX-Code |
| 3063 | |
| 3064 | |
| 3065 | \size small |
| 3066 | |
| 3067 | \layout LyX-Code |
| 3068 | |
| 3069 | |
| 3070 | \size small |
| 3071 | /* ... |
| 3072 | here may go Rectangle decoding code ... |
| 3073 | */ |
| 3074 | \layout LyX-Code |
| 3075 | |
| 3076 | |
| 3077 | \size small |
| 3078 | |
| 3079 | \layout LyX-Code |
| 3080 | |
| 3081 | |
| 3082 | \size small |
| 3083 | ret = asn_check_constraints(asn_DEF_Rectangle, |
| 3084 | \layout LyX-Code |
| 3085 | |
| 3086 | |
| 3087 | \size small |
| 3088 | rectangle, errbuf, &errlen); |
| 3089 | \layout LyX-Code |
| 3090 | |
| 3091 | |
| 3092 | \size small |
| 3093 | /* assert(errlen < sizeof(errbuf)); // you may rely on that */ |
| 3094 | \layout LyX-Code |
| 3095 | |
| 3096 | |
| 3097 | \size small |
| 3098 | if(ret) { |
| 3099 | \layout LyX-Code |
| 3100 | |
| 3101 | |
| 3102 | \size small |
| 3103 | fprintf(stderr, |
| 3104 | \begin_inset Quotes sld |
| 3105 | \end_inset |
| 3106 | |
| 3107 | Constraint validation failed: %s |
| 3108 | \backslash |
| 3109 | n |
| 3110 | \begin_inset Quotes srd |
| 3111 | \end_inset |
| 3112 | |
| 3113 | , |
| 3114 | \layout LyX-Code |
| 3115 | |
| 3116 | |
| 3117 | \size small |
| 3118 | errbuf /* errbuf is properly nul-terminated */ |
| 3119 | \layout LyX-Code |
| 3120 | |
| 3121 | |
| 3122 | \size small |
| 3123 | ); |
| 3124 | \layout LyX-Code |
| 3125 | |
| 3126 | |
| 3127 | \size small |
| 3128 | /* exit(...); // Replace with appropriate action */ |
| 3129 | \layout LyX-Code |
| 3130 | |
| 3131 | |
| 3132 | \size small |
| 3133 | } |
| 3134 | \layout LyX-Code |
| 3135 | |
| 3136 | |
| 3137 | \size small |
| 3138 | |
| 3139 | \layout LyX-Code |
| 3140 | |
| 3141 | |
| 3142 | \size small |
| 3143 | /* ... |
| 3144 | here may go Rectangle encoding code ... |
| 3145 | */ |
| 3146 | \end_deeper |
| 3147 | \layout Enumerate |
| 3148 | |
| 3149 | Compile the resulting C code as shown in the previous chapters. |
| 3150 | \layout Enumerate |
| 3151 | |
vlm | 602b726 | 2005-02-02 11:06:38 +0000 | [diff] [blame] | 3152 | Try to test the constraints checking code by assigning integer value 101 |
| 3153 | to the |
| 3154 | \series bold |
| 3155 | .height |
| 3156 | \series default |
| 3157 | member of the Rectangle structure, or a negative value to the |
| 3158 | \series bold |
| 3159 | .width |
| 3160 | \series default |
| 3161 | member. |
| 3162 | In either case, the program should print |
| 3163 | \begin_inset Quotes sld |
| 3164 | \end_inset |
| 3165 | |
| 3166 | Constraint validation failed |
| 3167 | \begin_inset Quotes srd |
| 3168 | \end_inset |
| 3169 | |
| 3170 | message, followed by the short explanation why validation did not succeed. |
| 3171 | \layout Enumerate |
| 3172 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 3173 | Done. |
vlm | 856978f | 2005-02-21 14:16:10 +0000 | [diff] [blame] | 3174 | \layout Part |
| 3175 | |
| 3176 | |
| 3177 | \begin_inset LatexCommand \label{par:ASN.1-Basics} |
| 3178 | |
| 3179 | \end_inset |
| 3180 | |
| 3181 | ASN.1 Basics |
| 3182 | \layout Chapter |
| 3183 | |
| 3184 | |
| 3185 | \begin_inset LatexCommand \label{cha:Abstract-Syntax-Notation:} |
| 3186 | |
| 3187 | \end_inset |
| 3188 | |
| 3189 | Abstract Syntax Notation: ASN.1 |
| 3190 | \layout Standard |
| 3191 | |
| 3192 | |
| 3193 | \emph on |
| 3194 | This chapter defines some basic ASN.1 concepts and describes several most |
| 3195 | widely used types. |
| 3196 | It is by no means an authoritative or complete reference. |
| 3197 | For more complete ASN.1 description, please refer to Olivier Dubuisson's |
| 3198 | book |
| 3199 | \begin_inset LatexCommand \cite{Dub00} |
| 3200 | |
| 3201 | \end_inset |
| 3202 | |
| 3203 | or the ASN.1 body of standards itself |
| 3204 | \begin_inset LatexCommand \cite{ITU-T/ASN.1} |
| 3205 | |
| 3206 | \end_inset |
| 3207 | |
| 3208 | . |
| 3209 | \layout Standard |
| 3210 | |
| 3211 | The Abstract Syntax Notation One is used to formally describe the semantics |
| 3212 | of data transmitted across the network. |
| 3213 | Two communicating parties may have different formats of their native data |
| 3214 | types (i.e. |
| 3215 | number of bits in the integer type), thus it is important to have a way |
| 3216 | to describe the data in a manner which is independent from the particular |
| 3217 | machine's representation. |
| 3218 | The ASN.1 specifications are used to achieve the following: |
| 3219 | \layout Itemize |
| 3220 | |
| 3221 | The specification expressed in the ASN.1 notation is a formal and precise |
| 3222 | way to communicate the data semantics to human readers; |
| 3223 | \layout Itemize |
| 3224 | |
| 3225 | The ASN.1 specifications may be used as input for automatic compilers which |
| 3226 | produce the code for some target language (C, C++, Java, etc) to encode |
| 3227 | and decode the data according to some encoding rules (which are also defined |
| 3228 | by the ASN.1 standard). |
| 3229 | \layout Standard |
| 3230 | |
| 3231 | Consider the following example: |
| 3232 | \layout LyX-Code |
| 3233 | |
| 3234 | Rectangle ::= SEQUENCE { |
| 3235 | \layout LyX-Code |
| 3236 | |
| 3237 | height INTEGER, |
| 3238 | \layout LyX-Code |
| 3239 | |
| 3240 | width INTEGER |
| 3241 | \layout LyX-Code |
| 3242 | |
| 3243 | } |
| 3244 | \layout Standard |
| 3245 | |
| 3246 | This ASN.1 specification describes a constructed type, |
| 3247 | \emph on |
| 3248 | Rectangle |
| 3249 | \emph default |
| 3250 | , containing two integer fields. |
| 3251 | This specification may tell the reader that there exists this kind of data |
| 3252 | structure and that some entity may be prepared to send or receive it. |
| 3253 | The question on |
| 3254 | \emph on |
| 3255 | how |
| 3256 | \emph default |
| 3257 | that entity is going to send or receive the |
| 3258 | \emph on |
| 3259 | encoded data |
| 3260 | \emph default |
| 3261 | is outside the scope of ASN.1. |
| 3262 | For example, this data structure may be encoded according to some encoding |
| 3263 | rules and sent to the destination using the TCP protocol. |
| 3264 | The ASN.1 specifies several ways of encoding (or |
| 3265 | \begin_inset Quotes sld |
| 3266 | \end_inset |
| 3267 | |
| 3268 | serializing |
| 3269 | \begin_inset Quotes srd |
| 3270 | \end_inset |
| 3271 | |
| 3272 | , or |
| 3273 | \begin_inset Quotes sld |
| 3274 | \end_inset |
| 3275 | |
| 3276 | marshaling |
| 3277 | \begin_inset Quotes srd |
| 3278 | \end_inset |
| 3279 | |
| 3280 | ) the data: BER, PER, XER and others, including CER and DER derivatives |
| 3281 | from BER. |
| 3282 | \layout Standard |
| 3283 | |
| 3284 | The complete specification must be wrapped in a module, which looks like |
| 3285 | this: |
| 3286 | \layout LyX-Code |
| 3287 | |
| 3288 | RectangleModule1 |
| 3289 | \layout LyX-Code |
| 3290 | |
| 3291 | { iso org(3) dod(6) internet(1) private(4) |
| 3292 | \layout LyX-Code |
| 3293 | |
| 3294 | enterprise(1) spelio(9363) software(1) |
| 3295 | \layout LyX-Code |
| 3296 | |
| 3297 | asn1c(5) docs(2) rectangle(1) 1 } |
| 3298 | \layout LyX-Code |
| 3299 | |
| 3300 | DEFINITIONS AUTOMATIC TAGS ::= |
| 3301 | \layout LyX-Code |
| 3302 | |
| 3303 | BEGIN |
| 3304 | \layout LyX-Code |
| 3305 | |
| 3306 | |
| 3307 | \layout LyX-Code |
| 3308 | |
| 3309 | -- This is a comment which describes nothing. |
| 3310 | \layout LyX-Code |
| 3311 | |
| 3312 | Rectangle ::= SEQUENCE { |
| 3313 | \layout LyX-Code |
| 3314 | |
| 3315 | height INTEGER, -- Height of the rectangle |
| 3316 | \layout LyX-Code |
| 3317 | |
| 3318 | width INTEGER -- Width of the rectangle |
| 3319 | \layout LyX-Code |
| 3320 | |
| 3321 | } |
| 3322 | \layout LyX-Code |
| 3323 | |
| 3324 | |
| 3325 | \layout LyX-Code |
| 3326 | |
| 3327 | END |
| 3328 | \layout Standard |
| 3329 | |
| 3330 | The module header consists of module name (RectangleModule1), the module |
| 3331 | object identifier ({...}), a keyword |
| 3332 | \begin_inset Quotes sld |
| 3333 | \end_inset |
| 3334 | |
| 3335 | DEFINITIONS |
| 3336 | \begin_inset Quotes srd |
| 3337 | \end_inset |
| 3338 | |
| 3339 | , a set of module flags (AUTOMATIC TAGS) and |
| 3340 | \begin_inset Quotes sld |
| 3341 | \end_inset |
| 3342 | |
| 3343 | ::= BEGIN |
| 3344 | \begin_inset Quotes srd |
| 3345 | \end_inset |
| 3346 | |
| 3347 | . |
| 3348 | The module ends with an |
| 3349 | \begin_inset Quotes sld |
| 3350 | \end_inset |
| 3351 | |
| 3352 | END |
| 3353 | \begin_inset Quotes srd |
| 3354 | \end_inset |
| 3355 | |
| 3356 | statement. |
| 3357 | \layout Section |
| 3358 | |
| 3359 | Some of the ASN.1 Basic Types |
| 3360 | \layout Subsection |
| 3361 | |
| 3362 | The BOOLEAN type |
| 3363 | \layout Standard |
| 3364 | |
| 3365 | The BOOLEAN type models the simple binary TRUE/FALSE, YES/NO, ON/OFF or |
| 3366 | a similar kind of two-way choice. |
| 3367 | \layout Subsection |
| 3368 | |
| 3369 | The INTEGER type |
| 3370 | \layout Standard |
| 3371 | |
| 3372 | The INTEGER type is a signed natural number type without any restrictions |
| 3373 | on its size. |
| 3374 | If the automatic checking on INTEGER value bounds are necessary, the subtype |
| 3375 | constraints must be used. |
| 3376 | \layout LyX-Code |
| 3377 | |
| 3378 | SimpleInteger ::= INTEGER |
| 3379 | \layout LyX-Code |
| 3380 | |
| 3381 | |
| 3382 | \layout LyX-Code |
| 3383 | |
| 3384 | -- An integer with a very limited range |
| 3385 | \layout LyX-Code |
| 3386 | |
| 3387 | SmallPositiveInt ::= INTEGER (0..127) |
| 3388 | \layout LyX-Code |
| 3389 | |
| 3390 | |
| 3391 | \layout LyX-Code |
| 3392 | |
| 3393 | -- Integer, negative |
| 3394 | \layout LyX-Code |
| 3395 | |
| 3396 | NegativeInt ::= INTEGER (MIN..0) |
| 3397 | \layout Subsection |
| 3398 | |
| 3399 | The ENUMERATED type |
| 3400 | \layout Standard |
| 3401 | |
| 3402 | The ENUMERATED type is semantically equivalent to the INTEGER type with |
| 3403 | some integer values explicitly named. |
| 3404 | \layout LyX-Code |
| 3405 | |
| 3406 | FruitId ::= ENUMERATED { apple(1), orange(2) } |
| 3407 | \layout LyX-Code |
| 3408 | |
| 3409 | |
| 3410 | \layout LyX-Code |
| 3411 | |
| 3412 | -- The numbers in braces are optional, |
| 3413 | \layout LyX-Code |
| 3414 | |
| 3415 | -- the enumeration can be performed |
| 3416 | \layout LyX-Code |
| 3417 | |
| 3418 | -- automatically by the compiler |
| 3419 | \layout LyX-Code |
| 3420 | |
| 3421 | ComputerOSType ::= ENUMERATED { |
| 3422 | \layout LyX-Code |
| 3423 | |
| 3424 | FreeBSD, -- acquires value 0 |
| 3425 | \layout LyX-Code |
| 3426 | |
| 3427 | Windows, -- acquires value 1 |
| 3428 | \layout LyX-Code |
| 3429 | |
| 3430 | Solaris(5), -- remains 5 |
| 3431 | \layout LyX-Code |
| 3432 | |
| 3433 | Linux, -- becomes 6 |
| 3434 | \layout LyX-Code |
| 3435 | |
| 3436 | MacOS -- becomes 7 |
| 3437 | \layout LyX-Code |
| 3438 | |
| 3439 | } |
| 3440 | \layout Subsection |
| 3441 | |
| 3442 | The OCTET STRING type |
| 3443 | \layout Standard |
| 3444 | |
| 3445 | This type models the sequence of 8-bit bytes. |
| 3446 | This may be used to transmit some opaque data or data serialized by other |
| 3447 | types of encoders (i.e. |
| 3448 | video file, photo picture, etc). |
| 3449 | \layout Subsection |
| 3450 | |
| 3451 | The OBJECT IDENTIFIER type |
| 3452 | \layout Standard |
| 3453 | |
| 3454 | The OBJECT IDENTIFIER is used to represent the unique identifier of any |
| 3455 | object, starting from the very root of the registration tree. |
| 3456 | If your organization needs to uniquely identify something (a router, a |
| 3457 | room, a person, a standard, or whatever), you are encouraged to get your |
| 3458 | own identification subtree at |
| 3459 | \begin_inset LatexCommand \htmlurl{http://www.iana.org/protocols/forms.htm} |
| 3460 | |
| 3461 | \end_inset |
| 3462 | |
| 3463 | . |
| 3464 | \layout Standard |
| 3465 | |
| 3466 | For example, the very first ASN.1 module in this Chapter (RectangleModule1) |
| 3467 | has the following OBJECT IDENTIFIER: 1 3 6 1 4 1 9363 1 5 2 1 1. |
| 3468 | \layout LyX-Code |
| 3469 | |
| 3470 | ExampleOID ::= OBJECT IDENTIFIER |
| 3471 | \layout LyX-Code |
| 3472 | |
| 3473 | |
| 3474 | \layout LyX-Code |
| 3475 | |
| 3476 | rectangleModule1-oid ExampleOID |
| 3477 | \layout LyX-Code |
| 3478 | |
| 3479 | ::= { 1 3 6 1 4 1 9363 1 5 2 1 1 } |
| 3480 | \layout LyX-Code |
| 3481 | |
| 3482 | |
| 3483 | \layout LyX-Code |
| 3484 | |
| 3485 | -- An identifier of the Internet. |
| 3486 | \layout LyX-Code |
| 3487 | |
| 3488 | internet-id OBJECT IDENTIFIER |
| 3489 | \layout LyX-Code |
| 3490 | |
| 3491 | ::= { iso(1) identified-organization(3) |
| 3492 | \layout LyX-Code |
| 3493 | |
| 3494 | dod(6) internet(1) } |
| 3495 | \layout Standard |
| 3496 | |
| 3497 | As you see, names are optional. |
| 3498 | \layout Subsection |
| 3499 | |
| 3500 | The RELATIVE-OID type |
| 3501 | \layout Standard |
| 3502 | |
| 3503 | The RELATIVE-OID type has the semantics of a subtree of an OBJECT IDENTIFIER. |
| 3504 | There may be no need to repeat the whole sequence of numbers from the root |
| 3505 | of the registration tree where the only thing of interest is some of the |
| 3506 | tree's subsequence. |
| 3507 | \layout LyX-Code |
| 3508 | |
| 3509 | this-document RELATIVE-OID ::= { docs(2) usage(1) } |
| 3510 | \layout LyX-Code |
| 3511 | |
| 3512 | |
| 3513 | \layout LyX-Code |
| 3514 | |
| 3515 | this-example RELATIVE-OID ::= { |
| 3516 | \layout LyX-Code |
| 3517 | |
| 3518 | this-document assorted-examples(0) this-example(1) } |
| 3519 | \layout Section |
| 3520 | |
| 3521 | Some of the ASN.1 String Types |
| 3522 | \layout Subsection |
| 3523 | |
| 3524 | The IA5String type |
| 3525 | \layout Standard |
| 3526 | |
| 3527 | This is essentially the ASCII, with 128 character codes available (7 lower |
| 3528 | bits of an 8-bit byte). |
| 3529 | \layout Subsection |
| 3530 | |
| 3531 | The UTF8String type |
| 3532 | \layout Standard |
| 3533 | |
| 3534 | This is the character string which encodes the full Unicode range (4 bytes) |
| 3535 | using multibyte character sequences. |
| 3536 | \layout Subsection |
| 3537 | |
| 3538 | The NumericString type |
| 3539 | \layout Standard |
| 3540 | |
| 3541 | This type represents the character string with the alphabet consisting of |
| 3542 | numbers ( |
| 3543 | \begin_inset Quotes sld |
| 3544 | \end_inset |
| 3545 | |
| 3546 | 0 |
| 3547 | \begin_inset Quotes srd |
| 3548 | \end_inset |
| 3549 | |
| 3550 | to |
| 3551 | \begin_inset Quotes sld |
| 3552 | \end_inset |
| 3553 | |
| 3554 | 9 |
| 3555 | \begin_inset Quotes srd |
| 3556 | \end_inset |
| 3557 | |
| 3558 | ) and a space. |
| 3559 | \layout Subsection |
| 3560 | |
| 3561 | The PrintableString type |
| 3562 | \layout Standard |
| 3563 | |
| 3564 | The character string with the following alphabet: space, |
| 3565 | \begin_inset Quotes sld |
| 3566 | \end_inset |
| 3567 | |
| 3568 | |
| 3569 | \series bold |
| 3570 | ' |
| 3571 | \series default |
| 3572 | |
| 3573 | \begin_inset Quotes srd |
| 3574 | \end_inset |
| 3575 | |
| 3576 | (single quote), |
| 3577 | \begin_inset Quotes sld |
| 3578 | \end_inset |
| 3579 | |
| 3580 | |
| 3581 | \series bold |
| 3582 | ( |
| 3583 | \series default |
| 3584 | |
| 3585 | \begin_inset Quotes sld |
| 3586 | \end_inset |
| 3587 | |
| 3588 | , |
| 3589 | \begin_inset Quotes sld |
| 3590 | \end_inset |
| 3591 | |
| 3592 | |
| 3593 | \series bold |
| 3594 | ) |
| 3595 | \series default |
| 3596 | |
| 3597 | \begin_inset Quotes srd |
| 3598 | \end_inset |
| 3599 | |
| 3600 | , |
| 3601 | \begin_inset Quotes sld |
| 3602 | \end_inset |
| 3603 | |
| 3604 | |
| 3605 | \series bold |
| 3606 | + |
| 3607 | \series default |
| 3608 | |
| 3609 | \begin_inset Quotes srd |
| 3610 | \end_inset |
| 3611 | |
| 3612 | , |
| 3613 | \begin_inset Quotes sld |
| 3614 | \end_inset |
| 3615 | |
| 3616 | |
| 3617 | \series bold |
| 3618 | , |
| 3619 | \series default |
| 3620 | |
| 3621 | \begin_inset Quotes srd |
| 3622 | \end_inset |
| 3623 | |
| 3624 | (comma), |
| 3625 | \begin_inset Quotes sld |
| 3626 | \end_inset |
| 3627 | |
| 3628 | |
| 3629 | \series bold |
| 3630 | - |
| 3631 | \series default |
| 3632 | |
| 3633 | \begin_inset Quotes srd |
| 3634 | \end_inset |
| 3635 | |
| 3636 | , |
| 3637 | \begin_inset Quotes sld |
| 3638 | \end_inset |
| 3639 | |
| 3640 | |
| 3641 | \series bold |
| 3642 | . |
| 3643 | \series default |
| 3644 | |
| 3645 | \begin_inset Quotes srd |
| 3646 | \end_inset |
| 3647 | |
| 3648 | , |
| 3649 | \begin_inset Quotes sld |
| 3650 | \end_inset |
| 3651 | |
| 3652 | |
| 3653 | \series bold |
| 3654 | / |
| 3655 | \series default |
| 3656 | |
| 3657 | \begin_inset Quotes srd |
| 3658 | \end_inset |
| 3659 | |
| 3660 | , digits ( |
| 3661 | \begin_inset Quotes sld |
| 3662 | \end_inset |
| 3663 | |
| 3664 | 0 |
| 3665 | \begin_inset Quotes srd |
| 3666 | \end_inset |
| 3667 | |
| 3668 | to |
| 3669 | \begin_inset Quotes sld |
| 3670 | \end_inset |
| 3671 | |
| 3672 | 9 |
| 3673 | \begin_inset Quotes srd |
| 3674 | \end_inset |
| 3675 | |
| 3676 | ), |
| 3677 | \begin_inset Quotes sld |
| 3678 | \end_inset |
| 3679 | |
| 3680 | |
| 3681 | \series bold |
| 3682 | : |
| 3683 | \series default |
| 3684 | |
| 3685 | \begin_inset Quotes srd |
| 3686 | \end_inset |
| 3687 | |
| 3688 | , |
| 3689 | \begin_inset Quotes sld |
| 3690 | \end_inset |
| 3691 | |
| 3692 | |
| 3693 | \series bold |
| 3694 | = |
| 3695 | \series default |
| 3696 | |
| 3697 | \begin_inset Quotes srd |
| 3698 | \end_inset |
| 3699 | |
| 3700 | , |
| 3701 | \begin_inset Quotes sld |
| 3702 | \end_inset |
| 3703 | |
| 3704 | |
| 3705 | \series bold |
| 3706 | ? |
| 3707 | \series default |
| 3708 | |
| 3709 | \begin_inset Quotes srd |
| 3710 | \end_inset |
| 3711 | |
| 3712 | , upper-case and lower-case letters ( |
| 3713 | \begin_inset Quotes sld |
| 3714 | \end_inset |
| 3715 | |
| 3716 | A |
| 3717 | \begin_inset Quotes srd |
| 3718 | \end_inset |
| 3719 | |
| 3720 | to |
| 3721 | \begin_inset Quotes sld |
| 3722 | \end_inset |
| 3723 | |
| 3724 | Z |
| 3725 | \begin_inset Quotes srd |
| 3726 | \end_inset |
| 3727 | |
| 3728 | and |
| 3729 | \begin_inset Quotes sld |
| 3730 | \end_inset |
| 3731 | |
| 3732 | a |
| 3733 | \begin_inset Quotes srd |
| 3734 | \end_inset |
| 3735 | |
| 3736 | to |
| 3737 | \begin_inset Quotes sld |
| 3738 | \end_inset |
| 3739 | |
| 3740 | z |
| 3741 | \begin_inset Quotes srd |
| 3742 | \end_inset |
| 3743 | |
| 3744 | ). |
| 3745 | \layout Subsection |
| 3746 | |
| 3747 | The VisibleString type |
| 3748 | \layout Standard |
| 3749 | |
| 3750 | The character string with the alphabet which is more or less a subset of |
| 3751 | ASCII between the space and the |
| 3752 | \begin_inset Quotes sld |
| 3753 | \end_inset |
| 3754 | |
| 3755 | |
| 3756 | \series bold |
| 3757 | ~ |
| 3758 | \series default |
| 3759 | |
| 3760 | \begin_inset Quotes srd |
| 3761 | \end_inset |
| 3762 | |
| 3763 | symbol (tilde). |
| 3764 | \layout Standard |
| 3765 | |
| 3766 | Alternatively, the alphabet may be described as the PrintableString alphabet |
| 3767 | presented earlier, plus the following characters: |
| 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 | \begin_inset Quotes srd |
| 3787 | \end_inset |
| 3788 | |
| 3789 | |
| 3790 | \series default |
| 3791 | |
| 3792 | \begin_inset Quotes srd |
| 3793 | \end_inset |
| 3794 | |
| 3795 | , |
| 3796 | \begin_inset Quotes sld |
| 3797 | \end_inset |
| 3798 | |
| 3799 | |
| 3800 | \series bold |
| 3801 | # |
| 3802 | \series default |
| 3803 | |
| 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 | , |
| 3844 | \begin_inset Quotes sld |
| 3845 | \end_inset |
| 3846 | |
| 3847 | |
| 3848 | \series bold |
| 3849 | * |
| 3850 | \series default |
| 3851 | |
| 3852 | \begin_inset Quotes srd |
| 3853 | \end_inset |
| 3854 | |
| 3855 | , |
| 3856 | \begin_inset Quotes sld |
| 3857 | \end_inset |
| 3858 | |
| 3859 | |
| 3860 | \series bold |
| 3861 | ; |
| 3862 | \series default |
| 3863 | |
| 3864 | \begin_inset Quotes srd |
| 3865 | \end_inset |
| 3866 | |
| 3867 | , |
| 3868 | \begin_inset Quotes sld |
| 3869 | \end_inset |
| 3870 | |
| 3871 | |
| 3872 | \series bold |
| 3873 | < |
| 3874 | \series default |
| 3875 | |
| 3876 | \begin_inset Quotes srd |
| 3877 | \end_inset |
| 3878 | |
| 3879 | , |
| 3880 | \begin_inset Quotes sld |
| 3881 | \end_inset |
| 3882 | |
| 3883 | |
| 3884 | \series bold |
| 3885 | > |
| 3886 | \series default |
| 3887 | |
| 3888 | \begin_inset Quotes srd |
| 3889 | \end_inset |
| 3890 | |
| 3891 | , |
| 3892 | \begin_inset Quotes sld |
| 3893 | \end_inset |
| 3894 | |
| 3895 | |
| 3896 | \series bold |
| 3897 | [ |
| 3898 | \series default |
| 3899 | |
| 3900 | \begin_inset Quotes srd |
| 3901 | \end_inset |
| 3902 | |
| 3903 | , |
| 3904 | \begin_inset Quotes sld |
| 3905 | \end_inset |
| 3906 | |
| 3907 | |
| 3908 | \series bold |
| 3909 | |
| 3910 | \backslash |
| 3911 | |
| 3912 | \series default |
| 3913 | |
| 3914 | \begin_inset Quotes srd |
| 3915 | \end_inset |
| 3916 | |
| 3917 | , |
| 3918 | \begin_inset Quotes sld |
| 3919 | \end_inset |
| 3920 | |
| 3921 | |
| 3922 | \series bold |
| 3923 | ] |
| 3924 | \series default |
| 3925 | |
| 3926 | \begin_inset Quotes srd |
| 3927 | \end_inset |
| 3928 | |
| 3929 | , |
| 3930 | \begin_inset Quotes sld |
| 3931 | \end_inset |
| 3932 | |
| 3933 | |
| 3934 | \series bold |
| 3935 | ^ |
| 3936 | \series default |
| 3937 | |
| 3938 | \begin_inset Quotes srd |
| 3939 | \end_inset |
| 3940 | |
| 3941 | , |
| 3942 | \begin_inset Quotes sld |
| 3943 | \end_inset |
| 3944 | |
| 3945 | |
| 3946 | \series bold |
| 3947 | _ |
| 3948 | \series default |
| 3949 | |
| 3950 | \begin_inset Quotes srd |
| 3951 | \end_inset |
| 3952 | |
| 3953 | , |
| 3954 | \begin_inset Quotes sld |
| 3955 | \end_inset |
| 3956 | |
| 3957 | |
| 3958 | \series bold |
| 3959 | ` |
| 3960 | \series default |
| 3961 | |
| 3962 | \begin_inset Quotes srd |
| 3963 | \end_inset |
| 3964 | |
| 3965 | (single left quote), |
| 3966 | \begin_inset Quotes sld |
| 3967 | \end_inset |
| 3968 | |
| 3969 | |
| 3970 | \series bold |
| 3971 | { |
| 3972 | \series default |
| 3973 | |
| 3974 | \begin_inset Quotes srd |
| 3975 | \end_inset |
| 3976 | |
| 3977 | , |
| 3978 | \begin_inset Quotes sld |
| 3979 | \end_inset |
| 3980 | |
| 3981 | |
| 3982 | \series bold |
| 3983 | | |
| 3984 | \series default |
| 3985 | |
| 3986 | \begin_inset Quotes srd |
| 3987 | \end_inset |
| 3988 | |
| 3989 | , |
| 3990 | \begin_inset Quotes sld |
| 3991 | \end_inset |
| 3992 | |
| 3993 | |
| 3994 | \series bold |
| 3995 | } |
| 3996 | \series default |
| 3997 | |
| 3998 | \begin_inset Quotes srd |
| 3999 | \end_inset |
| 4000 | |
| 4001 | , |
| 4002 | \begin_inset Quotes sld |
| 4003 | \end_inset |
| 4004 | |
| 4005 | |
| 4006 | \series bold |
| 4007 | ~ |
| 4008 | \series default |
| 4009 | |
| 4010 | \begin_inset Quotes srd |
| 4011 | \end_inset |
| 4012 | |
| 4013 | . |
| 4014 | \layout Section |
| 4015 | |
| 4016 | ASN.1 Constructed Types |
| 4017 | \layout Subsection |
| 4018 | |
| 4019 | The SEQUENCE type |
| 4020 | \layout Standard |
| 4021 | |
| 4022 | This is an ordered collection of other simple or constructed types. |
| 4023 | The SEQUENCE constructed type resembles the C |
| 4024 | \begin_inset Quotes sld |
| 4025 | \end_inset |
| 4026 | |
| 4027 | struct |
| 4028 | \begin_inset Quotes srd |
| 4029 | \end_inset |
| 4030 | |
| 4031 | statement. |
| 4032 | \layout LyX-Code |
| 4033 | |
| 4034 | Address ::= SEQUENCE { |
| 4035 | \layout LyX-Code |
| 4036 | |
| 4037 | -- The apartment number may be omitted |
| 4038 | \layout LyX-Code |
| 4039 | |
| 4040 | apartmentNumber NumericString OPTIONAL, |
| 4041 | \layout LyX-Code |
| 4042 | |
| 4043 | streetName PrintableString, |
| 4044 | \layout LyX-Code |
| 4045 | |
| 4046 | cityName PrintableString, |
| 4047 | \layout LyX-Code |
| 4048 | |
| 4049 | stateName PrintableString, |
| 4050 | \layout LyX-Code |
| 4051 | |
| 4052 | -- This one may be omitted too |
| 4053 | \layout LyX-Code |
| 4054 | |
| 4055 | zipNo NumericString OPTIONAL |
| 4056 | \layout LyX-Code |
| 4057 | |
| 4058 | } |
| 4059 | \layout Subsection |
| 4060 | |
| 4061 | The SET type |
| 4062 | \layout Standard |
| 4063 | |
| 4064 | This is a collection of other simple or constructed types. |
| 4065 | Ordering is not important. |
| 4066 | The data may arrive in the order which is different from the order of specifica |
| 4067 | tion. |
| 4068 | Data is encoded in the order not necessarily corresponding to the order |
| 4069 | of specification. |
| 4070 | \layout Subsection |
| 4071 | |
| 4072 | The CHOICE type |
| 4073 | \layout Standard |
| 4074 | |
| 4075 | This type is just a choice between the subtypes specified in it. |
| 4076 | The CHOICE type contains at most one of the subtypes specified, and it |
| 4077 | is always implicitly known which choice is being decoded or encoded. |
| 4078 | This one resembles the C |
| 4079 | \begin_inset Quotes sld |
| 4080 | \end_inset |
| 4081 | |
| 4082 | union |
| 4083 | \begin_inset Quotes srd |
| 4084 | \end_inset |
| 4085 | |
| 4086 | statement. |
| 4087 | \layout Standard |
| 4088 | |
| 4089 | The following type defines a response code, which may be either an integer |
| 4090 | code or a boolean |
| 4091 | \begin_inset Quotes sld |
| 4092 | \end_inset |
| 4093 | |
| 4094 | true |
| 4095 | \begin_inset Quotes srd |
| 4096 | \end_inset |
| 4097 | |
| 4098 | / |
| 4099 | \begin_inset Quotes srd |
| 4100 | \end_inset |
| 4101 | |
| 4102 | false |
| 4103 | \begin_inset Quotes srd |
| 4104 | \end_inset |
| 4105 | |
| 4106 | code. |
| 4107 | \layout LyX-Code |
| 4108 | |
| 4109 | ResponseCode ::= CHOICE { |
| 4110 | \layout LyX-Code |
| 4111 | |
| 4112 | intCode INTEGER, |
| 4113 | \layout LyX-Code |
| 4114 | |
| 4115 | boolCode BOOLEAN |
| 4116 | \layout LyX-Code |
| 4117 | |
| 4118 | } |
| 4119 | \layout LyX-Code |
| 4120 | |
| 4121 | \layout Subsection |
| 4122 | |
| 4123 | The SEQUENCE OF type |
| 4124 | \layout Standard |
| 4125 | |
| 4126 | This one is the list (array) of simple or constructed types: |
| 4127 | \layout LyX-Code |
| 4128 | |
| 4129 | -- Example 1 |
| 4130 | \layout LyX-Code |
| 4131 | |
| 4132 | ManyIntegers ::= SEQUENCE OF INTEGER |
| 4133 | \layout LyX-Code |
| 4134 | |
| 4135 | |
| 4136 | \layout LyX-Code |
| 4137 | |
| 4138 | -- Example 2 |
| 4139 | \layout LyX-Code |
| 4140 | |
| 4141 | ManyRectangles ::= SEQUENCE OF Rectangle |
| 4142 | \layout LyX-Code |
| 4143 | |
| 4144 | |
| 4145 | \layout LyX-Code |
| 4146 | |
| 4147 | -- More complex example: |
| 4148 | \layout LyX-Code |
| 4149 | |
| 4150 | -- an array of structures defined in place. |
| 4151 | \layout LyX-Code |
| 4152 | |
| 4153 | ManyCircles ::= SEQUENCE OF SEQUENCE { |
| 4154 | \layout LyX-Code |
| 4155 | |
| 4156 | radius INTEGER |
| 4157 | \layout LyX-Code |
| 4158 | |
| 4159 | } |
| 4160 | \layout Subsection |
| 4161 | |
| 4162 | The SET OF type |
| 4163 | \layout Standard |
| 4164 | |
| 4165 | The SET OF type models the bag of structures. |
| 4166 | It resembles the SEQUENCE OF type, but the order is not important: i.e. |
| 4167 | the elements may arrive in the order which is not necessarily the same |
| 4168 | as the in-memory order on the remote machines. |
| 4169 | \layout LyX-Code |
| 4170 | |
| 4171 | -- A set of structures defined elsewhere |
| 4172 | \layout LyX-Code |
| 4173 | |
| 4174 | SetOfApples :: SET OF Apple |
| 4175 | \layout LyX-Code |
| 4176 | |
| 4177 | |
| 4178 | \layout LyX-Code |
| 4179 | |
| 4180 | -- Set of integers encoding the kind of a fruit |
| 4181 | \layout LyX-Code |
| 4182 | |
| 4183 | FruitBag ::= SET OF ENUMERATED { apple, orange } |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 4184 | \layout Bibliography |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 4185 | \bibitem [ASN1C]{ASN1C} |
| 4186 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 4187 | The Open Source ASN.1 Compiler. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 4188 | |
vlm | c7737f6 | 2005-02-02 09:53:46 +0000 | [diff] [blame] | 4189 | \begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 4190 | |
| 4191 | \end_inset |
| 4192 | |
| 4193 | |
| 4194 | \layout Bibliography |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame] | 4195 | \bibitem [AONL]{AONL} |
| 4196 | |
| 4197 | Online ASN.1 Compiler. |
| 4198 | |
| 4199 | \begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c/asn1c.cgi} |
| 4200 | |
| 4201 | \end_inset |
| 4202 | |
| 4203 | |
| 4204 | \layout Bibliography |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 4205 | \bibitem [Dub00]{Dub00} |
| 4206 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 4207 | Olivier Dubuisson --- |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 4208 | \emph on |
| 4209 | ASN.1 Communication between heterogeneous systems |
| 4210 | \emph default |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 4211 | --- Morgan Kaufmann Publishers, 2000. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 4212 | |
| 4213 | \begin_inset LatexCommand \htmlurl{http://asn1.elibel.tm.fr/en/book/} |
| 4214 | |
| 4215 | \end_inset |
| 4216 | |
| 4217 | . |
| 4218 | ISBN:0-12-6333361-0. |
| 4219 | \layout Bibliography |
| 4220 | \bibitem [ITU-T/ASN.1]{ITU-T/ASN.1} |
| 4221 | |
| 4222 | ITU-T Study Group 17 -- Languages for Telecommunication Systems |
| 4223 | \begin_inset LatexCommand \url{http://www.itu.int/ITU-T/studygroups/com17/languages/} |
| 4224 | |
| 4225 | \end_inset |
| 4226 | |
| 4227 | |
| 4228 | \the_end |