1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
\input texinfo @c -*-texinfo-*-
@comment %**start of header
@setfilename libtasn1.info
@include version.texi
@settitle GNU Libtasn1 @value{VERSION}
@c Unify some of the indices.
@syncodeindex tp fn
@syncodeindex pg fn
@comment %**end of header
@copying
This manual is for GNU Libtasn1
(version @value{VERSION}, @value{UPDATED}),
which is a library for Abstract Syntax Notation One (ASN.1) and
Distinguish Encoding Rules (DER) manipulation.
Copyright @copyright{} 2004, 2006, 2007, 2008, 2009 Free Software Foundation
Copyright @copyright{} 2001, 2002, 2003 Fabio Fiorina
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled ``GNU Free
Documentation License''.
@end quotation
@end copying
@dircategory Software libraries
@direntry
* libtasn1: (libtasn1). Library for Abstract Syntax Notation One (ASN.1).
@end direntry
@titlepage
@title Libtasn1
@subtitle Abstract Syntax Notation One (ASN.1) library for the GNU system
@subtitle for version @value{VERSION}, @value{UPDATED}
@author Fabio Fiorina
@author Simon Josefsson (@email{bug-gnutls@@gnu.org})
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top Libtasn1
@insertcopying
@end ifnottex
@menu
* Introduction::
* ASN.1 structure handling::
* Utilities::
* Function reference::
* Copying Information::
Indices
* Concept Index:: Index of concepts and programs.
* Function and Data Index:: Index of functions, variables and data types.
@end menu
@node Introduction
@chapter Introduction
This document describes the Libtasn1 library developed for ASN.1
(Abstract Syntax Notation One) structures management and DER
(Distinguished Encoding Rules) encoding functions.
The main features of this library are:
@itemize @bullet
@item On line ASN1 structure management that doesn't require any
C code file generation.
@item Off line ASN1 structure management with C code file generation
containing an array.
@item DER (Distinguish Encoding Rules) encoding.
@item No limits for INTEGER and ENUMERATED values.
@item It's Free Software.
Anybody can use, modify, and redistribute the library under the terms
of the GNU Lesser General Public License version 2.1 or later. The
command line tools, self-tests and build infrastructure are licensed
under the GNU General Public License version 3.0 or later.
@item It's thread-safe.
@cindex threads
No global variables are used and multiple library handles and session
handles may be used in parallel.
@item It's portable.
@cindex Porting
It should work on all Unix like operating systems, including Windows.
The library itself should be portable to any C89 system, not even
POSIX is required.
@end itemize
@node ASN.1 structure handling
@chapter ASN.1 structure handling
@menu
* ASN.1 syntax::
* Naming::
* Library Notes::
* Future developments::
@end menu
@node ASN.1 syntax
@section ASN.1 syntax
@cindex ASN.1 schema
The parser is case sensitive. The comments begin with "-- " and end at
the end of lines. An example is in "pkix.asn" file. ASN.1
definitions must have this syntax:
@verbatim
definitions_name {<object definition>}
DEFINITIONS <EXPLICIT or IMPLICIT> TAGS ::=
BEGIN
<type and constants definitions>
END
@end verbatim
The token "::=" must be separate from others elements, so this is a
wrong declaration:
@example
;; INCORRECT
Version ::=INTEGER
@end example
the correct form is:
@example
Version ::= INTEGER
@end example
Here is the list of types that the parser can manage:
@cindex Supported ASN.1 types, list of
@itemize @bullet
@item INTEGER
@item ENUMERATED
@item BOOLEAN
@item OBJECT IDENTIFIER
@item NULL
@item BIT STRING
@item OCTET STRING
@item UTCTime
@item GeneralizedTime
@item GeneralString
@item SEQUENCE
@item SEQUENCE OF
@item SET
@item SET OF
@item CHOICE
@item ANY
@item ANY DEFINED BY
@end itemize
This version doesn't manage REAL type. It doesn't allow the "EXPORT"
and "IMPORT" sections too.
The SIZE constraints are allowed, but no check is done on them.
@node Naming
@section Naming
Consider this definition:
@verbatim
Example { 1 2 3 4 }
DEFINITIONS EXPLICIT TAGS ::=
BEGIN
Group ::= SEQUENCE {
id OBJECT IDENTIFIER,
value Value
}
Value ::= SEQUENCE {
value1 INTEGER,
value2 BOOLEAN
}
END
@end verbatim
To identify the type 'Group' you have to use the null terminated
string "Example.Group". These strings are used in functions that are
described below.
Others examples:
Field 'id' in 'Group' type : "Example.Group.id".
Field 'value1' in field 'value' in type 'Group':
"Example.Group.value.value1".
Elements of structured types that don't have a name, receive the name
"?1","?2", and so on.
The name "?LAST" indicates the last element of a @code{SET_OF} or
@code{SEQUENCE_OF}.
@node Library Notes
@section Library Notes
@cindex Header file libtasn1.h
The header file of this library is @file{libtasn1.h}.
@cindex Main type ASN1_TYPE
The main type used in it is @code{ASN1_TYPE}, and it's used to store
the @acronym{ASN.1} definitions and structures (instances).
The constant @acronym{ASN1_TYPE_EMPTY} can be used for the variable
initialization. For example:
@example
ASN1_TYPE definitions=ASN1_TYPE_EMPTY;
@end example
Some functions require a parameter named errorDescription of char*
type. The array must be already allocated and must have at least
@code{ASN1_MAX_ERROR_DESCRIPTION_SIZE} bytes (E.g, as in @code{char
Description[ASN1_MAX_ERROR_DESCRIPTION_SIZE];}).
@code{ASN1_MAX_NAME_SIZE} indicates the maximum number of characters of a
name inside a file with ASN1 definitions.
@node Future developments
@section Future developments
@cindex Future developments
@itemize @bullet
@item Add functions for a C code file generation containing equivalent
data structures (not a single array like now).
@item Type REAL.
@end itemize
@node Utilities
@chapter Utilities
@menu
* Invoking asn1Parser::
* Invoking asn1Coding::
* Invoking asn1Decoding::
@end menu
@node Invoking asn1Parser
@section Invoking asn1Parser
@cindex asn1Parser program
@file{asn1Parser} reads one file with ASN1 definitions and generates a
file with an array to use with libtasn1 functions.
@verbatim
Usage: asn1Parser [options] file
Options:
-h : shows the help message.
-v : shows version information and exit.
-c : checks the syntax only.
-o file : output file.
-n name : array name.
@end verbatim
@node Invoking asn1Coding
@section Invoking asn1Coding
@cindex asn1Coding program
@file{asn1Coding} generates a DER encoding from a file with ASN1
definitions and another one with assignments.
The file with assignments must have this syntax:
@verbatim
InstanceName Asn1Definition
nameString value
nameString value
...
@end verbatim
The output file is a binary file with the DER encoding.
@verbatim
Usage: asn1Coding [options] file1 file2
file1 : file with ASN1 definitions.
file2 : file with assignments.
Options:
-h : shows the help message.
-v : shows version information and exit.
-c : checks the syntax only.
-o file : output file.
@end verbatim
@node Invoking asn1Decoding
@section Invoking asn1Decoding
@cindex asn1Decoding program
@file{asn1Decoding} generates an ASN1 structure from a file with ASN1
definitions and a binary file with a DER encoding.
@verbatim
Usage: asn1Decoding [options] file1 file2 type
file1 : file with ASN1 definitions.
file2 : binary file with a DER encoding.
type : ASN1 definition name.
Options:
-h : shows the help message.
-v : shows version information and exit.
-c : checks the syntax only.
-o file : output file.
@end verbatim
@node Function reference
@chapter Function reference
@menu
* ASN.1 schema functions::
* ASN.1 field functions::
* DER functions::
* Error handling functions::
* Auxilliary functions::
@end menu
@node ASN.1 schema functions
@section ASN.1 schema functions
@include texi/ASN1.c.texi
@node ASN.1 field functions
@section ASN.1 field functions
@include texi/structure.c.texi
@include texi/element.c.texi
@node DER functions
@section DER functions
@include texi/coding.c.texi
@include texi/decoding.c.texi
@node Error handling functions
@section Error handling functions
@include texi/errors.c.texi
@node Auxilliary functions
@section Auxilliary functions
@include texi/parser_aux.c.texi
@node Copying Information
@appendix Copying Information
@menu
* GNU Free Documentation License:: License for copying this manual.
@end menu
@node GNU Free Documentation License
@appendixsec GNU Free Documentation License
@cindex FDL, GNU Free Documentation License
@include fdl-1.3.texi
@node Concept Index
@unnumbered Concept Index
@printindex cp
@node Function and Data Index
@unnumbered Function and Data Index
@printindex fn
@bye
|