Document that ider and ider_len are optional in asn1_der_decoding_startEnd()
[platform/upstream/libtasn1.git] / doc / libtasn1.texi
1 \input texinfo   @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename libtasn1.info
4 @include version.texi
5 @settitle GNU Libtasn1 @value{VERSION}
6
7 @c Unify some of the indices.
8 @syncodeindex tp fn
9 @syncodeindex pg fn
10
11 @comment %**end of header
12 @copying
13 This manual is for GNU Libtasn1
14 (version @value{VERSION}, @value{UPDATED}),
15 which is a library for Abstract Syntax Notation One (ASN.1) and
16 Distinguished Encoding Rules (DER) manipulation.
17
18 Copyright @copyright{} 2001-2014 Free Software Foundation, Inc.
19
20 @quotation
21 Permission is granted to copy, distribute and/or modify this document
22 under the terms of the GNU Free Documentation License, Version 1.3 or
23 any later version published by the Free Software Foundation; with no
24 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
25 copy of the license is included in the section entitled ``GNU Free
26 Documentation License''.
27 @end quotation
28 @end copying
29
30 @dircategory Software libraries
31 @direntry
32 * libtasn1: (libtasn1). Library for Abstract Syntax Notation One (ASN.1).
33 @end direntry
34
35 @titlepage
36 @title Libtasn1
37 @subtitle Abstract Syntax Notation One (ASN.1) library for the GNU system
38 @subtitle for version @value{VERSION}, @value{UPDATED}
39 @author Fabio Fiorina
40 @author Simon Josefsson
41 @author Nikos Mavrogiannopoulos (@email{help-libtasn1@@gnu.org})
42 @page
43 @vskip 0pt plus 1filll
44 @insertcopying
45 @end titlepage
46
47 @contents
48
49 @ifnottex
50 @node Top
51 @top Libtasn1
52
53 @insertcopying
54 @end ifnottex
55
56 @menu
57 * Introduction::
58 * ASN.1 structure handling::
59 * Utilities::
60 * Function reference::
61 * Copying Information::
62
63 Indices
64
65 * Concept Index::               Index of concepts and programs.
66 * Function and Data Index::     Index of functions, variables and data types.
67 @end menu
68
69 @node Introduction
70 @chapter Introduction
71
72 This document describes the Libtasn1 library that provides
73 Abstract Syntax Notation One (ASN.1, as specified by the X.680 ITU-T
74 recommendation) parsing and structures management,
75 and Distinguished Encoding Rules (DER, as per X.690) encoding and
76 decoding functions.
77
78 The main features of this library are:
79
80 @itemize @bullet
81
82 @item On-line ASN.1 structure management that doesn't require any
83 C code file generation.
84
85 @item Off-line ASN.1 structure management with C code file generation
86 containing an array.
87
88 @item Distinguished Encoding Rules (DER) encoding support.
89
90 @item No limits for INTEGER and ENUMERATED values.
91
92 @item It's Free Software.
93 Anybody can use, modify, and redistribute the library under the terms
94 of the GNU Lesser General Public License version 2.1 or later.  The
95 command line tools, self-tests and build infrastructure are licensed
96 under the GNU General Public License version 3.0 or later.
97
98 @item Thread-safety.
99 @cindex threads
100 No global variables are used and multiple library handles and session
101 handles may be used in parallel.
102
103 @item Portability.
104 @cindex Porting
105 The code should work on all Unix like operating systems, and Windows.
106 The library itself should be portable to any C89 system, not even
107 POSIX is required.
108 @end itemize
109
110 @node ASN.1 structure handling
111 @chapter ASN.1 structure handling
112
113 @menu
114 * ASN.1 syntax::
115 * Naming::
116 * Simple parsing::
117 * Library Notes::
118 * Future developments::
119 @end menu
120
121 @node ASN.1 syntax
122 @section ASN.1 syntax
123
124 @cindex ASN.1 schema
125
126 The parser is case sensitive.  The comments begin with @code{--} and
127 end either with another @code{--}, or at the end of the respective
128 line, whichever comes first.  The C-style @code{/*}, @code{*/}
129 comments are not supported.
130
131 For an example of the syntax, check the @file{pkix.asn} file
132 distributed with the library.
133
134 ASN.1 definitions must follow the syntax below:
135
136 @verbatim
137       definitions_name {<object definition>}
138
139       DEFINITIONS <EXPLICIT or IMPLICIT> TAGS ::=
140
141       BEGIN
142
143       <type and constants definitions>
144
145       END
146 @end verbatim
147
148 The @code{::=} token must be separate from other elements, so the
149 following declaration is invalid:
150
151 @example
152    -- INCORRECT
153    Version ::=INTEGER
154 @end example
155
156 The correct form is:
157
158 @example
159    Version ::= INTEGER
160 @end example
161
162 Here is the list of types that the parser can manage:
163
164 @cindex Supported ASN.1 types, list of
165
166 @itemize @bullet
167
168 @item @code{INTEGER};
169 @item @code{ENUMERATED};
170 @item @code{BOOLEAN};
171 @item @code{OBJECT IDENTIFIER};
172 @item @code{NULL};
173 @item @code{BIT STRING};
174 @item @code{OCTET STRING};
175 @item @code{UTCTime};
176 @item @code{GeneralizedTime};
177 @item @code{GeneralString};
178 @item @code{NumericString};
179 @item @code{IA5String};
180 @item @code{TeletexString};
181 @item @code{PrintableString};
182 @item @code{UniversalString};
183 @item @code{BMPString};
184 @item @code{UTF8String};
185 @item @code{VisibleString};
186 @item @code{SEQUENCE};
187 @item @code{SEQUENCE OF};
188 @item @code{SET};
189 @item @code{SET OF};
190 @item @code{CHOICE};
191 @item @code{ANY};
192 @item @code{ANY DEFINED BY}.
193
194 @end itemize
195
196 This version doesn't handle the @code{REAL} type.  It doesn't support
197 the @code{AUTOMATIC TAGS} option, and the @code{EXPORT} and
198 @code{IMPORT} sections, either.
199
200 The @code{SIZE} constraints are allowed, but no check is done on them.
201
202 @node Naming
203 @section Naming
204
205 Consider this definition:
206
207 @verbatim
208       Example { 1 2 3 4 }
209
210       DEFINITIONS EXPLICIT TAGS ::=
211
212       BEGIN
213
214       Group ::= SEQUENCE {
215          id   OBJECT IDENTIFIER,
216          value  Value
217       }
218
219       Value ::= SEQUENCE {
220          value1  INTEGER,
221          value2  BOOLEAN
222       }
223
224       END
225 @end verbatim
226
227 The notation to access the @samp{Group} type of the @samp{Example}
228 definition above is @samp{Example.Group} (as a NUL-terminated string.)
229 Such strings are used in the functions described below.
230
231 Others examples:
232
233 @itemize @bullet
234
235 @item field @samp{id} of the @samp{Group} type: @samp{Example.Group.id};
236
237 @item field @samp{value1} of the @samp{value} field of the @samp{Group}
238 type: @samp{Example.Group.value.value1}.
239
240 @end itemize
241
242 Elements of structured types unnamed by the respective definition
243 receive the names @code{?1}, @code{?2}, and so on.
244
245 The @code{?LAST} name indicates the last element of a @code{SET OF} or
246 @code{SEQUENCE OF}.
247
248 @node Simple parsing
249 @section Simple parsing
250
251 For simple types like @code{OCTET STRING} the simple parsing functions listed
252 below may be used instead.
253
254 @itemize
255 @item @ref{asn1_decode_simple_der}
256 @item @ref{asn1_encode_simple_der}
257 @end itemize
258
259 @node Library Notes
260 @section Library Notes
261
262 @cindex Header file libtasn1.h
263
264 The header file of this library is @file{libtasn1.h}.
265
266 @cindex Main type asn1_node
267
268 The main type used in it is @code{asn1_node}, and it's used to store
269 the ASN.1 definitions and structures (instances).
270
271 The @code{NULL} constant can be used for the variable
272 initialization.  For example:
273
274 @example
275  asn1_node definitions = NULL;
276 @end example
277
278 Some functions require an @code{errorDescription} argument of type
279 @code{char *}, pointing to a pre-allocated buffer of at least
280 @code{ASN1_MAX_ERROR_DESCRIPTION_SIZE} bytes size (e.g., as in
281 @samp{char description[ASN1_MAX_ERROR_DESCRIPTION_SIZE];}).
282
283 @code{ASN1_MAX_NAME_SIZE} is the maximum number of characters allowed
284 for an ASN.1 identifier.
285
286 @node Future developments
287 @section Future developments
288 @cindex Future developments
289
290 @itemize @bullet
291
292 @item Add functions for a C code file generation containing equivalent
293 data structures (not a single array like now).
294
295 @item The @code{REAL} type.
296
297 @end itemize
298
299 @node Utilities
300 @chapter Utilities
301
302 @menu
303 * Invoking asn1Parser::
304 * Invoking asn1Coding::
305 * Invoking asn1Decoding::
306 @end menu
307
308 @node Invoking asn1Parser
309 @section Invoking asn1Parser
310 @cindex asn1Parser program
311
312 @command{asn1Parser} reads a single file with ASN.1 definitions and
313 generates a
314 file with an array to use with libtasn1 functions.
315
316 @verbatim
317 Usage:  asn1Parser [options] file
318
319 Options:
320  -h : shows the help message.
321  -v : shows version information and exit.
322  -c : checks the syntax only.
323  -o file : output file.
324  -n name : array name.
325 @end verbatim
326
327 @node Invoking asn1Coding
328 @section Invoking asn1Coding
329 @cindex asn1Coding program
330
331 @command{asn1Coding} generates a DER encoding from a file with ASN.1
332 definitions and another one with assignments.
333
334 The file with assignments must have this syntax:
335
336 @verbatim
337 InstanceName  Asn1Definition
338
339 nameString  value
340
341 nameString  value
342 ...
343 @end verbatim
344
345 To specify the field of a @code{CHOICE} to be used, specify its name
346 as a value to the @code{CHOICE} element itself.  Use @code{''} to
347 denote the root element itself.
348 (as in the example below.)
349
350 The output file is a binary file with the DER encoding.
351
352 @verbatim
353 Usage:  asn1Coding [options] file1 file2
354  file1 : file with ASN1 definitions.
355  file2 : file with assignments.
356 Options:
357  -h : shows the help message.
358  -v : shows version information and exit.
359  -c : checks the syntax only.
360  -o file : output file.
361 @end verbatim
362
363 For example, consider an ASN.1 definitions file as follows:
364
365 @verbatim
366 PKIX1 { }
367
368 DEFINITIONS IMPLICIT TAGS ::=
369
370 BEGIN
371
372 Dss-Sig-Value ::= SEQUENCE {
373      r       INTEGER,
374      s       INTEGER
375 }
376
377 END
378 @end verbatim
379
380 And a assignments file as follows:
381
382 @verbatim
383 dp PKIX1.Dss-Sig-Value
384
385 r 42
386 s 47
387 @end verbatim
388
389 Running the command below will generate a @file{assign.out} file,
390 containing the DER encoding of @code{PKIX1.Dss-Sig-Value}.
391
392 @verbatim
393 $ asn1Coding pkix.asn assign.asn1
394 @end verbatim
395
396 If the root element is of the @code{CHOICE} type, the assignment file
397 may be like (using the types defined in @file{pkix.asn}):
398 @verbatim
399 elt PKIX1Implicit88.GeneralName
400
401 ''      dNSName
402 dNSName example.org
403 @end verbatim
404
405 @node Invoking asn1Decoding
406 @section Invoking asn1Decoding
407 @cindex asn1Decoding program
408
409 @command{asn1Decoding} generates an ASN.1 structure from a file with
410 ASN.1
411 definitions and a binary file with a DER encoding.
412
413 @verbatim
414 Usage:  asn1Decoding [options] file1 file2 type
415  file1 : file with ASN1 definitions.
416  file2 : binary file with a DER encoding.
417  type : ASN1 definition name.
418 Options:
419  -h : shows the help message.
420  -v : shows version information and exit.
421  -o file : output file.
422 @end verbatim
423
424 For example, after generating the @file{assign.out} file from the
425 example section of the @command{asn1Coding} command above, the
426 following
427 invocation will decode the DER data.
428
429 @verbatim
430 $ asn1Decoding pkix.asn assign.out PKIX1.Dss-Sig-Value
431 @end verbatim
432
433 @node Function reference
434 @chapter Function reference
435
436 @menu
437 * ASN.1 schema functions::
438 * ASN.1 field functions::
439 * DER functions::
440 * Error handling functions::
441 * Auxilliary functions::
442 @end menu
443
444 @node ASN.1 schema functions
445 @section ASN.1 schema functions
446
447 @include texi/ASN1.c.texi
448
449 @node ASN.1 field functions
450 @section ASN.1 field functions
451
452 @include texi/structure.c.texi
453 @include texi/element.c.texi
454
455 @node DER functions
456 @section DER functions
457
458 @include texi/coding.c.texi
459 @include texi/decoding.c.texi
460
461 @node Error handling functions
462 @section Error handling functions
463
464 @include texi/errors.c.texi
465
466 @node Auxilliary functions
467 @section Auxilliary functions
468
469 @include texi/parser_aux.c.texi
470 @include texi/version.c.texi
471
472 @node Copying Information
473 @appendix Copying Information
474
475 @menu
476 * GNU Free Documentation License::   License for copying this manual.
477 @end menu
478
479 @node GNU Free Documentation License
480 @appendixsec GNU Free Documentation License
481
482 @cindex FDL, GNU Free Documentation License
483
484 @include fdl-1.3.texi
485
486 @node Concept Index
487 @unnumbered Concept Index
488
489 @printindex cp
490
491 @node Function and Data Index
492 @unnumbered Function and Data Index
493
494 @printindex fn
495
496 @bye