vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1 | #LyX 1.3 created this file. For more info see http://www.lyx.org/ |
| 2 | \lyxformat 221 |
| 3 | \textclass book |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 4 | \begin_preamble |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 5 | \usepackage{extramarks} |
| 6 | \lhead{\firstxmark} |
| 7 | \rfoot{\lastxmark} |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 8 | \usepackage{color} |
| 9 | \definecolor{gray40}{gray}{.4} |
| 10 | \definecolor{urlblue}{rgb}{0,0,.6} |
| 11 | \usepackage[colorlinks=true, |
| 12 | linkcolor={gray40}, |
| 13 | urlcolor={urlblue}, |
| 14 | pdfauthor={Lev Walkin}, |
| 15 | pdftitle={Using the OpenSource ASN.1 Compiler}, |
| 16 | pdfkeywords={ASN.1,asn1c,compiler} |
| 17 | ]{hyperref} |
| 18 | %\fancyhf{} |
| 19 | %\fancyhead[LE,RO]{\thepage} |
| 20 | %\fancyhead[LO]{\rightmark} |
| 21 | %\fancyhead[RE]{\leftmark} |
| 22 | %\fancyfoot[R]{\lastxmark} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 23 | \end_preamble |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 24 | \language english |
| 25 | \inputencoding latin1 |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 26 | \fontscheme times |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 27 | \graphics default |
| 28 | \paperfontsize default |
| 29 | \spacing single |
| 30 | \papersize Default |
| 31 | \paperpackage a4 |
| 32 | \use_geometry 0 |
| 33 | \use_amsmath 0 |
| 34 | \use_natbib 0 |
| 35 | \use_numerical_citations 0 |
| 36 | \paperorientation portrait |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 37 | \secnumdepth 2 |
| 38 | \tocdepth 2 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 39 | \paragraph_separation indent |
| 40 | \defskip medskip |
| 41 | \quotes_language swedish |
| 42 | \quotes_times 2 |
| 43 | \papercolumns 1 |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 44 | \papersides 2 |
| 45 | \paperpagestyle fancy |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 46 | |
| 47 | \layout Title |
| 48 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 49 | Using the OpenSource ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 50 | \layout Author |
| 51 | |
| 52 | Lev Walkin < |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 53 | \begin_inset ERT |
| 54 | status Collapsed |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 55 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 56 | \layout Standard |
| 57 | |
| 58 | \backslash |
| 59 | href{mailto:vlm@lionet.info?Subject=asn1c}{vlm@lionet.info} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 60 | \end_inset |
| 61 | |
| 62 | > |
| 63 | \layout Standard |
| 64 | |
| 65 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 66 | \begin_inset ERT |
| 67 | status Open |
| 68 | |
| 69 | \layout Standard |
| 70 | |
| 71 | \backslash |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 72 | lhead{Document describes |
| 73 | \backslash |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 74 | href{http://lionet.info/asn1c}{asn1c-0.9.8}} |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 75 | \layout Standard |
| 76 | |
| 77 | \backslash |
| 78 | rhead{$Revision$} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 79 | \end_inset |
| 80 | |
| 81 | |
| 82 | \layout Standard |
| 83 | |
| 84 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 85 | \begin_inset LatexCommand \tableofcontents{} |
| 86 | |
| 87 | \end_inset |
| 88 | |
| 89 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 90 | \layout Standard |
| 91 | |
| 92 | |
| 93 | \begin_inset ERT |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 94 | status Open |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 95 | |
| 96 | \layout Standard |
| 97 | |
| 98 | \backslash |
| 99 | pagestyle{headings} |
| 100 | \end_inset |
| 101 | |
| 102 | |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 103 | \layout Part |
| 104 | |
| 105 | ASN.1 Basics |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 106 | \layout Chapter |
| 107 | |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 108 | Abstract Syntax Notation: ASN.1 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 109 | \layout Standard |
| 110 | |
| 111 | |
| 112 | \emph on |
| 113 | This chapter defines some basic ASN.1 concepts and describes several most |
| 114 | widely used types. |
| 115 | It is by no means an authoritative or complete reference. |
| 116 | For more complete ASN.1 description, please refer to Olivier Dubuisson's |
| 117 | book |
| 118 | \begin_inset LatexCommand \cite{Dub00} |
| 119 | |
| 120 | \end_inset |
| 121 | |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 122 | or the ASN.1 body of standards itself |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 123 | \begin_inset LatexCommand \cite{ITU-T/ASN.1} |
| 124 | |
| 125 | \end_inset |
| 126 | |
| 127 | . |
| 128 | \layout Standard |
| 129 | |
| 130 | The Abstract Syntax Notation One is used to formally describe the semantics |
| 131 | of data transmitted across the network. |
| 132 | Two communicating parties may have different formats of their native data |
| 133 | types (i.e. |
| 134 | number of bits in the integer type), thus it is important to have a way |
| 135 | to describe the data in a manner which is independent from the particular |
| 136 | machine's representation. |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 137 | The ASN.1 specifications are used to achieve the following: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 138 | \layout Itemize |
| 139 | |
| 140 | The specification expressed in the ASN.1 notation is a formal and precise |
| 141 | way to communicate the data semantics to human readers; |
| 142 | \layout Itemize |
| 143 | |
| 144 | The ASN.1 specifications may be used as input for automatic compilers which |
| 145 | produce the code for some target language (C, C++, Java, etc) to encode |
| 146 | and decode the data according to some encoding rules (which are also defined |
| 147 | by the ASN.1 standard). |
| 148 | \layout Standard |
| 149 | |
| 150 | Consider the following example: |
| 151 | \layout LyX-Code |
| 152 | |
| 153 | Rectangle ::= SEQUENCE { |
| 154 | \layout LyX-Code |
| 155 | |
| 156 | height INTEGER, |
| 157 | \layout LyX-Code |
| 158 | |
| 159 | width INTEGER |
| 160 | \layout LyX-Code |
| 161 | |
| 162 | } |
| 163 | \layout Standard |
| 164 | |
| 165 | This ASN.1 specification describes a constructed type, |
| 166 | \emph on |
| 167 | Rectangle |
| 168 | \emph default |
| 169 | , containing two integer fields. |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 170 | This specification may tell the reader that there exists this kind of data |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 171 | structure and that some entity may be prepared to send or receive it. |
| 172 | The question on |
| 173 | \emph on |
| 174 | how |
| 175 | \emph default |
| 176 | that entity is going to send or receive the |
| 177 | \emph on |
| 178 | encoded data |
| 179 | \emph default |
| 180 | is outside the scope of ASN.1. |
| 181 | For example, this data structure may be encoded according to some encoding |
| 182 | rules and sent to the destination using the TCP protocol. |
| 183 | The ASN.1 specifies several ways of encoding (or |
| 184 | \begin_inset Quotes sld |
| 185 | \end_inset |
| 186 | |
| 187 | serializing |
| 188 | \begin_inset Quotes srd |
| 189 | \end_inset |
| 190 | |
| 191 | , or |
| 192 | \begin_inset Quotes sld |
| 193 | \end_inset |
| 194 | |
| 195 | marshaling |
| 196 | \begin_inset Quotes srd |
| 197 | \end_inset |
| 198 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 199 | ) the data: BER, CER, DER and XER, some of them which will be outlined later. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 200 | \layout Standard |
| 201 | |
| 202 | The complete specification must be wrapped in a module, which looks like |
| 203 | this: |
| 204 | \layout LyX-Code |
| 205 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 206 | RectangleModule1 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 207 | \layout LyX-Code |
| 208 | |
| 209 | { iso org(3) dod(6) internet(1) private(4) |
| 210 | \layout LyX-Code |
| 211 | |
| 212 | enterprise(1) spelio(9363) software(1) |
| 213 | \layout LyX-Code |
| 214 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 215 | asn1c(5) docs(2) rectangle(1) 1 } |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 216 | \layout LyX-Code |
| 217 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 218 | DEFINITIONS AUTOMATIC TAGS ::= |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 219 | \layout LyX-Code |
| 220 | |
| 221 | BEGIN |
| 222 | \layout LyX-Code |
| 223 | |
| 224 | |
| 225 | \layout LyX-Code |
| 226 | |
| 227 | -- This is a comment which describes nothing. |
| 228 | \layout LyX-Code |
| 229 | |
| 230 | Rectangle ::= SEQUENCE { |
| 231 | \layout LyX-Code |
| 232 | |
| 233 | height INTEGER, -- Height of the rectangle |
| 234 | \layout LyX-Code |
| 235 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 236 | width INTEGER -- Width of the rectangle |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 237 | \layout LyX-Code |
| 238 | |
| 239 | } |
| 240 | \layout LyX-Code |
| 241 | |
| 242 | |
| 243 | \layout LyX-Code |
| 244 | |
| 245 | END |
| 246 | \layout Standard |
| 247 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 248 | The module header consists of module name (RectangleModule1), the module |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 249 | object identifier ({...}), a keyword |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 250 | \begin_inset Quotes sld |
| 251 | \end_inset |
| 252 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 253 | DEFINITIONS |
| 254 | \begin_inset Quotes srd |
| 255 | \end_inset |
| 256 | |
| 257 | , a set of module flags (AUTOMATIC TAGS) and |
| 258 | \begin_inset Quotes sld |
| 259 | \end_inset |
| 260 | |
| 261 | ::= BEGIN |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 262 | \begin_inset Quotes srd |
| 263 | \end_inset |
| 264 | |
| 265 | . |
| 266 | The module ends with an |
| 267 | \begin_inset Quotes sld |
| 268 | \end_inset |
| 269 | |
| 270 | END |
| 271 | \begin_inset Quotes srd |
| 272 | \end_inset |
| 273 | |
| 274 | statement. |
| 275 | \layout Section |
| 276 | |
| 277 | Some of the ASN.1 Basic Types |
| 278 | \layout Subsection |
| 279 | |
| 280 | The BOOLEAN type |
| 281 | \layout Standard |
| 282 | |
| 283 | The BOOLEAN type models the simple binary TRUE/FALSE, YES/NO, ON/OFF or |
| 284 | a similar kind of two-way choice. |
| 285 | \layout Subsection |
| 286 | |
| 287 | The INTEGER type |
| 288 | \layout Standard |
| 289 | |
| 290 | The INTEGER type is a signed natural number type without any restrictions |
| 291 | on its size. |
| 292 | If the automatic checking on INTEGER value bounds are necessary, the subtype |
| 293 | constraints must be used. |
| 294 | \layout LyX-Code |
| 295 | |
| 296 | SimpleInteger ::= INTEGER |
| 297 | \layout LyX-Code |
| 298 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 299 | |
| 300 | \layout LyX-Code |
| 301 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 302 | -- An integer with a very limited range |
| 303 | \layout LyX-Code |
| 304 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 305 | SmallPositiveInt ::= INTEGER (0..127) |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 306 | \layout LyX-Code |
| 307 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 308 | |
| 309 | \layout LyX-Code |
| 310 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 311 | -- Integer, negative |
| 312 | \layout LyX-Code |
| 313 | |
| 314 | NegativeInt ::= INTEGER (MIN..0) |
| 315 | \layout Subsection |
| 316 | |
| 317 | The ENUMERATED type |
| 318 | \layout Standard |
| 319 | |
| 320 | The ENUMERATED type is semantically equivalent to the INTEGER type with |
| 321 | some integer values explicitly named. |
| 322 | \layout LyX-Code |
| 323 | |
| 324 | FruitId ::= ENUMERATED { apple(1), orange(2) } |
| 325 | \layout LyX-Code |
| 326 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 327 | |
| 328 | \layout LyX-Code |
| 329 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 330 | -- The numbers in braces are optional, |
| 331 | \layout LyX-Code |
| 332 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 333 | -- the enumeration can be performed |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 334 | \layout LyX-Code |
| 335 | |
| 336 | -- automatically by the compiler |
| 337 | \layout LyX-Code |
| 338 | |
| 339 | ComputerOSType ::= ENUMERATED { |
| 340 | \layout LyX-Code |
| 341 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 342 | FreeBSD, -- acquires value 0 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 343 | \layout LyX-Code |
| 344 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 345 | Windows, -- acquires value 1 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 346 | \layout LyX-Code |
| 347 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 348 | Solaris(5), -- remains 5 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 349 | \layout LyX-Code |
| 350 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 351 | Linux, -- becomes 6 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 352 | \layout LyX-Code |
| 353 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 354 | MacOS -- becomes 7 |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 355 | \layout LyX-Code |
| 356 | |
| 357 | } |
| 358 | \layout Subsection |
| 359 | |
| 360 | The OCTET STRING type |
| 361 | \layout Standard |
| 362 | |
| 363 | This type models the sequence of 8-bit bytes. |
| 364 | This may be used to transmit some opaque data or data serialized by other |
| 365 | types of encoders (i.e. |
| 366 | video file, photo picture, etc). |
| 367 | \layout Subsection |
| 368 | |
| 369 | The OBJECT IDENTIFIER type |
| 370 | \layout Standard |
| 371 | |
| 372 | The OBJECT IDENTIFIER is used to represent the unique identifier of any |
| 373 | object, starting from the very root of the registration tree. |
| 374 | If your organization needs to uniquely identify something (a router, a |
| 375 | room, a person, a standard, or whatever), you are encouraged to get your |
| 376 | own identification subtree at |
| 377 | \begin_inset LatexCommand \htmlurl{http://www.iana.org/protocols/forms.htm} |
| 378 | |
| 379 | \end_inset |
| 380 | |
| 381 | . |
| 382 | \layout Standard |
| 383 | |
| 384 | For example, the very first ASN.1 module in this document has the following |
| 385 | OBJECT IDENTIFIER: 1 3 6 1 4 1 9363 1 5 2 1 1. |
| 386 | \layout LyX-Code |
| 387 | |
| 388 | ExampleOID ::= OBJECT IDENTIFIER |
| 389 | \layout LyX-Code |
| 390 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 391 | |
| 392 | \layout LyX-Code |
| 393 | |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 394 | rectangleModule1-oid ExampleOID |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 395 | \layout LyX-Code |
| 396 | |
| 397 | ::= { 1 3 6 1 4 1 9363 1 5 2 1 1 } |
| 398 | \layout LyX-Code |
| 399 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 400 | |
| 401 | \layout LyX-Code |
| 402 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 403 | -- An identifier of the Internet. |
| 404 | \layout LyX-Code |
| 405 | |
| 406 | internet-id OBJECT IDENTIFIER |
| 407 | \layout LyX-Code |
| 408 | |
| 409 | ::= { iso(1) identified-organization(3) |
| 410 | \layout LyX-Code |
| 411 | |
| 412 | dod(6) internet(1) } |
| 413 | \layout Standard |
| 414 | |
| 415 | As you see, names are optional. |
| 416 | \layout Subsection |
| 417 | |
| 418 | The RELATIVE-OID type |
| 419 | \layout Standard |
| 420 | |
| 421 | The RELATIVE-OID type has the semantics of a subtree of an OBJECT IDENTIFIER. |
| 422 | There may be no need to repeat the whole sequence of numbers from the root |
| 423 | of the registration tree where the only thing of interest is some of the |
| 424 | tree's subsequence. |
| 425 | \layout LyX-Code |
| 426 | |
| 427 | this-document RELATIVE-OID ::= { docs(2) usage(1) } |
| 428 | \layout LyX-Code |
| 429 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 430 | |
| 431 | \layout LyX-Code |
| 432 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 433 | this-example RELATIVE-OID ::= { |
| 434 | \layout LyX-Code |
| 435 | |
| 436 | this-document assorted-examples(0) this-example(1) } |
| 437 | \layout Section |
| 438 | |
| 439 | Some of the ASN.1 String Types |
| 440 | \layout Subsection |
| 441 | |
| 442 | The IA5String type |
| 443 | \layout Standard |
| 444 | |
| 445 | This is essentially the ASCII, with 128 character codes available (7 lower |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 446 | bits of an 8-bit byte). |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 447 | \layout Subsection |
| 448 | |
| 449 | The UTF8String type |
| 450 | \layout Standard |
| 451 | |
| 452 | This is the character string which encodes the full Unicode range (4 bytes) |
| 453 | using multibyte character sequences. |
| 454 | \layout Subsection |
| 455 | |
| 456 | The NumericString type |
| 457 | \layout Standard |
| 458 | |
| 459 | This type represents the character string with the alphabet consisting of |
| 460 | numbers ( |
| 461 | \begin_inset Quotes sld |
| 462 | \end_inset |
| 463 | |
| 464 | 0 |
| 465 | \begin_inset Quotes srd |
| 466 | \end_inset |
| 467 | |
| 468 | to |
| 469 | \begin_inset Quotes sld |
| 470 | \end_inset |
| 471 | |
| 472 | 9 |
| 473 | \begin_inset Quotes srd |
| 474 | \end_inset |
| 475 | |
| 476 | ) and a space. |
| 477 | \layout Subsection |
| 478 | |
| 479 | The PrintableString type |
| 480 | \layout Standard |
| 481 | |
| 482 | The character string with the following alphabet: space, |
| 483 | \begin_inset Quotes sld |
| 484 | \end_inset |
| 485 | |
| 486 | |
| 487 | \series bold |
| 488 | ' |
| 489 | \series default |
| 490 | |
| 491 | \begin_inset Quotes srd |
| 492 | \end_inset |
| 493 | |
| 494 | (single quote), |
| 495 | \begin_inset Quotes sld |
| 496 | \end_inset |
| 497 | |
| 498 | |
| 499 | \series bold |
| 500 | ( |
| 501 | \series default |
| 502 | |
| 503 | \begin_inset Quotes sld |
| 504 | \end_inset |
| 505 | |
| 506 | , |
| 507 | \begin_inset Quotes sld |
| 508 | \end_inset |
| 509 | |
| 510 | |
| 511 | \series bold |
| 512 | ) |
| 513 | \series default |
| 514 | |
| 515 | \begin_inset Quotes srd |
| 516 | \end_inset |
| 517 | |
| 518 | , |
| 519 | \begin_inset Quotes sld |
| 520 | \end_inset |
| 521 | |
| 522 | |
| 523 | \series bold |
| 524 | + |
| 525 | \series default |
| 526 | |
| 527 | \begin_inset Quotes srd |
| 528 | \end_inset |
| 529 | |
| 530 | , |
| 531 | \begin_inset Quotes sld |
| 532 | \end_inset |
| 533 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 534 | |
| 535 | \series bold |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 536 | , |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 537 | \series default |
| 538 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 539 | \begin_inset Quotes srd |
| 540 | \end_inset |
| 541 | |
| 542 | (comma), |
| 543 | \begin_inset Quotes sld |
| 544 | \end_inset |
| 545 | |
| 546 | |
| 547 | \series bold |
| 548 | - |
| 549 | \series default |
| 550 | |
| 551 | \begin_inset Quotes srd |
| 552 | \end_inset |
| 553 | |
| 554 | , |
| 555 | \begin_inset Quotes sld |
| 556 | \end_inset |
| 557 | |
| 558 | |
| 559 | \series bold |
| 560 | . |
| 561 | \series default |
| 562 | |
| 563 | \begin_inset Quotes srd |
| 564 | \end_inset |
| 565 | |
| 566 | , |
| 567 | \begin_inset Quotes sld |
| 568 | \end_inset |
| 569 | |
| 570 | |
| 571 | \series bold |
| 572 | / |
| 573 | \series default |
| 574 | |
| 575 | \begin_inset Quotes srd |
| 576 | \end_inset |
| 577 | |
| 578 | , digits ( |
| 579 | \begin_inset Quotes sld |
| 580 | \end_inset |
| 581 | |
| 582 | 0 |
| 583 | \begin_inset Quotes srd |
| 584 | \end_inset |
| 585 | |
| 586 | to |
| 587 | \begin_inset Quotes sld |
| 588 | \end_inset |
| 589 | |
| 590 | 9 |
| 591 | \begin_inset Quotes srd |
| 592 | \end_inset |
| 593 | |
| 594 | ), |
| 595 | \begin_inset Quotes sld |
| 596 | \end_inset |
| 597 | |
| 598 | |
| 599 | \series bold |
| 600 | : |
| 601 | \series default |
| 602 | |
| 603 | \begin_inset Quotes srd |
| 604 | \end_inset |
| 605 | |
| 606 | , |
| 607 | \begin_inset Quotes sld |
| 608 | \end_inset |
| 609 | |
| 610 | |
| 611 | \series bold |
| 612 | = |
| 613 | \series default |
| 614 | |
| 615 | \begin_inset Quotes srd |
| 616 | \end_inset |
| 617 | |
| 618 | , |
| 619 | \begin_inset Quotes sld |
| 620 | \end_inset |
| 621 | |
| 622 | |
| 623 | \series bold |
| 624 | ? |
| 625 | \series default |
| 626 | |
| 627 | \begin_inset Quotes srd |
| 628 | \end_inset |
| 629 | |
| 630 | , upper-case and lower-case letters ( |
| 631 | \begin_inset Quotes sld |
| 632 | \end_inset |
| 633 | |
| 634 | A |
| 635 | \begin_inset Quotes srd |
| 636 | \end_inset |
| 637 | |
| 638 | to |
| 639 | \begin_inset Quotes sld |
| 640 | \end_inset |
| 641 | |
| 642 | Z |
| 643 | \begin_inset Quotes srd |
| 644 | \end_inset |
| 645 | |
| 646 | and |
| 647 | \begin_inset Quotes sld |
| 648 | \end_inset |
| 649 | |
| 650 | a |
| 651 | \begin_inset Quotes srd |
| 652 | \end_inset |
| 653 | |
| 654 | to |
| 655 | \begin_inset Quotes sld |
| 656 | \end_inset |
| 657 | |
| 658 | z |
| 659 | \begin_inset Quotes srd |
| 660 | \end_inset |
| 661 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 662 | ). |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 663 | \layout Subsection |
| 664 | |
| 665 | The VisibleString type |
| 666 | \layout Standard |
| 667 | |
| 668 | The character string with the alphabet which is more or less a subset of |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 669 | ASCII between the space and the |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 670 | \begin_inset Quotes sld |
| 671 | \end_inset |
| 672 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 673 | |
| 674 | \series bold |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 675 | ~ |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 676 | \series default |
| 677 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 678 | \begin_inset Quotes srd |
| 679 | \end_inset |
| 680 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 681 | symbol (tilde). |
| 682 | \layout Standard |
| 683 | |
| 684 | Alternatively, the alphabet may be described as the PrintableString alphabet |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 685 | presented earlier, plus the following characters: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 686 | \begin_inset Quotes sld |
| 687 | \end_inset |
| 688 | |
| 689 | |
| 690 | \series bold |
| 691 | ! |
| 692 | \series default |
| 693 | |
| 694 | \begin_inset Quotes srd |
| 695 | \end_inset |
| 696 | |
| 697 | , |
| 698 | \begin_inset Quotes sld |
| 699 | \end_inset |
| 700 | |
| 701 | |
| 702 | \series bold |
| 703 | |
| 704 | \begin_inset Quotes srd |
| 705 | \end_inset |
| 706 | |
| 707 | |
| 708 | \series default |
| 709 | |
| 710 | \begin_inset Quotes srd |
| 711 | \end_inset |
| 712 | |
| 713 | , |
| 714 | \begin_inset Quotes sld |
| 715 | \end_inset |
| 716 | |
| 717 | |
| 718 | \series bold |
| 719 | # |
| 720 | \series default |
| 721 | |
| 722 | \begin_inset Quotes srd |
| 723 | \end_inset |
| 724 | |
| 725 | , |
| 726 | \begin_inset Quotes sld |
| 727 | \end_inset |
| 728 | |
| 729 | |
| 730 | \series bold |
| 731 | $ |
| 732 | \series default |
| 733 | |
| 734 | \begin_inset Quotes srd |
| 735 | \end_inset |
| 736 | |
| 737 | , |
| 738 | \begin_inset Quotes sld |
| 739 | \end_inset |
| 740 | |
| 741 | |
| 742 | \series bold |
| 743 | % |
| 744 | \series default |
| 745 | |
| 746 | \begin_inset Quotes srd |
| 747 | \end_inset |
| 748 | |
| 749 | , |
| 750 | \begin_inset Quotes sld |
| 751 | \end_inset |
| 752 | |
| 753 | |
| 754 | \series bold |
| 755 | & |
| 756 | \series default |
| 757 | |
| 758 | \begin_inset Quotes srd |
| 759 | \end_inset |
| 760 | |
| 761 | , |
| 762 | \begin_inset Quotes sld |
| 763 | \end_inset |
| 764 | |
| 765 | |
| 766 | \series bold |
| 767 | * |
| 768 | \series default |
| 769 | |
| 770 | \begin_inset Quotes srd |
| 771 | \end_inset |
| 772 | |
| 773 | , |
| 774 | \begin_inset Quotes sld |
| 775 | \end_inset |
| 776 | |
| 777 | |
| 778 | \series bold |
| 779 | ; |
| 780 | \series default |
| 781 | |
| 782 | \begin_inset Quotes srd |
| 783 | \end_inset |
| 784 | |
| 785 | , |
| 786 | \begin_inset Quotes sld |
| 787 | \end_inset |
| 788 | |
| 789 | |
| 790 | \series bold |
| 791 | < |
| 792 | \series default |
| 793 | |
| 794 | \begin_inset Quotes srd |
| 795 | \end_inset |
| 796 | |
| 797 | , |
| 798 | \begin_inset Quotes sld |
| 799 | \end_inset |
| 800 | |
| 801 | |
| 802 | \series bold |
| 803 | > |
| 804 | \series default |
| 805 | |
| 806 | \begin_inset Quotes srd |
| 807 | \end_inset |
| 808 | |
| 809 | , |
| 810 | \begin_inset Quotes sld |
| 811 | \end_inset |
| 812 | |
| 813 | |
| 814 | \series bold |
| 815 | [ |
| 816 | \series default |
| 817 | |
| 818 | \begin_inset Quotes srd |
| 819 | \end_inset |
| 820 | |
| 821 | , |
| 822 | \begin_inset Quotes sld |
| 823 | \end_inset |
| 824 | |
| 825 | |
| 826 | \series bold |
| 827 | |
| 828 | \backslash |
| 829 | |
| 830 | \series default |
| 831 | |
| 832 | \begin_inset Quotes srd |
| 833 | \end_inset |
| 834 | |
| 835 | , |
| 836 | \begin_inset Quotes sld |
| 837 | \end_inset |
| 838 | |
| 839 | |
| 840 | \series bold |
| 841 | ] |
| 842 | \series default |
| 843 | |
| 844 | \begin_inset Quotes srd |
| 845 | \end_inset |
| 846 | |
| 847 | , |
| 848 | \begin_inset Quotes sld |
| 849 | \end_inset |
| 850 | |
| 851 | |
| 852 | \series bold |
| 853 | ^ |
| 854 | \series default |
| 855 | |
| 856 | \begin_inset Quotes srd |
| 857 | \end_inset |
| 858 | |
| 859 | , |
| 860 | \begin_inset Quotes sld |
| 861 | \end_inset |
| 862 | |
| 863 | |
| 864 | \series bold |
| 865 | _ |
| 866 | \series default |
| 867 | |
| 868 | \begin_inset Quotes srd |
| 869 | \end_inset |
| 870 | |
| 871 | , |
| 872 | \begin_inset Quotes sld |
| 873 | \end_inset |
| 874 | |
| 875 | |
| 876 | \series bold |
| 877 | ` |
| 878 | \series default |
| 879 | |
| 880 | \begin_inset Quotes srd |
| 881 | \end_inset |
| 882 | |
| 883 | (single left quote), |
| 884 | \begin_inset Quotes sld |
| 885 | \end_inset |
| 886 | |
| 887 | |
| 888 | \series bold |
| 889 | { |
| 890 | \series default |
| 891 | |
| 892 | \begin_inset Quotes srd |
| 893 | \end_inset |
| 894 | |
| 895 | , |
| 896 | \begin_inset Quotes sld |
| 897 | \end_inset |
| 898 | |
| 899 | |
| 900 | \series bold |
| 901 | | |
| 902 | \series default |
| 903 | |
| 904 | \begin_inset Quotes srd |
| 905 | \end_inset |
| 906 | |
| 907 | , |
| 908 | \begin_inset Quotes sld |
| 909 | \end_inset |
| 910 | |
| 911 | |
| 912 | \series bold |
| 913 | } |
| 914 | \series default |
| 915 | |
| 916 | \begin_inset Quotes srd |
| 917 | \end_inset |
| 918 | |
| 919 | , |
| 920 | \begin_inset Quotes sld |
| 921 | \end_inset |
| 922 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 923 | |
| 924 | \series bold |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 925 | ~ |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 926 | \series default |
| 927 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 928 | \begin_inset Quotes srd |
| 929 | \end_inset |
| 930 | |
| 931 | . |
| 932 | \layout Section |
| 933 | |
| 934 | ASN.1 Constructed Types |
| 935 | \layout Subsection |
| 936 | |
| 937 | The SEQUENCE type |
| 938 | \layout Standard |
| 939 | |
| 940 | This is an ordered collection of other simple or constructed types. |
| 941 | The SEQUENCE constructed type resembles the C |
| 942 | \begin_inset Quotes sld |
| 943 | \end_inset |
| 944 | |
| 945 | struct |
| 946 | \begin_inset Quotes srd |
| 947 | \end_inset |
| 948 | |
| 949 | statement. |
| 950 | \layout LyX-Code |
| 951 | |
| 952 | Address ::= SEQUENCE { |
| 953 | \layout LyX-Code |
| 954 | |
| 955 | -- The apartment number may be omitted |
| 956 | \layout LyX-Code |
| 957 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 958 | apartmentNumber NumericString OPTIONAL, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 959 | \layout LyX-Code |
| 960 | |
| 961 | streetName PrintableString, |
| 962 | \layout LyX-Code |
| 963 | |
| 964 | cityName PrintableString, |
| 965 | \layout LyX-Code |
| 966 | |
| 967 | stateName PrintableString, |
| 968 | \layout LyX-Code |
| 969 | |
| 970 | -- This one may be omitted too |
| 971 | \layout LyX-Code |
| 972 | |
| 973 | zipNo NumericString OPTIONAL |
| 974 | \layout LyX-Code |
| 975 | |
| 976 | } |
| 977 | \layout Subsection |
| 978 | |
| 979 | The SET type |
| 980 | \layout Standard |
| 981 | |
| 982 | This is a collection of other simple or constructed types. |
| 983 | Ordering is not important. |
| 984 | The data may arrive in the order which is different from the order of specifica |
| 985 | tion. |
| 986 | Data is encoded in the order not necessarily corresponding to the order |
| 987 | of specification. |
| 988 | \layout Subsection |
| 989 | |
| 990 | The CHOICE type |
| 991 | \layout Standard |
| 992 | |
| 993 | This type is just a choice between the subtypes specified in it. |
| 994 | The CHOICE type contains at most one of the subtypes specified, and it |
| 995 | is always implicitly known which choice is being decoded or encoded. |
| 996 | This one resembles the C |
| 997 | \begin_inset Quotes sld |
| 998 | \end_inset |
| 999 | |
| 1000 | union |
| 1001 | \begin_inset Quotes srd |
| 1002 | \end_inset |
| 1003 | |
| 1004 | statement. |
| 1005 | \layout Standard |
| 1006 | |
| 1007 | The following type defines a response code, which may be either an integer |
| 1008 | code or a boolean |
| 1009 | \begin_inset Quotes sld |
| 1010 | \end_inset |
| 1011 | |
| 1012 | true |
| 1013 | \begin_inset Quotes srd |
| 1014 | \end_inset |
| 1015 | |
| 1016 | / |
| 1017 | \begin_inset Quotes srd |
| 1018 | \end_inset |
| 1019 | |
| 1020 | false |
| 1021 | \begin_inset Quotes srd |
| 1022 | \end_inset |
| 1023 | |
| 1024 | code. |
| 1025 | \layout LyX-Code |
| 1026 | |
| 1027 | ResponseCode ::= CHOICE { |
| 1028 | \layout LyX-Code |
| 1029 | |
| 1030 | intCode INTEGER, |
| 1031 | \layout LyX-Code |
| 1032 | |
| 1033 | boolCode BOOLEAN |
| 1034 | \layout LyX-Code |
| 1035 | |
| 1036 | } |
| 1037 | \layout LyX-Code |
| 1038 | |
| 1039 | \layout Subsection |
| 1040 | |
| 1041 | The SEQUENCE OF type |
| 1042 | \layout Standard |
| 1043 | |
| 1044 | This one is the list (array) of simple or constructed types: |
| 1045 | \layout LyX-Code |
| 1046 | |
| 1047 | -- Example 1 |
| 1048 | \layout LyX-Code |
| 1049 | |
| 1050 | ManyIntegers ::= SEQUENCE OF INTEGER |
| 1051 | \layout LyX-Code |
| 1052 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1053 | |
| 1054 | \layout LyX-Code |
| 1055 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1056 | -- Example 2 |
| 1057 | \layout LyX-Code |
| 1058 | |
| 1059 | ManyRectangles ::= SEQUENCE OF Rectangle |
| 1060 | \layout LyX-Code |
| 1061 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1062 | |
| 1063 | \layout LyX-Code |
| 1064 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1065 | -- More complex example: |
| 1066 | \layout LyX-Code |
| 1067 | |
| 1068 | -- an array of structures defined in place. |
| 1069 | \layout LyX-Code |
| 1070 | |
| 1071 | ManyCircles ::= SEQUENCE OF SEQUENCE { |
| 1072 | \layout LyX-Code |
| 1073 | |
| 1074 | radius INTEGER |
| 1075 | \layout LyX-Code |
| 1076 | |
| 1077 | } |
| 1078 | \layout Subsection |
| 1079 | |
| 1080 | The SET OF type |
| 1081 | \layout Standard |
| 1082 | |
| 1083 | The SET OF type models the bag of structures. |
| 1084 | It resembles the SEQUENCE OF type, but the order is not important: i.e. |
| 1085 | the elements may arrive in the order which is not necessarily the same |
| 1086 | as the in-memory order on the remote machines. |
| 1087 | \layout LyX-Code |
| 1088 | |
| 1089 | -- A set of structures defined elsewhere |
| 1090 | \layout LyX-Code |
| 1091 | |
| 1092 | SetOfApples :: SET OF Apple |
| 1093 | \layout LyX-Code |
| 1094 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1095 | |
| 1096 | \layout LyX-Code |
| 1097 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1098 | -- Set of integers encoding the kind of a fruit |
| 1099 | \layout LyX-Code |
| 1100 | |
| 1101 | FruitBag ::= SET OF ENUMERATED { apple, orange } |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 1102 | \layout Part |
| 1103 | |
| 1104 | Using the ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1105 | \layout Chapter |
| 1106 | |
vlm | caba97b | 2004-08-07 05:00:07 +0000 | [diff] [blame] | 1107 | Introduction to the ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1108 | \layout Standard |
| 1109 | |
| 1110 | The purpose of the ASN.1 compiler, of which this document is part, is to |
| 1111 | convert the ASN.1 specifications to some other target language (currently, |
| 1112 | only C is supported |
| 1113 | \begin_inset Foot |
| 1114 | collapsed false |
| 1115 | |
| 1116 | \layout Standard |
| 1117 | |
| 1118 | C++ is |
| 1119 | \begin_inset Quotes sld |
| 1120 | \end_inset |
| 1121 | |
| 1122 | supported |
| 1123 | \begin_inset Quotes srd |
| 1124 | \end_inset |
| 1125 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1126 | too, as long as an class-based approach is not a definitive factor. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1127 | \end_inset |
| 1128 | |
| 1129 | ). |
| 1130 | The compiler reads the specification and emits a series of target language |
| 1131 | structures and surrounding maintenance code. |
| 1132 | For example, the C structure which may be created by compiler to represent |
| 1133 | the simple |
| 1134 | \emph on |
| 1135 | Rectangle |
| 1136 | \emph default |
| 1137 | specification defined earlier in this document, may look like this |
| 1138 | \begin_inset Foot |
| 1139 | collapsed false |
| 1140 | |
| 1141 | \layout Standard |
| 1142 | |
| 1143 | |
| 1144 | \emph on |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 1145 | -fnative-types |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1146 | \emph default |
| 1147 | compiler option is used to produce basic C |
| 1148 | \emph on |
| 1149 | int |
| 1150 | \emph default |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1151 | types instead of infinite width INTEGER_t structures. |
| 1152 | See Table |
| 1153 | \begin_inset LatexCommand \vref{cap:asn1c-cmdopts} |
| 1154 | |
| 1155 | \end_inset |
| 1156 | |
| 1157 | . |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1158 | \end_inset |
| 1159 | |
| 1160 | : |
| 1161 | \layout LyX-Code |
| 1162 | |
| 1163 | typedef struct Rectangle_s { |
| 1164 | \layout LyX-Code |
| 1165 | |
| 1166 | int height; |
| 1167 | \layout LyX-Code |
| 1168 | |
| 1169 | int width; |
| 1170 | \layout LyX-Code |
| 1171 | |
| 1172 | } Rectangle_t; |
| 1173 | \layout Standard |
| 1174 | |
| 1175 | This would not be of much value for such a simple specification, so the |
| 1176 | compiler goes further and actually produces the code which fills in this |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1177 | structure by parsing the opaque binary |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1178 | \begin_inset Foot |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1179 | collapsed true |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1180 | |
| 1181 | \layout Standard |
| 1182 | |
| 1183 | BER, CER and DER encodings are binary. |
| 1184 | However, the XER encoding is text (XML) based. |
| 1185 | \end_inset |
| 1186 | |
| 1187 | data provided in some buffer. |
| 1188 | It also produces the code that takes this structure as an argument and |
| 1189 | performs structure serialization by emitting a series of bytes. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1190 | \layout Chapter |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1191 | |
| 1192 | Quick start |
| 1193 | \layout Standard |
| 1194 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1195 | After building and installing the compiler, the |
| 1196 | \emph on |
| 1197 | asn1c |
| 1198 | \begin_inset Foot |
| 1199 | collapsed false |
| 1200 | |
| 1201 | \layout Standard |
| 1202 | |
| 1203 | The 1 symbol in asn |
| 1204 | \series bold |
| 1205 | 1 |
| 1206 | \series default |
| 1207 | c is a digit, not an |
| 1208 | \begin_inset Quotes sld |
| 1209 | \end_inset |
| 1210 | |
| 1211 | ell |
| 1212 | \begin_inset Quotes srd |
| 1213 | \end_inset |
| 1214 | |
| 1215 | letter. |
| 1216 | \end_inset |
| 1217 | |
| 1218 | |
| 1219 | \emph default |
| 1220 | command may be used to compile the ASN.1 specification |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1221 | \begin_inset Foot |
| 1222 | collapsed false |
| 1223 | |
| 1224 | \layout Standard |
| 1225 | |
| 1226 | This is probably |
| 1227 | \series bold |
| 1228 | not |
| 1229 | \series default |
| 1230 | what you want to try out right now -- read through the rest of this chapter |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1231 | to find out about |
| 1232 | \series bold |
| 1233 | -P |
| 1234 | \series default |
| 1235 | and |
| 1236 | \series bold |
| 1237 | -R |
| 1238 | \series default |
| 1239 | options. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1240 | \end_inset |
| 1241 | |
| 1242 | : |
| 1243 | \layout LyX-Code |
| 1244 | |
| 1245 | asn1c |
| 1246 | \emph on |
| 1247 | <spec.asn1> |
| 1248 | \layout Standard |
| 1249 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1250 | If several specifications contain interdependencies, all of the files must |
| 1251 | be specified altogether: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1252 | \layout LyX-Code |
| 1253 | |
| 1254 | asn1c |
| 1255 | \emph on |
| 1256 | <spec1.asn1> <spec2.asn1> ... |
| 1257 | \layout Standard |
| 1258 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1259 | The compiler |
| 1260 | \series bold |
| 1261 | -E |
| 1262 | \series default |
| 1263 | and |
| 1264 | \series bold |
| 1265 | -EF |
| 1266 | \series default |
| 1267 | options are used for testing the parser and the semantic fixer, respectively. |
| 1268 | These options will instruct the compiler to dump out the parsed (and fixed, |
| 1269 | if |
| 1270 | \series bold |
| 1271 | -F |
| 1272 | \series default |
| 1273 | is involved) ASN.1 specification as it was "understood" by the compiler. |
| 1274 | It might be useful to check whether a particular syntactic construction |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1275 | is properly supported by the compiler. |
| 1276 | \layout LyX-Code |
| 1277 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1278 | asn1c |
| 1279 | \series bold |
| 1280 | -EF |
| 1281 | \series default |
| 1282 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1283 | \emph on |
| 1284 | <spec-to-test.asn1> |
| 1285 | \layout Standard |
| 1286 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1287 | The |
| 1288 | \series bold |
| 1289 | -P |
| 1290 | \series default |
| 1291 | option is used to dump the compiled output on the screen instead of creating |
| 1292 | a bunch of .c and .h files on disk in the current directory. |
| 1293 | You would probably want to start with |
| 1294 | \series bold |
| 1295 | -P |
| 1296 | \series default |
| 1297 | option instead of creating a mess in your current directory. |
| 1298 | Another option, |
| 1299 | \series bold |
| 1300 | -R |
| 1301 | \series default |
| 1302 | , asks compiler to only generate the files which need to be generated, and |
| 1303 | supress linking in the numerous support files. |
| 1304 | \layout Standard |
| 1305 | |
| 1306 | Print the compiled output instead of creating multiple source files: |
| 1307 | \layout LyX-Code |
| 1308 | |
| 1309 | asn1c |
| 1310 | \series bold |
| 1311 | -P |
| 1312 | \series default |
| 1313 | |
| 1314 | \emph on |
| 1315 | <spec-to-compile-and-print.asn1> |
| 1316 | \layout LyX-Code |
| 1317 | |
| 1318 | \layout Chapter |
| 1319 | |
| 1320 | Using the ASN.1 Compiler |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1321 | \layout Section |
| 1322 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1323 | Command-line options |
| 1324 | \layout Standard |
| 1325 | |
| 1326 | The Table |
| 1327 | \begin_inset LatexCommand \vref{cap:asn1c-cmdopts} |
| 1328 | |
| 1329 | \end_inset |
| 1330 | |
| 1331 | summarizes various options affecting the compiler's behavior. |
| 1332 | \layout Standard |
| 1333 | |
| 1334 | |
| 1335 | \begin_inset Float table |
| 1336 | wide false |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 1337 | collapsed false |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1338 | |
| 1339 | \layout Standard |
| 1340 | |
| 1341 | |
| 1342 | \begin_inset Tabular |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1343 | <lyxtabular version="3" rows="22" columns="2"> |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1344 | <features islongtable="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1345 | <column alignment="left" valignment="top" leftline="true" width="0"> |
| 1346 | <column alignment="block" valignment="top" leftline="true" rightline="true" width="3in"> |
| 1347 | <row topline="true" bottomline="true"> |
| 1348 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1349 | \begin_inset Text |
| 1350 | |
| 1351 | \layout Standard |
| 1352 | |
| 1353 | |
| 1354 | \series bold |
| 1355 | Overall Options |
| 1356 | \end_inset |
| 1357 | </cell> |
| 1358 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1359 | \begin_inset Text |
| 1360 | |
| 1361 | \layout Standard |
| 1362 | |
| 1363 | |
| 1364 | \series bold |
| 1365 | Description |
| 1366 | \end_inset |
| 1367 | </cell> |
| 1368 | </row> |
| 1369 | <row topline="true"> |
| 1370 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1371 | \begin_inset Text |
| 1372 | |
| 1373 | \layout Standard |
| 1374 | |
| 1375 | -E |
| 1376 | \end_inset |
| 1377 | </cell> |
| 1378 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1379 | \begin_inset Text |
| 1380 | |
| 1381 | \layout Standard |
| 1382 | |
| 1383 | |
| 1384 | \size small |
| 1385 | Stop after the parsing stage and print the reconstructed ASN.1 specification |
| 1386 | code to the standard output. |
| 1387 | \end_inset |
| 1388 | </cell> |
| 1389 | </row> |
| 1390 | <row topline="true"> |
| 1391 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1392 | \begin_inset Text |
| 1393 | |
| 1394 | \layout Standard |
| 1395 | |
| 1396 | -F |
| 1397 | \end_inset |
| 1398 | </cell> |
| 1399 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1400 | \begin_inset Text |
| 1401 | |
| 1402 | \layout Standard |
| 1403 | |
| 1404 | |
| 1405 | \size small |
| 1406 | Used together with -E, instructs the compiler to stop after the ASN.1 syntax |
| 1407 | tree fixing stage and dump the reconstructed ASN.1 specification to the |
| 1408 | standard output. |
| 1409 | \end_inset |
| 1410 | </cell> |
| 1411 | </row> |
| 1412 | <row topline="true"> |
| 1413 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1414 | \begin_inset Text |
| 1415 | |
| 1416 | \layout Standard |
| 1417 | |
| 1418 | -P |
| 1419 | \end_inset |
| 1420 | </cell> |
| 1421 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1422 | \begin_inset Text |
| 1423 | |
| 1424 | \layout Standard |
| 1425 | |
| 1426 | |
| 1427 | \size small |
| 1428 | Dump the compiled output to the standard output instead of cre- ating the |
| 1429 | target language files on disk. |
| 1430 | \end_inset |
| 1431 | </cell> |
| 1432 | </row> |
| 1433 | <row topline="true"> |
| 1434 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1435 | \begin_inset Text |
| 1436 | |
| 1437 | \layout Standard |
| 1438 | |
| 1439 | -R |
| 1440 | \end_inset |
| 1441 | </cell> |
| 1442 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1443 | \begin_inset Text |
| 1444 | |
| 1445 | \layout Standard |
| 1446 | |
| 1447 | |
| 1448 | \size small |
| 1449 | Restrict the compiler to generate only the ASN.1 tables, omit- ting the usual |
| 1450 | support code. |
| 1451 | \end_inset |
| 1452 | </cell> |
| 1453 | </row> |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1454 | <row topline="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1455 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1456 | \begin_inset Text |
| 1457 | |
| 1458 | \layout Standard |
| 1459 | |
| 1460 | -S |
| 1461 | \emph on |
| 1462 | <directory> |
| 1463 | \end_inset |
| 1464 | </cell> |
| 1465 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1466 | \begin_inset Text |
| 1467 | |
| 1468 | \layout Standard |
| 1469 | |
| 1470 | |
| 1471 | \size small |
| 1472 | Use the specified directory with ASN.1 skeleton files. |
| 1473 | \end_inset |
| 1474 | </cell> |
| 1475 | </row> |
vlm | 60e7ef0 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1476 | <row topline="true" bottomline="true"> |
| 1477 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1478 | \begin_inset Text |
| 1479 | |
| 1480 | \layout Standard |
| 1481 | |
| 1482 | -X |
| 1483 | \end_inset |
| 1484 | </cell> |
| 1485 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1486 | \begin_inset Text |
| 1487 | |
| 1488 | \layout Standard |
| 1489 | |
| 1490 | Generate the XML DTD for the specified ASN.1 modules. |
| 1491 | \end_inset |
| 1492 | </cell> |
| 1493 | </row> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1494 | <row topline="true"> |
| 1495 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1496 | \begin_inset Text |
| 1497 | |
| 1498 | \layout Standard |
| 1499 | |
| 1500 | |
| 1501 | \series bold |
| 1502 | Warning Options |
| 1503 | \end_inset |
| 1504 | </cell> |
| 1505 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1506 | \begin_inset Text |
| 1507 | |
| 1508 | \layout Standard |
| 1509 | |
| 1510 | |
| 1511 | \series bold |
| 1512 | Description |
| 1513 | \end_inset |
| 1514 | </cell> |
| 1515 | </row> |
| 1516 | <row topline="true"> |
| 1517 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1518 | \begin_inset Text |
| 1519 | |
| 1520 | \layout Standard |
| 1521 | |
| 1522 | -Werror |
| 1523 | \end_inset |
| 1524 | </cell> |
| 1525 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1526 | \begin_inset Text |
| 1527 | |
| 1528 | \layout Standard |
| 1529 | |
| 1530 | |
| 1531 | \size small |
| 1532 | Treat warnings as errors; abort if any warning is produced. |
| 1533 | \end_inset |
| 1534 | </cell> |
| 1535 | </row> |
| 1536 | <row topline="true"> |
| 1537 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1538 | \begin_inset Text |
| 1539 | |
| 1540 | \layout Standard |
| 1541 | |
| 1542 | -Wdebug-lexer |
| 1543 | \end_inset |
| 1544 | </cell> |
| 1545 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1546 | \begin_inset Text |
| 1547 | |
| 1548 | \layout Standard |
| 1549 | |
| 1550 | |
| 1551 | \size small |
| 1552 | Enable lexer debugging during the ASN.1 parsing stage. |
| 1553 | \end_inset |
| 1554 | </cell> |
| 1555 | </row> |
| 1556 | <row topline="true"> |
| 1557 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1558 | \begin_inset Text |
| 1559 | |
| 1560 | \layout Standard |
| 1561 | |
| 1562 | -Wdebug-fixer |
| 1563 | \end_inset |
| 1564 | </cell> |
| 1565 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1566 | \begin_inset Text |
| 1567 | |
| 1568 | \layout Standard |
| 1569 | |
| 1570 | |
| 1571 | \size small |
| 1572 | Enable ASN.1 syntax tree fixer debugging during the fixing stage. |
| 1573 | \end_inset |
| 1574 | </cell> |
| 1575 | </row> |
| 1576 | <row topline="true" bottomline="true"> |
| 1577 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1578 | \begin_inset Text |
| 1579 | |
| 1580 | \layout Standard |
| 1581 | |
| 1582 | -Wdebug-compiler |
| 1583 | \end_inset |
| 1584 | </cell> |
| 1585 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1586 | \begin_inset Text |
| 1587 | |
| 1588 | \layout Standard |
| 1589 | |
| 1590 | |
| 1591 | \size small |
| 1592 | Enable debugging during the actual compile time. |
| 1593 | \end_inset |
| 1594 | </cell> |
| 1595 | </row> |
| 1596 | <row topline="true"> |
| 1597 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1598 | \begin_inset Text |
| 1599 | |
| 1600 | \layout Standard |
| 1601 | |
| 1602 | |
| 1603 | \series bold |
| 1604 | Language Options |
| 1605 | \end_inset |
| 1606 | </cell> |
| 1607 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1608 | \begin_inset Text |
| 1609 | |
| 1610 | \layout Standard |
| 1611 | |
| 1612 | |
| 1613 | \series bold |
| 1614 | Description |
| 1615 | \end_inset |
| 1616 | </cell> |
| 1617 | </row> |
| 1618 | <row topline="true"> |
| 1619 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1620 | \begin_inset Text |
| 1621 | |
| 1622 | \layout Standard |
| 1623 | |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 1624 | -fall-defs-global |
| 1625 | \end_inset |
| 1626 | </cell> |
| 1627 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1628 | \begin_inset Text |
| 1629 | |
| 1630 | \layout Standard |
| 1631 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1632 | Normally the compiler hides the definitions (asn_DEF_xxx) of the inner structure |
| 1633 | elements (members of SEQUENCE, SET and other types). |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 1634 | This option makes all such definitions global. |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1635 | Enabling this option may pollute the namespace by making lots of asn_DEF_xxx |
vlm | 12c8f69 | 2004-09-06 08:07:29 +0000 | [diff] [blame] | 1636 | structures globally visible, but will allow you to manipulate (encode and |
| 1637 | decode) the individual members of any complex ASN.1 structure. |
| 1638 | \end_inset |
| 1639 | </cell> |
| 1640 | </row> |
| 1641 | <row topline="true"> |
| 1642 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1643 | \begin_inset Text |
| 1644 | |
| 1645 | \layout Standard |
| 1646 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1647 | -fbless-SIZE |
| 1648 | \end_inset |
| 1649 | </cell> |
| 1650 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1651 | \begin_inset Text |
| 1652 | |
| 1653 | \layout Standard |
| 1654 | |
| 1655 | |
| 1656 | \size small |
| 1657 | Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which |
| 1658 | this constraint is normally prohibited by the standard. |
| 1659 | This is a violation of an ASN.1 standard and compiler may fail to produce |
| 1660 | the meaningful code. |
| 1661 | \end_inset |
| 1662 | </cell> |
| 1663 | </row> |
| 1664 | <row topline="true"> |
| 1665 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1666 | \begin_inset Text |
| 1667 | |
| 1668 | \layout Standard |
| 1669 | |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 1670 | -fnative-types |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1671 | \end_inset |
| 1672 | </cell> |
| 1673 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1674 | \begin_inset Text |
| 1675 | |
| 1676 | \layout Standard |
| 1677 | |
| 1678 | |
| 1679 | \size small |
vlm | 03af0f0 | 2004-09-14 12:48:17 +0000 | [diff] [blame] | 1680 | Use the native machine's data types (int, double) whenever possible, instead |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1681 | of the compound INTEGER_t, ENUMERATED_t and REAL_t types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1682 | |
| 1683 | \end_inset |
| 1684 | </cell> |
| 1685 | </row> |
| 1686 | <row topline="true"> |
| 1687 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1688 | \begin_inset Text |
| 1689 | |
| 1690 | \layout Standard |
| 1691 | |
vlm | bfc49bd | 2004-09-26 13:13:13 +0000 | [diff] [blame] | 1692 | -fno-constraints |
| 1693 | \end_inset |
| 1694 | </cell> |
| 1695 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1696 | \begin_inset Text |
| 1697 | |
| 1698 | \layout Standard |
| 1699 | |
| 1700 | Do not generate ASN.1 subtype constraint checking code. |
| 1701 | This may make a shorter executable. |
| 1702 | \end_inset |
| 1703 | </cell> |
| 1704 | </row> |
| 1705 | <row topline="true"> |
| 1706 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1707 | \begin_inset Text |
| 1708 | |
| 1709 | \layout Standard |
| 1710 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1711 | -funnamed-unions |
| 1712 | \end_inset |
| 1713 | </cell> |
| 1714 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1715 | \begin_inset Text |
| 1716 | |
| 1717 | \layout Standard |
| 1718 | |
| 1719 | |
| 1720 | \size small |
| 1721 | Enable unnamed unions in the definitions of target language's structures. |
| 1722 | \end_inset |
| 1723 | </cell> |
| 1724 | </row> |
| 1725 | <row topline="true" bottomline="true"> |
| 1726 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1727 | \begin_inset Text |
| 1728 | |
| 1729 | \layout Standard |
| 1730 | |
| 1731 | -ftypes88 |
| 1732 | \end_inset |
| 1733 | </cell> |
| 1734 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1735 | \begin_inset Text |
| 1736 | |
| 1737 | \layout Standard |
| 1738 | |
| 1739 | |
| 1740 | \size small |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1741 | Pretend to support only ASN.1:1988 embedded types. |
| 1742 | Certain reserved words, such as UniversalString and BMPString, become ordinary |
| 1743 | type references and may be redefined by the specification. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1744 | \end_inset |
| 1745 | </cell> |
| 1746 | </row> |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1747 | <row topline="true" newpage="true"> |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1748 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1749 | \begin_inset Text |
| 1750 | |
| 1751 | \layout Standard |
| 1752 | |
| 1753 | |
| 1754 | \series bold |
| 1755 | Output Options |
| 1756 | \end_inset |
| 1757 | </cell> |
| 1758 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1759 | \begin_inset Text |
| 1760 | |
| 1761 | \layout Standard |
| 1762 | |
| 1763 | |
| 1764 | \series bold |
| 1765 | Description |
| 1766 | \end_inset |
| 1767 | </cell> |
| 1768 | </row> |
| 1769 | <row topline="true"> |
| 1770 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1771 | \begin_inset Text |
| 1772 | |
| 1773 | \layout Standard |
| 1774 | |
| 1775 | -print-constraints |
| 1776 | \end_inset |
| 1777 | </cell> |
| 1778 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1779 | \begin_inset Text |
| 1780 | |
| 1781 | \layout Standard |
| 1782 | |
| 1783 | |
| 1784 | \size small |
| 1785 | When -EF are also specified, this option forces the compiler to explain |
| 1786 | its internal understanding of subtype constraints. |
| 1787 | \end_inset |
| 1788 | </cell> |
| 1789 | </row> |
| 1790 | <row topline="true" bottomline="true"> |
| 1791 | <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> |
| 1792 | \begin_inset Text |
| 1793 | |
| 1794 | \layout Standard |
| 1795 | |
| 1796 | -print-lines |
| 1797 | \end_inset |
| 1798 | </cell> |
| 1799 | <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> |
| 1800 | \begin_inset Text |
| 1801 | |
| 1802 | \layout Standard |
| 1803 | |
| 1804 | |
| 1805 | \size small |
| 1806 | Generate "-- #line" comments in -E output. |
| 1807 | \end_inset |
| 1808 | </cell> |
| 1809 | </row> |
| 1810 | </lyxtabular> |
| 1811 | |
| 1812 | \end_inset |
| 1813 | |
| 1814 | |
| 1815 | \layout Caption |
| 1816 | |
| 1817 | |
| 1818 | \begin_inset LatexCommand \label{cap:asn1c-cmdopts} |
| 1819 | |
| 1820 | \end_inset |
| 1821 | |
| 1822 | The list of asn1c command line options |
| 1823 | \end_inset |
| 1824 | |
| 1825 | |
| 1826 | \layout Section |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1827 | |
| 1828 | Recognizing compiler output |
| 1829 | \layout Standard |
| 1830 | |
| 1831 | After compiling, the following entities will be created in your current |
| 1832 | directory: |
| 1833 | \layout Itemize |
| 1834 | |
| 1835 | A set of .c and .h files, generally a single pair for each type defined in |
| 1836 | the ASN.1 specifications. |
| 1837 | These files will be named similarly to the ASN.1 types ( |
| 1838 | \emph on |
| 1839 | Rectangle.c |
| 1840 | \emph default |
| 1841 | and |
| 1842 | \emph on |
| 1843 | Rectangle.h |
| 1844 | \emph default |
| 1845 | for the specification defined in the beginning of this document). |
| 1846 | \layout Itemize |
| 1847 | |
| 1848 | A set of helper .c and .h files which contain generic encoders, decoders and |
| 1849 | other useful routines. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1850 | There will be quite a few of them, some of them even are not always necessary, |
| 1851 | but the overall amount of code after compiling will be rather small anyway. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1852 | \layout Standard |
| 1853 | |
| 1854 | It is your responsibility to create .c file with the |
| 1855 | \emph on |
| 1856 | int main() |
| 1857 | \emph default |
| 1858 | routine and the Makefile (if needed). |
| 1859 | Compiler helps you with the latter by creating the Makefile.am.sample, containing |
| 1860 | the skeleton definition for the automake, should you want to use autotools. |
| 1861 | \layout Standard |
| 1862 | |
| 1863 | In other words, after compiling the Rectangle module, you have the following |
| 1864 | set of files: { Makefile.am.sample, Rectangle.c, Rectangle.h, |
| 1865 | \series bold |
| 1866 | \SpecialChar \ldots{} |
| 1867 | |
| 1868 | \series default |
| 1869 | }, where |
| 1870 | \series bold |
| 1871 | |
| 1872 | \begin_inset Quotes sld |
| 1873 | \end_inset |
| 1874 | |
| 1875 | \SpecialChar \ldots{} |
| 1876 | |
| 1877 | \begin_inset Quotes srd |
| 1878 | \end_inset |
| 1879 | |
| 1880 | |
| 1881 | \series default |
| 1882 | stands for the set of additional |
| 1883 | \begin_inset Quotes sld |
| 1884 | \end_inset |
| 1885 | |
| 1886 | helper |
| 1887 | \begin_inset Quotes srd |
| 1888 | \end_inset |
| 1889 | |
| 1890 | files created by the compiler. |
| 1891 | If you add the simple file with the |
| 1892 | \emph on |
| 1893 | int main() |
| 1894 | \emph default |
| 1895 | routine, it would even be possible to compile everything with the single |
| 1896 | instruction: |
| 1897 | \layout LyX-Code |
| 1898 | |
| 1899 | cc -o rectangle *.c # It could be |
| 1900 | \emph on |
| 1901 | that |
| 1902 | \emph default |
| 1903 | simple |
| 1904 | \begin_inset Foot |
| 1905 | collapsed false |
| 1906 | |
| 1907 | \layout Standard |
| 1908 | |
| 1909 | Provided that you've also created a .c file with the |
| 1910 | \emph on |
| 1911 | int main() |
| 1912 | \emph default |
| 1913 | routine. |
| 1914 | \end_inset |
| 1915 | |
| 1916 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1917 | \layout Section |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1918 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 1919 | Invoking the ASN.1 helper code from an application |
| 1920 | \begin_inset OptArg |
| 1921 | collapsed true |
| 1922 | |
| 1923 | \layout Standard |
| 1924 | |
| 1925 | Invoking the helper code |
| 1926 | \end_inset |
| 1927 | |
| 1928 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1929 | \layout Standard |
| 1930 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1931 | First of all, you should to include one or more header files into your applicati |
| 1932 | on. |
| 1933 | For our Rectangle module, including the Rectangle.h file is enough: |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1934 | \layout LyX-Code |
| 1935 | |
| 1936 | #include <Rectangle.h> |
| 1937 | \layout Standard |
| 1938 | |
| 1939 | The header files defines the C structure corresponding to the ASN.1 definition |
| 1940 | of a rectangle and the declaration of the ASN.1 type descriptor, which is |
| 1941 | used as an argument to most of the functions provided by the ASN.1 module. |
| 1942 | For example, here is the code which frees the Rectangle_t structure: |
| 1943 | \layout LyX-Code |
| 1944 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 1945 | Rectangle_t *rect = ...; |
| 1946 | \layout LyX-Code |
| 1947 | |
| 1948 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1949 | \layout LyX-Code |
| 1950 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1951 | asn_DEF_Rectangle->free_struct(&asn_DEF_Rectangle, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1952 | \layout LyX-Code |
| 1953 | |
| 1954 | rect, 0); |
| 1955 | \layout Standard |
| 1956 | |
| 1957 | This code defines a |
| 1958 | \emph on |
| 1959 | rect |
| 1960 | \emph default |
| 1961 | pointer which points to the Rectangle_t structure which needs to be freed. |
| 1962 | The second line invokes the generic free_struct routine created specifically |
| 1963 | for this Rectangle_t structure. |
| 1964 | The |
| 1965 | \emph on |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 1966 | asn_DEF_Rectangle |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1967 | \emph default |
| 1968 | is the type descriptor, which holds a collection of generic routines to |
| 1969 | deal with the Rectangle_t structure. |
| 1970 | \layout Standard |
| 1971 | |
| 1972 | There are several generic functions available: |
| 1973 | \layout Description |
| 1974 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 1975 | ber_decoder This is the generic |
| 1976 | \emph on |
| 1977 | restartable |
| 1978 | \begin_inset Foot |
| 1979 | collapsed false |
| 1980 | |
| 1981 | \layout Standard |
| 1982 | |
| 1983 | Restartable means that if the decoder encounters the end of the buffer, |
| 1984 | it will fail, but may later be invoked again with the rest of the buffer |
| 1985 | to continue decoding. |
| 1986 | \end_inset |
| 1987 | |
| 1988 | |
| 1989 | \emph default |
| 1990 | BER decoder (Basic Encoding Rules). |
| 1991 | This decoder would create and/or fill the target structure for you. |
| 1992 | Please refer to Section |
| 1993 | \begin_inset LatexCommand \ref{sub:Decoding-BER} |
| 1994 | |
| 1995 | \end_inset |
| 1996 | |
| 1997 | . |
| 1998 | \layout Description |
| 1999 | |
| 2000 | der_encoder This is the generic DER encoder (Distinguished Encoding Rules). |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2001 | This encoder will take the target structure and encode it into a series |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2002 | of bytes. |
| 2003 | Please refer to Section |
| 2004 | \begin_inset LatexCommand \ref{sub:Encoding-DER} |
| 2005 | |
| 2006 | \end_inset |
| 2007 | |
| 2008 | . |
| 2009 | \layout Description |
| 2010 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2011 | xer_encoder This is the generic XER encoder (XML Encoding Rules). |
| 2012 | This encoder will take the target structure and represent it as an XML |
| 2013 | (text) document. |
| 2014 | Please refer to Section |
| 2015 | \begin_inset LatexCommand \ref{sub:Encoding-XER} |
| 2016 | |
| 2017 | \end_inset |
| 2018 | |
| 2019 | . |
| 2020 | \layout Description |
| 2021 | |
| 2022 | check_constraints Check that the contents of the target structure are semantical |
| 2023 | ly valid and constrained to appropriate implicit or explicit subtype constraints. |
| 2024 | Please refer to Section |
| 2025 | \begin_inset LatexCommand \vref{sub:Validating-the-target} |
| 2026 | |
| 2027 | \end_inset |
| 2028 | |
| 2029 | . |
| 2030 | \layout Description |
| 2031 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2032 | print_struct This function convert the contents of the passed target structure |
| 2033 | into human readable form. |
| 2034 | This form is not formal and cannot be converted back into the structure, |
| 2035 | but it may turn out to be useful for debugging or quick-n-dirty printing. |
| 2036 | Please refer to Section |
| 2037 | \begin_inset LatexCommand \ref{sub:Printing-the-target} |
| 2038 | |
| 2039 | \end_inset |
| 2040 | |
| 2041 | . |
| 2042 | \layout Description |
| 2043 | |
| 2044 | free_struct This is a generic disposal which frees the target structure. |
| 2045 | Please refer to Section |
| 2046 | \begin_inset LatexCommand \ref{sub:Freeing-the-target} |
| 2047 | |
| 2048 | \end_inset |
| 2049 | |
| 2050 | . |
| 2051 | \layout Standard |
| 2052 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2053 | check_constraints Check that the contents of the target structure are semantical |
| 2054 | ly valid and constrained to appropriate implicit or explicit subtype constraints. |
| 2055 | Please refer to Section |
| 2056 | \begin_inset LatexCommand \vref{sub:Validating-the-target} |
| 2057 | |
| 2058 | \end_inset |
| 2059 | |
| 2060 | . |
| 2061 | \layout Standard |
| 2062 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2063 | Each of the above function takes the type descriptor ( |
| 2064 | \emph on |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2065 | asn_DEF_\SpecialChar \ldots{} |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2066 | |
| 2067 | \emph default |
| 2068 | ) and the target structure ( |
| 2069 | \emph on |
| 2070 | rect |
| 2071 | \emph default |
| 2072 | , in the above example). |
| 2073 | The target structure is typically created by the generic BER decoder or |
| 2074 | by the application itself. |
| 2075 | \layout Standard |
| 2076 | |
| 2077 | Here is how the buffer can be deserialized into the structure: |
| 2078 | \layout LyX-Code |
| 2079 | |
| 2080 | Rectangle_t * |
| 2081 | \layout LyX-Code |
| 2082 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2083 | simple_deserializer(const void *buffer, size_t buf_size) { |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2084 | \layout LyX-Code |
| 2085 | |
| 2086 | Rectangle_t *rect = 0; /* Note this 0! */ |
| 2087 | \layout LyX-Code |
| 2088 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 2089 | asn_dec_rval_t rval; |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2090 | \layout LyX-Code |
| 2091 | |
| 2092 | |
| 2093 | \layout LyX-Code |
| 2094 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2095 | rval = asn_DEF_Rectangle->ber_decoder(0, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2096 | \layout LyX-Code |
| 2097 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2098 | &asn_DEF_Rectangle, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2099 | \layout LyX-Code |
| 2100 | |
| 2101 | (void **)&rect, |
| 2102 | \layout LyX-Code |
| 2103 | |
| 2104 | buffer, buf_size, |
| 2105 | \layout LyX-Code |
| 2106 | |
| 2107 | 0); |
| 2108 | \layout LyX-Code |
| 2109 | |
| 2110 | |
| 2111 | \layout LyX-Code |
| 2112 | |
| 2113 | if(rval |
| 2114 | \series bold |
| 2115 | .code |
| 2116 | \series default |
| 2117 | == RC_OK) { |
| 2118 | \layout LyX-Code |
| 2119 | |
| 2120 | return rect; /* Decoding succeeded */ |
| 2121 | \layout LyX-Code |
| 2122 | |
| 2123 | } else { |
| 2124 | \layout LyX-Code |
| 2125 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2126 | /* Free partially decoded rect */ |
| 2127 | \layout LyX-Code |
| 2128 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2129 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2130 | \layout LyX-Code |
| 2131 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2132 | &asn_DEF_Rectangle, rect, 0); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2133 | \layout LyX-Code |
| 2134 | |
| 2135 | return 0; |
| 2136 | \layout LyX-Code |
| 2137 | |
| 2138 | } |
| 2139 | \layout LyX-Code |
| 2140 | |
| 2141 | } |
| 2142 | \layout Standard |
| 2143 | |
| 2144 | The code above defines a function, |
| 2145 | \emph on |
| 2146 | simple_deserializer |
| 2147 | \emph default |
| 2148 | , which takes a buffer and its length and expected to return a pointer to |
| 2149 | the Rectangle_t structure. |
| 2150 | Inside, it tries to convert the bytes passed into the target structure |
| 2151 | (rect) using the generic BER decoder and returns the rect pointer afterwards. |
| 2152 | If the structure cannot be deserialized, it frees the memory which might |
| 2153 | be left allocated by the unfinished |
| 2154 | \emph on |
| 2155 | ber_decoder |
| 2156 | \emph default |
| 2157 | routine and returns NULL. |
| 2158 | |
| 2159 | \series bold |
| 2160 | This freeing is necessary |
| 2161 | \series default |
| 2162 | because the ber_decoder is a restartable procedure, and may fail just because |
| 2163 | there is more data needs to be provided before decoding could be finalized. |
| 2164 | The code above obviously does not take into account the way the |
| 2165 | \emph on |
| 2166 | ber_decoder |
| 2167 | \emph default |
| 2168 | failed, so the freeing is necessary because the part of the buffer may |
| 2169 | already be decoded into the structure by the time something goes wrong. |
| 2170 | \layout Standard |
| 2171 | |
| 2172 | Restartable decoding is a little bit trickier: you need to provide the old |
| 2173 | target structure pointer (which might be already half-decoded) and react |
| 2174 | on RC_WMORE return code. |
| 2175 | This will be explained later in Section |
| 2176 | \begin_inset LatexCommand \vref{sub:Decoding-BER} |
| 2177 | |
| 2178 | \end_inset |
| 2179 | |
| 2180 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2181 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2182 | |
| 2183 | |
| 2184 | \begin_inset LatexCommand \label{sub:Decoding-BER} |
| 2185 | |
| 2186 | \end_inset |
| 2187 | |
| 2188 | Decoding BER |
| 2189 | \layout Standard |
| 2190 | |
| 2191 | The Basic Encoding Rules describe the basic way how the structure can be |
| 2192 | encoded and decoded. |
| 2193 | Several other encoding rules (CER, DER) define a more restrictive versions |
| 2194 | of BER, so the generic BER parser is also capable of decoding the data |
| 2195 | encoded by CER and DER encoders. |
| 2196 | The opposite is not true. |
| 2197 | \layout Standard |
| 2198 | |
| 2199 | The ASN.1 compiler provides the generic BER decoder which is implicitly capable |
| 2200 | of decoding BER, CER and DER encoded data. |
| 2201 | \layout Standard |
| 2202 | |
| 2203 | The decoder is restartable (stream-oriented), which means that in case the |
| 2204 | buffer has less data than it is expected, the decoder will process whatever |
| 2205 | it is available and ask for more data to be provided. |
| 2206 | Please note that the decoder may actually process less data than it is |
| 2207 | given in the buffer, which means that you should be able to make the next |
| 2208 | buffer contain the unprocessed part of the previous buffer. |
| 2209 | \layout Standard |
| 2210 | |
| 2211 | Suppose, you have two buffers of encoded data: 100 bytes and 200 bytes. |
| 2212 | \layout Itemize |
| 2213 | |
| 2214 | You may concatenate these buffers and feed the BER decoder with 300 bytes |
| 2215 | of data, or |
| 2216 | \layout Itemize |
| 2217 | |
| 2218 | You may feed it the first buffer of 100 bytes of data, realize that the |
| 2219 | ber_decoder consumed only 95 bytes from it and later feed the decoder with |
| 2220 | 205 bytes buffer which consists of 5 unprocessed bytes from the first buffer |
| 2221 | and the latter 200 bytes from the second buffer. |
| 2222 | \layout Standard |
| 2223 | |
| 2224 | This is not as convenient as it could be (like, the BER encoder would consume |
| 2225 | the whole 100 bytes and keep these 5 bytes in some temporary storage), |
| 2226 | but in case of stream-based processing it might actually be OK. |
| 2227 | Suggestions are welcome. |
| 2228 | \layout Standard |
| 2229 | |
| 2230 | There are two ways to invoke a BER decoder. |
| 2231 | The first one is a direct reference of the type-specific decoder. |
| 2232 | This way was shown in the previous example of |
| 2233 | \emph on |
| 2234 | simple_deserializer |
| 2235 | \emph default |
| 2236 | function. |
| 2237 | The second way is to invoke a |
| 2238 | \emph on |
| 2239 | ber_decode |
| 2240 | \emph default |
| 2241 | function, which is just a simple wrapper of the former approach into a |
| 2242 | less wordy notation: |
| 2243 | \layout LyX-Code |
| 2244 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2245 | rval = ber_decode(0, &asn_DEF_Rectangle, (void **)&rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2246 | \layout LyX-Code |
| 2247 | |
| 2248 | buffer, buf_size); |
| 2249 | \layout Standard |
| 2250 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2251 | Note that the initial (asn_DEF_Rectangle->ber_decoder) reference is gone, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2252 | and also the last argument (0) is no longer necessary. |
| 2253 | \layout Standard |
| 2254 | |
| 2255 | These two ways of invocations are fully equivalent. |
| 2256 | \layout Standard |
| 2257 | |
| 2258 | The BER de |
| 2259 | \emph on |
| 2260 | coder |
| 2261 | \emph default |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2262 | may fail because of ( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2263 | \emph on |
| 2264 | the following RC_\SpecialChar \ldots{} |
| 2265 | codes are defined in ber_decoder.h |
| 2266 | \emph default |
| 2267 | ): |
| 2268 | \layout Itemize |
| 2269 | |
| 2270 | RC_WMORE: There is more data expected than it is provided (stream mode continuat |
| 2271 | ion feature); |
| 2272 | \layout Itemize |
| 2273 | |
| 2274 | RC_FAIL: General failure to decode the buffer; |
| 2275 | \layout Itemize |
| 2276 | |
| 2277 | \SpecialChar \ldots{} |
| 2278 | other codes may be defined as well. |
| 2279 | \layout Standard |
| 2280 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 2281 | Together with the return code (.code) the asn_dec_rval_t type contains the |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2282 | number of bytes which is consumed from the buffer. |
| 2283 | In the previous hypothetical example of two buffers (of 100 and 200 bytes), |
| 2284 | the first call to ber_decode() would return with .code = RC_WMORE and .consumed |
| 2285 | = 95. |
| 2286 | The .consumed field of the BER decoder return value is |
| 2287 | \series bold |
| 2288 | always |
| 2289 | \series default |
| 2290 | valid, even if the decoder succeeds or fails with any other return code. |
| 2291 | \layout Standard |
| 2292 | |
| 2293 | Please look into ber_decoder.h for the precise definition of ber_decode() |
| 2294 | and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2295 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2296 | |
| 2297 | |
| 2298 | \begin_inset LatexCommand \label{sub:Encoding-DER} |
| 2299 | |
| 2300 | \end_inset |
| 2301 | |
| 2302 | Encoding DER |
| 2303 | \layout Standard |
| 2304 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2305 | The Distinguished Encoding Rules is the |
| 2306 | \emph on |
| 2307 | canonical |
| 2308 | \emph default |
| 2309 | variant of BER encoding rules. |
| 2310 | The DER is best suited to encode the structures where all the lengths are |
| 2311 | known beforehand. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2312 | This is probably exactly how you want to encode: either after a BER decoding |
| 2313 | or after a manual fill-up, the target structure contains the data which |
| 2314 | size is implicitly known before encoding. |
| 2315 | The DER encoding is used, for example, to encode X.509 certificates. |
| 2316 | \layout Standard |
| 2317 | |
| 2318 | As with BER decoder, the DER encoder may be invoked either directly from |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2319 | the ASN.1 type descriptor (asn_DEF_Rectangle) or from the stand-alone function, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2320 | which is somewhat simpler: |
| 2321 | \layout LyX-Code |
| 2322 | |
| 2323 | /* |
| 2324 | \layout LyX-Code |
| 2325 | |
| 2326 | * This is a custom function which writes the |
| 2327 | \layout LyX-Code |
| 2328 | |
| 2329 | * encoded output into some FILE stream. |
| 2330 | \layout LyX-Code |
| 2331 | |
| 2332 | */ |
| 2333 | \layout LyX-Code |
| 2334 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2335 | static int |
| 2336 | \layout LyX-Code |
| 2337 | |
| 2338 | write_stream(const void *buffer, size_t size, void *app_key) { |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2339 | \layout LyX-Code |
| 2340 | |
| 2341 | FILE *ostream = app_key; |
| 2342 | \layout LyX-Code |
| 2343 | |
| 2344 | size_t wrote; |
| 2345 | \layout LyX-Code |
| 2346 | |
| 2347 | |
| 2348 | \layout LyX-Code |
| 2349 | |
| 2350 | wrote = fwrite(buffer, 1, size, ostream); |
| 2351 | \layout LyX-Code |
| 2352 | |
| 2353 | |
| 2354 | \layout LyX-Code |
| 2355 | |
| 2356 | return (wrote == size) ? 0 : -1; |
| 2357 | \layout LyX-Code |
| 2358 | |
| 2359 | } |
| 2360 | \layout LyX-Code |
| 2361 | |
| 2362 | |
| 2363 | \layout LyX-Code |
| 2364 | |
| 2365 | /* |
| 2366 | \layout LyX-Code |
| 2367 | |
| 2368 | * This is the serializer itself, |
| 2369 | \layout LyX-Code |
| 2370 | |
| 2371 | * it supplies the DER encoder with the |
| 2372 | \layout LyX-Code |
| 2373 | |
| 2374 | * pointer to the custom output function. |
| 2375 | \layout LyX-Code |
| 2376 | |
| 2377 | */ |
| 2378 | \layout LyX-Code |
| 2379 | |
| 2380 | ssize_t |
| 2381 | \layout LyX-Code |
| 2382 | |
| 2383 | simple_serializer(FILE *ostream, Rectangle_t *rect) { |
| 2384 | \layout LyX-Code |
| 2385 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2386 | asn_enc_rval_t er; /* Encoder return value */ |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2387 | \layout LyX-Code |
| 2388 | |
| 2389 | |
| 2390 | \layout LyX-Code |
| 2391 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2392 | er = der_encode(&asn_DEF_Rect, rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2393 | \layout LyX-Code |
| 2394 | |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2395 | write_stream, ostream); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2396 | \layout LyX-Code |
| 2397 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2398 | if(er. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2399 | \series bold |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2400 | encoded |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2401 | \series default |
| 2402 | == -1) { |
| 2403 | \layout LyX-Code |
| 2404 | |
| 2405 | /* |
| 2406 | \layout LyX-Code |
| 2407 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2408 | * Failed to encode the rectangle data. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2409 | \layout LyX-Code |
| 2410 | |
| 2411 | */ |
| 2412 | \layout LyX-Code |
| 2413 | |
| 2414 | fprintf(stderr, |
| 2415 | \begin_inset Quotes sld |
| 2416 | \end_inset |
| 2417 | |
| 2418 | Cannot encode %s: %s |
| 2419 | \backslash |
| 2420 | n |
| 2421 | \begin_inset Quotes srd |
| 2422 | \end_inset |
| 2423 | |
| 2424 | , |
| 2425 | \layout LyX-Code |
| 2426 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2427 | er. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2428 | \series bold |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2429 | failed_type |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2430 | \series default |
| 2431 | ->name, |
| 2432 | \layout LyX-Code |
| 2433 | |
| 2434 | strerror(errno)); |
| 2435 | \layout LyX-Code |
| 2436 | |
| 2437 | return -1; |
| 2438 | \layout LyX-Code |
| 2439 | |
| 2440 | } else { |
| 2441 | \layout LyX-Code |
| 2442 | |
| 2443 | /* Return the number of bytes */ |
| 2444 | \layout LyX-Code |
| 2445 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2446 | return er.encoded; |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2447 | \layout LyX-Code |
| 2448 | |
| 2449 | } |
| 2450 | \layout LyX-Code |
| 2451 | |
| 2452 | } |
| 2453 | \layout Standard |
| 2454 | |
| 2455 | As you see, the DER encoder does not write into some sort of buffer or something. |
| 2456 | It just invokes the custom function (possible, multiple times) which would |
| 2457 | save the data into appropriate storage. |
| 2458 | The optional argument |
| 2459 | \emph on |
| 2460 | app_key |
| 2461 | \emph default |
| 2462 | is opaque for the DER encoder code and just used by |
| 2463 | \emph on |
| 2464 | _write_stream() |
| 2465 | \emph default |
| 2466 | as the pointer to the appropriate output stream to be used. |
| 2467 | \layout Standard |
| 2468 | |
| 2469 | If the custom write function is not given (passed as 0), then the DER encoder |
| 2470 | will essentially do the same thing (i.e., encode the data) but no callbacks |
| 2471 | will be invoked (so the data goes nowhere). |
| 2472 | It may prove useful to determine the size of the structure's encoding before |
| 2473 | actually doing the encoding |
| 2474 | \begin_inset Foot |
| 2475 | collapsed false |
| 2476 | |
| 2477 | \layout Standard |
| 2478 | |
| 2479 | It is actually faster too: the encoder might skip over some computations |
| 2480 | which aren't important for the size determination. |
| 2481 | \end_inset |
| 2482 | |
| 2483 | . |
| 2484 | \layout Standard |
| 2485 | |
| 2486 | Please look into der_encoder.h for the precise definition of der_encode() |
| 2487 | and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2488 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2489 | |
| 2490 | |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2491 | \begin_inset LatexCommand \label{sub:Encoding-XER} |
| 2492 | |
| 2493 | \end_inset |
| 2494 | |
| 2495 | Encoding XER |
| 2496 | \layout Standard |
| 2497 | |
| 2498 | The XER stands for XML Encoding Rules, where XML, in turn, is eXtensible |
| 2499 | Markup Language, a text-based format for information exchange. |
| 2500 | The encoder routine API comes in two flavors: stdio-based and callback-based. |
| 2501 | With the callback-based encoder, the encoding process is very similar to |
| 2502 | the DER one, described in Section |
| 2503 | \begin_inset LatexCommand \vref{sub:Encoding-DER} |
| 2504 | |
| 2505 | \end_inset |
| 2506 | |
| 2507 | . |
| 2508 | The following example uses the definition of write_stream() from up there. |
| 2509 | \layout LyX-Code |
| 2510 | |
| 2511 | /* |
| 2512 | \layout LyX-Code |
| 2513 | |
| 2514 | * This procedure generates the XML document |
| 2515 | \layout LyX-Code |
| 2516 | |
| 2517 | * by invoking the XER encoder. |
| 2518 | \layout LyX-Code |
| 2519 | |
| 2520 | * NOTE: Do not copy this code verbatim! |
| 2521 | \layout LyX-Code |
| 2522 | |
| 2523 | * If the stdio output is necessary, |
| 2524 | \layout LyX-Code |
| 2525 | |
| 2526 | * use the xer_fprint() procedure instead. |
| 2527 | \layout LyX-Code |
| 2528 | |
| 2529 | * See Section |
| 2530 | \begin_inset LatexCommand \vref{sub:Printing-the-target} |
| 2531 | |
| 2532 | \end_inset |
| 2533 | |
| 2534 | . |
| 2535 | \layout LyX-Code |
| 2536 | |
| 2537 | */ |
| 2538 | \layout LyX-Code |
| 2539 | |
| 2540 | int |
| 2541 | \layout LyX-Code |
| 2542 | |
| 2543 | print_as_XML(FILE *ostream, Rectangle_t *rect) { |
| 2544 | \layout LyX-Code |
| 2545 | |
| 2546 | asn_enc_rval_t er; /* Encoder return value */ |
| 2547 | \layout LyX-Code |
| 2548 | |
| 2549 | |
| 2550 | \layout LyX-Code |
| 2551 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2552 | er = xer_encode(&asn_DEF_Rect, rect, |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2553 | \layout LyX-Code |
| 2554 | |
| 2555 | XER_F_BASIC, /* BASIC-XER or CANONICAL-XER */ |
| 2556 | \layout LyX-Code |
| 2557 | |
| 2558 | write_stream, ostream); |
| 2559 | \layout LyX-Code |
| 2560 | |
| 2561 | |
| 2562 | \layout LyX-Code |
| 2563 | |
| 2564 | return (er.encoded == -1) ? -1 : 0; |
| 2565 | \layout LyX-Code |
| 2566 | |
| 2567 | } |
| 2568 | \layout Standard |
| 2569 | |
| 2570 | Please look into xer_encoder.h for the precise definition of xer_encode() |
| 2571 | and related types. |
| 2572 | \layout Standard |
| 2573 | |
| 2574 | See Section |
| 2575 | \begin_inset LatexCommand \ref{sub:Printing-the-target} |
| 2576 | |
| 2577 | \end_inset |
| 2578 | |
| 2579 | for the example of stdio-based XML encoder and other pretty-printing suggestion |
| 2580 | s. |
| 2581 | \layout Subsection |
| 2582 | |
| 2583 | |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2584 | \begin_inset LatexCommand \label{sub:Validating-the-target} |
| 2585 | |
| 2586 | \end_inset |
| 2587 | |
| 2588 | Validating the target structure |
| 2589 | \layout Standard |
| 2590 | |
| 2591 | Sometimes the target structure needs to be validated. |
| 2592 | For example, if the structure was created by the application (as opposed |
| 2593 | to being decoded from some external source), some important information |
| 2594 | required by the ASN.1 specification might be missing. |
| 2595 | On the other hand, the successful decoding of the data from some external |
| 2596 | source does not necessarily mean that the data is fully valid either. |
| 2597 | It might well be the case that the specification describes some subtype |
| 2598 | constraints that were not taken into account during decoding, and it would |
| 2599 | actually be useful to perform the last check when the data is ready to |
| 2600 | be encoded or when the data has just been decoded to ensure its validity |
| 2601 | according to some stricter rules. |
| 2602 | \layout Standard |
| 2603 | |
| 2604 | The asn_check_constraints() function checks the type for various implicit |
| 2605 | and explicit constraints. |
| 2606 | It is recommended to use asn_check_constraints() function after each decoding |
| 2607 | and before each encoding. |
| 2608 | \layout Standard |
| 2609 | |
| 2610 | Please look into constraints.h for the precise definition of asn_check_constraint |
| 2611 | s() and related types. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2612 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2613 | |
| 2614 | |
| 2615 | \begin_inset LatexCommand \label{sub:Printing-the-target} |
| 2616 | |
| 2617 | \end_inset |
| 2618 | |
| 2619 | Printing the target structure |
| 2620 | \layout Standard |
| 2621 | |
| 2622 | There are two ways to print the target structure: either invoke the print_struct |
| 2623 | member of the ASN.1 type descriptor, or using the asn_fprint() function, |
| 2624 | which is a simpler wrapper of the former: |
| 2625 | \layout LyX-Code |
| 2626 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2627 | asn_fprint(stdout, &asn_DEF_Rectangle, rect); |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2628 | \layout Standard |
| 2629 | |
| 2630 | Please look into constr_TYPE.h for the precise definition of asn_fprint() |
| 2631 | and related types. |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2632 | \layout Standard |
| 2633 | |
| 2634 | Another practical alternative to this custom format printing would be to |
| 2635 | invoke XER encoder. |
| 2636 | The default BASIC-XER encoder performs reasonable formatting for the output |
| 2637 | to be useful and human readable. |
| 2638 | To invoke the XER decoder in a manner similar to asn_fprint(), use the |
| 2639 | xer_fprint() call: |
| 2640 | \layout LyX-Code |
| 2641 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2642 | xer_fprint(stdout, &asn_DEF_Rectangle, rect); |
vlm | 68d43e9 | 2004-09-24 20:56:07 +0000 | [diff] [blame] | 2643 | \layout Standard |
| 2644 | |
| 2645 | See Section |
| 2646 | \begin_inset LatexCommand \vref{sub:Encoding-XER} |
| 2647 | |
| 2648 | \end_inset |
| 2649 | |
| 2650 | for XML-related details. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 2651 | \layout Subsection |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2652 | |
| 2653 | |
| 2654 | \begin_inset LatexCommand \label{sub:Freeing-the-target} |
| 2655 | |
| 2656 | \end_inset |
| 2657 | |
| 2658 | Freeing the target structure |
| 2659 | \layout Standard |
| 2660 | |
| 2661 | Freeing the structure is slightly more complex than it may seem to. |
| 2662 | When the ASN.1 structure is freed, all the members of the structure and |
| 2663 | their submembers etc etc are recursively freed too. |
| 2664 | But it might not be feasible to free the structure itself. |
| 2665 | Consider the following case: |
| 2666 | \layout LyX-Code |
| 2667 | |
| 2668 | struct my_figure { /* The custom structure */ |
| 2669 | \layout LyX-Code |
| 2670 | |
| 2671 | int flags; /* <some custom member> */ |
| 2672 | \layout LyX-Code |
| 2673 | |
| 2674 | /* The type is generated by the ASN.1 compiler */ |
| 2675 | \layout LyX-Code |
| 2676 | |
| 2677 | |
| 2678 | \emph on |
| 2679 | Rectangle_t rect; |
| 2680 | \layout LyX-Code |
| 2681 | |
| 2682 | /* other members of the structure */ |
| 2683 | \layout LyX-Code |
| 2684 | |
| 2685 | }; |
| 2686 | \layout Standard |
| 2687 | |
| 2688 | In this example, the application programmer defined a custom structure with |
| 2689 | one ASN.1-derived member (rect). |
| 2690 | This member is not a reference to the Rectangle_t, but an in-place inclusion |
| 2691 | of the Rectangle_t structure. |
| 2692 | If the freeing is necessary, the usual procedure of freeing everything |
| 2693 | must not be applied to the &rect pointer itself, because it does not point |
| 2694 | to the memory block directly allocated by memory allocation routine, but |
| 2695 | instead lies within such a block allocated for my_figure structure. |
| 2696 | \layout Standard |
| 2697 | |
| 2698 | To solve this problem, the free_struct routine has the additional argument |
| 2699 | (besides the intuitive type descriptor and target structure pointers), |
| 2700 | which is the flag specifying whether the outer pointer itself must be freed |
| 2701 | (0, default) or it should be left intact (non-zero value). |
| 2702 | \layout LyX-Code |
| 2703 | |
| 2704 | /* Rectangle_t is defined within my_figure */ |
| 2705 | \layout LyX-Code |
| 2706 | |
| 2707 | struct my_figure *mf = |
| 2708 | \series bold |
| 2709 | ... |
| 2710 | \series default |
| 2711 | ; |
| 2712 | \layout LyX-Code |
| 2713 | |
| 2714 | /* |
| 2715 | \layout LyX-Code |
| 2716 | |
| 2717 | * Freeing the Rectangle_td |
| 2718 | \layout LyX-Code |
| 2719 | |
| 2720 | * without freeing the mf->rect pointer |
| 2721 | \layout LyX-Code |
| 2722 | |
| 2723 | */ |
| 2724 | \layout LyX-Code |
| 2725 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2726 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2727 | \layout LyX-Code |
| 2728 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2729 | &asn_DEF_Rectangle, &mf->rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2730 | \emph on |
| 2731 | 1 |
| 2732 | \emph default |
| 2733 | /* !free */); |
| 2734 | \layout LyX-Code |
| 2735 | |
| 2736 | |
| 2737 | \layout LyX-Code |
| 2738 | |
| 2739 | /* Rectangle_t is a stand-alone pointer */ |
| 2740 | \layout LyX-Code |
| 2741 | |
| 2742 | Rectangle_t *rect = |
| 2743 | \series bold |
| 2744 | ... |
| 2745 | \series default |
| 2746 | ; |
| 2747 | \layout LyX-Code |
| 2748 | |
| 2749 | /* |
| 2750 | \layout LyX-Code |
| 2751 | |
| 2752 | * Freeing the Rectangle_t |
| 2753 | \layout LyX-Code |
| 2754 | |
| 2755 | * and freeing the rect pointer |
| 2756 | \layout LyX-Code |
| 2757 | |
| 2758 | */ |
| 2759 | \layout LyX-Code |
| 2760 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2761 | asn_DEF_Rectangle->free_struct( |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2762 | \layout LyX-Code |
| 2763 | |
vlm | ba56d85 | 2004-09-29 13:29:17 +0000 | [diff] [blame] | 2764 | &asn_DEF_Rectangle, rect, |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 2765 | \emph on |
| 2766 | 0 |
| 2767 | \emph default |
| 2768 | /* free the pointer too */); |
| 2769 | \layout Standard |
| 2770 | |
| 2771 | It is safe to invoke the |
| 2772 | \emph on |
| 2773 | free_struct |
| 2774 | \emph default |
| 2775 | function with the target structure pointer set to 0 (NULL), the function |
| 2776 | will do nothing. |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 2777 | \layout Part |
| 2778 | |
| 2779 | Examples |
| 2780 | \layout Chapter |
| 2781 | |
| 2782 | Step-by-step: A |
| 2783 | \begin_inset Quotes sld |
| 2784 | \end_inset |
| 2785 | |
| 2786 | Rectangle |
| 2787 | \begin_inset Quotes srd |
| 2788 | \end_inset |
| 2789 | |
| 2790 | Decoder |
| 2791 | \layout Standard |
| 2792 | |
| 2793 | This chapter will help you to create a simple decoder of a simple |
| 2794 | \begin_inset Quotes sld |
| 2795 | \end_inset |
| 2796 | |
| 2797 | Rectangle |
| 2798 | \begin_inset Quotes srd |
| 2799 | \end_inset |
| 2800 | |
| 2801 | type used throughout this document. |
| 2802 | \layout Enumerate |
| 2803 | |
| 2804 | Create a file named |
| 2805 | \series bold |
| 2806 | rectangle.asn1 |
| 2807 | \series default |
| 2808 | with the following contents: |
| 2809 | \begin_deeper |
| 2810 | \layout LyX-Code |
| 2811 | |
| 2812 | RectangleModule1 DEFINITIONS ::= |
| 2813 | \layout LyX-Code |
| 2814 | |
| 2815 | BEGIN |
| 2816 | \layout LyX-Code |
| 2817 | |
| 2818 | |
| 2819 | \layout LyX-Code |
| 2820 | |
| 2821 | Rectangle ::= SEQUENCE { |
| 2822 | \layout LyX-Code |
| 2823 | |
| 2824 | height INTEGER, |
| 2825 | \layout LyX-Code |
| 2826 | |
| 2827 | width INTEGER |
| 2828 | \layout LyX-Code |
| 2829 | |
| 2830 | } |
| 2831 | \layout LyX-Code |
| 2832 | |
| 2833 | |
| 2834 | \layout LyX-Code |
| 2835 | |
| 2836 | END |
| 2837 | \end_deeper |
| 2838 | \layout Enumerate |
| 2839 | |
| 2840 | Compile it into the set of .c and .h files using asn1c compiler |
| 2841 | \begin_inset LatexCommand \cite{ASN1C} |
| 2842 | |
| 2843 | \end_inset |
| 2844 | |
| 2845 | : |
| 2846 | \begin_deeper |
| 2847 | \layout LyX-Code |
| 2848 | |
| 2849 | |
| 2850 | \emph on |
| 2851 | asn1c -fnative-types |
| 2852 | \series bold |
| 2853 | \emph default |
| 2854 | rectangle.asn1 |
| 2855 | \end_deeper |
| 2856 | \layout Enumerate |
| 2857 | |
| 2858 | Alternatively, use the Online ASN.1 compiler |
| 2859 | \begin_inset LatexCommand \cite{AONL} |
| 2860 | |
| 2861 | \end_inset |
| 2862 | |
| 2863 | by uploading the |
| 2864 | \series bold |
| 2865 | rectangle.asn1 |
| 2866 | \series default |
| 2867 | file into the Web form and unpacking the produced archive into the target |
| 2868 | directory on your computer. |
| 2869 | \layout Enumerate |
| 2870 | |
| 2871 | By this time, you should have multiple files in the current directory, including |
| 2872 | the Rectangle.c and Rectangle.h files. |
| 2873 | \layout Enumerate |
| 2874 | |
| 2875 | Create a main() routine which takes the binary input file, decodes it as |
| 2876 | it were a BER-encoded Rectangle type, and print out the text (XML) representati |
| 2877 | on of the Rectangle type. |
| 2878 | Let's name the file |
| 2879 | \series bold |
| 2880 | main.c |
| 2881 | \series default |
| 2882 | : |
| 2883 | \begin_deeper |
| 2884 | \layout LyX-Code |
| 2885 | |
| 2886 | |
| 2887 | \size small |
| 2888 | #include <stdio.h> |
| 2889 | \layout LyX-Code |
| 2890 | |
| 2891 | |
| 2892 | \size small |
| 2893 | #include <sys/types.h> |
| 2894 | \layout LyX-Code |
| 2895 | |
| 2896 | |
| 2897 | \size small |
| 2898 | #include <Rectangle.h> /* Rectangle ASN.1 type */ |
| 2899 | \layout LyX-Code |
| 2900 | |
| 2901 | |
| 2902 | \size small |
| 2903 | |
| 2904 | \layout LyX-Code |
| 2905 | |
| 2906 | |
| 2907 | \size small |
| 2908 | int main(int ac, char **av) { |
| 2909 | \layout LyX-Code |
| 2910 | |
| 2911 | |
| 2912 | \size small |
| 2913 | char buf[1024]; /* Temporary buffer */ |
| 2914 | \layout LyX-Code |
| 2915 | |
| 2916 | |
| 2917 | \size small |
| 2918 | Rectangle_t *rectangle = 0; /* Type to decode */ |
| 2919 | \layout LyX-Code |
| 2920 | |
| 2921 | |
| 2922 | \size small |
| 2923 | asn_dec_rval_t rval; /* Decoder return value */ |
| 2924 | \layout LyX-Code |
| 2925 | |
| 2926 | |
| 2927 | \size small |
| 2928 | FILE *fp; /* Input file handler */ |
| 2929 | \layout LyX-Code |
| 2930 | |
| 2931 | |
| 2932 | \size small |
| 2933 | size_t size; /* Number of bytes read */ |
| 2934 | \layout LyX-Code |
| 2935 | |
| 2936 | |
| 2937 | \size small |
| 2938 | char *filename; /* Input file name */ |
| 2939 | \layout LyX-Code |
| 2940 | |
| 2941 | |
| 2942 | \size small |
| 2943 | |
| 2944 | \layout LyX-Code |
| 2945 | |
| 2946 | |
| 2947 | \size small |
| 2948 | /* Require a single filename argument */ |
| 2949 | \layout LyX-Code |
| 2950 | |
| 2951 | |
| 2952 | \size small |
| 2953 | if(ac != 2) { |
| 2954 | \layout LyX-Code |
| 2955 | |
| 2956 | |
| 2957 | \size small |
| 2958 | fprintf(stderr, |
| 2959 | \begin_inset Quotes sld |
| 2960 | \end_inset |
| 2961 | |
| 2962 | Usage: %s <file.ber> |
| 2963 | \backslash |
| 2964 | n |
| 2965 | \begin_inset Quotes srd |
| 2966 | \end_inset |
| 2967 | |
| 2968 | , av[0]); |
| 2969 | \layout LyX-Code |
| 2970 | |
| 2971 | |
| 2972 | \size small |
| 2973 | exit(64); /* better, EX_USAGE */ |
| 2974 | \layout LyX-Code |
| 2975 | |
| 2976 | |
| 2977 | \size small |
| 2978 | } else { |
| 2979 | \layout LyX-Code |
| 2980 | |
| 2981 | |
| 2982 | \size small |
| 2983 | filename = av[1]; |
| 2984 | \layout LyX-Code |
| 2985 | |
| 2986 | |
| 2987 | \size small |
| 2988 | } |
| 2989 | \layout LyX-Code |
| 2990 | |
| 2991 | |
| 2992 | \size small |
| 2993 | |
| 2994 | \layout LyX-Code |
| 2995 | |
| 2996 | |
| 2997 | \size small |
| 2998 | /* Open input file as read-only binary */ |
| 2999 | \layout LyX-Code |
| 3000 | |
| 3001 | |
| 3002 | \size small |
| 3003 | fp = fopen(filename, |
| 3004 | \begin_inset Quotes sld |
| 3005 | \end_inset |
| 3006 | |
| 3007 | rb |
| 3008 | \begin_inset Quotes srd |
| 3009 | \end_inset |
| 3010 | |
| 3011 | ); |
| 3012 | \layout LyX-Code |
| 3013 | |
| 3014 | |
| 3015 | \size small |
| 3016 | if(!fp) { |
| 3017 | \layout LyX-Code |
| 3018 | |
| 3019 | |
| 3020 | \size small |
| 3021 | perror(filename); |
| 3022 | \layout LyX-Code |
| 3023 | |
| 3024 | |
| 3025 | \size small |
| 3026 | exit(66); /* better, EX_NOINPUT */ |
| 3027 | \layout LyX-Code |
| 3028 | |
| 3029 | |
| 3030 | \size small |
| 3031 | } |
| 3032 | \layout LyX-Code |
| 3033 | |
| 3034 | |
| 3035 | \size small |
| 3036 | |
| 3037 | \layout LyX-Code |
| 3038 | |
| 3039 | |
| 3040 | \size small |
| 3041 | /* Read up to the buffer size */ |
| 3042 | \layout LyX-Code |
| 3043 | |
| 3044 | |
| 3045 | \size small |
| 3046 | size = fread(buf, 1, sizeof(buf), fp); |
| 3047 | \layout LyX-Code |
| 3048 | |
| 3049 | |
| 3050 | \size small |
| 3051 | fclose(fp); |
| 3052 | \layout LyX-Code |
| 3053 | |
| 3054 | |
| 3055 | \size small |
| 3056 | if(!size) { |
| 3057 | \layout LyX-Code |
| 3058 | |
| 3059 | |
| 3060 | \size small |
| 3061 | fprintf(stderr, |
| 3062 | \begin_inset Quotes sld |
| 3063 | \end_inset |
| 3064 | |
| 3065 | %s: Empty or broken |
| 3066 | \backslash |
| 3067 | n |
| 3068 | \begin_inset Quotes srd |
| 3069 | \end_inset |
| 3070 | |
| 3071 | , filename); |
| 3072 | \layout LyX-Code |
| 3073 | |
| 3074 | |
| 3075 | \size small |
| 3076 | exit(65); /* better, EX_DATAERR */ |
| 3077 | \layout LyX-Code |
| 3078 | |
| 3079 | |
| 3080 | \size small |
| 3081 | } |
| 3082 | \layout LyX-Code |
| 3083 | |
| 3084 | |
| 3085 | \size small |
| 3086 | |
| 3087 | \layout LyX-Code |
| 3088 | |
| 3089 | |
| 3090 | \size small |
| 3091 | /* Decode the input buffer as Rectangle type */ |
| 3092 | \layout LyX-Code |
| 3093 | |
| 3094 | |
| 3095 | \size small |
| 3096 | rval = ber_decode(0, &asn_DEF_Rectangle, |
| 3097 | \layout LyX-Code |
| 3098 | |
| 3099 | |
| 3100 | \size small |
| 3101 | (void **)&rectangle, buf, size); |
| 3102 | \layout LyX-Code |
| 3103 | |
| 3104 | |
| 3105 | \size small |
| 3106 | if(rval.code != RC_OK) { |
| 3107 | \layout LyX-Code |
| 3108 | |
| 3109 | |
| 3110 | \size small |
| 3111 | fprintf(stderr, |
| 3112 | \layout LyX-Code |
| 3113 | |
| 3114 | |
| 3115 | \size small |
| 3116 | |
| 3117 | \begin_inset Quotes sld |
| 3118 | \end_inset |
| 3119 | |
| 3120 | %s: Broken Rectangle encoding at byte %ld |
| 3121 | \backslash |
| 3122 | n |
| 3123 | \begin_inset Quotes srd |
| 3124 | \end_inset |
| 3125 | |
| 3126 | , |
| 3127 | \layout LyX-Code |
| 3128 | |
| 3129 | |
| 3130 | \size small |
| 3131 | filename, (long)rval.consumed); |
| 3132 | \layout LyX-Code |
| 3133 | |
| 3134 | |
| 3135 | \size small |
| 3136 | exit(65); /* better, EX_DATAERR */ |
| 3137 | \layout LyX-Code |
| 3138 | |
| 3139 | |
| 3140 | \size small |
| 3141 | } |
| 3142 | \layout LyX-Code |
| 3143 | |
| 3144 | |
| 3145 | \size small |
| 3146 | |
| 3147 | \layout LyX-Code |
| 3148 | |
| 3149 | |
| 3150 | \size small |
| 3151 | /* Print the decoded Rectangle type as XML */ |
| 3152 | \layout LyX-Code |
| 3153 | |
| 3154 | |
| 3155 | \size small |
| 3156 | xer_fprint(stdout, &asn_DEF_Rectangle, rectangle); |
| 3157 | \layout LyX-Code |
| 3158 | |
| 3159 | |
| 3160 | \size small |
| 3161 | |
| 3162 | \layout LyX-Code |
| 3163 | |
| 3164 | |
| 3165 | \size small |
| 3166 | return 0; /* Decoding finished successfully */ |
| 3167 | \layout LyX-Code |
| 3168 | |
| 3169 | |
| 3170 | \size small |
| 3171 | } |
| 3172 | \end_deeper |
| 3173 | \layout Enumerate |
| 3174 | |
| 3175 | Compile all files together using C compiler: |
| 3176 | \begin_deeper |
| 3177 | \layout LyX-Code |
| 3178 | |
| 3179 | |
| 3180 | \emph on |
| 3181 | cc -I. |
| 3182 | -o rdecode *.c |
| 3183 | \end_deeper |
| 3184 | \layout Enumerate |
| 3185 | |
| 3186 | Voila! You have just created the Rectangle type decoder named |
| 3187 | \series bold |
| 3188 | rdecode |
| 3189 | \series default |
| 3190 | ! |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 3191 | \layout Bibliography |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 3192 | \bibitem [ASN1C]{ASN1C} |
| 3193 | |
vlm | 89d219b | 2004-09-08 03:01:06 +0000 | [diff] [blame] | 3194 | The OpenSource ASN.1 Compiler. |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 3195 | |
vlm | c3bfd81 | 2004-09-30 22:26:19 +0000 | [diff] [blame] | 3196 | \begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c/} |
vlm | fcec8e5 | 2004-08-23 15:12:04 +0000 | [diff] [blame] | 3197 | |
| 3198 | \end_inset |
| 3199 | |
| 3200 | |
| 3201 | \layout Bibliography |
vlm | 4cb0edf | 2005-01-14 11:38:49 +0000 | [diff] [blame^] | 3202 | \bibitem [AONL]{AONL} |
| 3203 | |
| 3204 | Online ASN.1 Compiler. |
| 3205 | |
| 3206 | \begin_inset LatexCommand \htmlurl{http://lionet.info/asn1c/asn1c.cgi} |
| 3207 | |
| 3208 | \end_inset |
| 3209 | |
| 3210 | |
| 3211 | \layout Bibliography |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 3212 | \bibitem [Dub00]{Dub00} |
| 3213 | |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 3214 | Olivier Dubuisson --- |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 3215 | \emph on |
| 3216 | ASN.1 Communication between heterogeneous systems |
| 3217 | \emph default |
vlm | af2155e | 2004-10-20 15:48:55 +0000 | [diff] [blame] | 3218 | --- Morgan Kaufmann Publishers, 2000. |
vlm | e18adea | 2004-06-03 03:49:45 +0000 | [diff] [blame] | 3219 | |
| 3220 | \begin_inset LatexCommand \htmlurl{http://asn1.elibel.tm.fr/en/book/} |
| 3221 | |
| 3222 | \end_inset |
| 3223 | |
| 3224 | . |
| 3225 | ISBN:0-12-6333361-0. |
| 3226 | \layout Bibliography |
| 3227 | \bibitem [ITU-T/ASN.1]{ITU-T/ASN.1} |
| 3228 | |
| 3229 | ITU-T Study Group 17 -- Languages for Telecommunication Systems |
| 3230 | \begin_inset LatexCommand \url{http://www.itu.int/ITU-T/studygroups/com17/languages/} |
| 3231 | |
| 3232 | \end_inset |
| 3233 | |
| 3234 | |
| 3235 | \the_end |