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