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