1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename libtasn1.info
5 @settitle GNU Libtasn1 @value{VERSION}
7 @c Unify some of the indices.
11 @comment %**end of header
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.
18 Copyright @copyright{} 2001-2014 Free Software Foundation, Inc.
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''.
30 @dircategory Software libraries
32 * libtasn1: (libtasn1). Library for Abstract Syntax Notation One (ASN.1).
37 @subtitle Abstract Syntax Notation One (ASN.1) library for the GNU system
38 @subtitle for version @value{VERSION}, @value{UPDATED}
40 @author Simon Josefsson
41 @author Nikos Mavrogiannopoulos (@email{help-libtasn1@@gnu.org})
43 @vskip 0pt plus 1filll
58 * ASN.1 structure handling::
60 * Function reference::
61 * Copying Information::
65 * Concept Index:: Index of concepts and programs.
66 * Function and Data Index:: Index of functions, variables and data types.
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
78 The main features of this library are:
82 @item On-line ASN.1 structure management that doesn't require any
83 C code file generation.
85 @item Off-line ASN.1 structure management with C code file generation
88 @item Distinguished Encoding Rules (DER) encoding support.
90 @item No limits for INTEGER and ENUMERATED values.
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.
100 No global variables are used and multiple library handles and session
101 handles may be used in parallel.
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
110 @node ASN.1 structure handling
111 @chapter ASN.1 structure handling
118 * Future developments::
122 @section ASN.1 syntax
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.
131 For an example of the syntax, check the @file{pkix.asn} file
132 distributed with the library.
134 ASN.1 definitions must follow the syntax below:
137 definitions_name {<object definition>}
139 DEFINITIONS <EXPLICIT or IMPLICIT> TAGS ::=
143 <type and constants definitions>
148 The @code{::=} token must be separate from other elements, so the
149 following declaration is invalid:
162 Here is the list of types that the parser can manage:
164 @cindex Supported ASN.1 types, list of
168 @item @code{INTEGER};
169 @item @code{ENUMERATED};
170 @item @code{BOOLEAN};
171 @item @code{OBJECT IDENTIFIER};
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};
192 @item @code{ANY DEFINED BY}.
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.
200 The @code{SIZE} constraints are allowed, but no check is done on them.
205 Consider this definition:
210 DEFINITIONS EXPLICIT TAGS ::=
215 id OBJECT IDENTIFIER,
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.
235 @item field @samp{id} of the @samp{Group} type: @samp{Example.Group.id};
237 @item field @samp{value1} of the @samp{value} field of the @samp{Group}
238 type: @samp{Example.Group.value.value1}.
242 Elements of structured types unnamed by the respective definition
243 receive the names @code{?1}, @code{?2}, and so on.
245 The @code{?LAST} name indicates the last element of a @code{SET OF} or
249 @section Simple parsing
251 For simple types like @code{OCTET STRING} the simple parsing functions listed
252 below may be used instead.
255 @item @ref{asn1_decode_simple_der}
256 @item @ref{asn1_encode_simple_der}
260 @section Library Notes
262 @cindex Header file libtasn1.h
264 The header file of this library is @file{libtasn1.h}.
266 @cindex Main type asn1_node
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).
271 The @code{NULL} constant can be used for the variable
272 initialization. For example:
275 asn1_node definitions = NULL;
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];}).
283 @code{ASN1_MAX_NAME_SIZE} is the maximum number of characters allowed
284 for an ASN.1 identifier.
286 @node Future developments
287 @section Future developments
288 @cindex Future developments
292 @item Add functions for a C code file generation containing equivalent
293 data structures (not a single array like now).
295 @item The @code{REAL} type.
303 * Invoking asn1Parser::
304 * Invoking asn1Coding::
305 * Invoking asn1Decoding::
308 @node Invoking asn1Parser
309 @section Invoking asn1Parser
310 @cindex asn1Parser program
312 @command{asn1Parser} reads a single file with ASN.1 definitions and
314 file with an array to use with libtasn1 functions.
317 Usage: asn1Parser [options] file
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.
327 @node Invoking asn1Coding
328 @section Invoking asn1Coding
329 @cindex asn1Coding program
331 @command{asn1Coding} generates a DER encoding from a file with ASN.1
332 definitions and another one with assignments.
334 The file with assignments must have this syntax:
337 InstanceName Asn1Definition
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.)
350 The output file is a binary file with the DER encoding.
353 Usage: asn1Coding [options] file1 file2
354 file1 : file with ASN1 definitions.
355 file2 : file with assignments.
357 -h : shows the help message.
358 -v : shows version information and exit.
359 -c : checks the syntax only.
360 -o file : output file.
363 For example, consider an ASN.1 definitions file as follows:
368 DEFINITIONS IMPLICIT TAGS ::=
372 Dss-Sig-Value ::= SEQUENCE {
380 And a assignments file as follows:
383 dp PKIX1.Dss-Sig-Value
389 Running the command below will generate a @file{assign.out} file,
390 containing the DER encoding of @code{PKIX1.Dss-Sig-Value}.
393 $ asn1Coding pkix.asn assign.asn1
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}):
399 elt PKIX1Implicit88.GeneralName
405 @node Invoking asn1Decoding
406 @section Invoking asn1Decoding
407 @cindex asn1Decoding program
409 @command{asn1Decoding} generates an ASN.1 structure from a file with
411 definitions and a binary file with a DER encoding.
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.
419 -h : shows the help message.
420 -v : shows version information and exit.
421 -o file : output file.
424 For example, after generating the @file{assign.out} file from the
425 example section of the @command{asn1Coding} command above, the
427 invocation will decode the DER data.
430 $ asn1Decoding pkix.asn assign.out PKIX1.Dss-Sig-Value
433 @node Function reference
434 @chapter Function reference
437 * ASN.1 schema functions::
438 * ASN.1 field functions::
440 * Error handling functions::
441 * Auxilliary functions::
444 @node ASN.1 schema functions
445 @section ASN.1 schema functions
447 @include texi/ASN1.c.texi
449 @node ASN.1 field functions
450 @section ASN.1 field functions
452 @include texi/structure.c.texi
453 @include texi/element.c.texi
456 @section DER functions
458 @include texi/coding.c.texi
459 @include texi/decoding.c.texi
461 @node Error handling functions
462 @section Error handling functions
464 @include texi/errors.c.texi
466 @node Auxilliary functions
467 @section Auxilliary functions
469 @include texi/parser_aux.c.texi
470 @include texi/version.c.texi
472 @node Copying Information
473 @appendix Copying Information
476 * GNU Free Documentation License:: License for copying this manual.
479 @node GNU Free Documentation License
480 @appendixsec GNU Free Documentation License
482 @cindex FDL, GNU Free Documentation License
484 @include fdl-1.3.texi
487 @unnumbered Concept Index
491 @node Function and Data Index
492 @unnumbered Function and Data Index