Added support for user specified SilcStack.
[silc.git] / lib / silcasn1 / silcasn1.h
1 /*
2
3   silcasn1.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 - 2007 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcasn1/ASN.1 Interface
21  *
22  * DESCRIPTION
23  *
24  * Efficient Abstract Syntax Notation One (ASN.1) implementation.  This
25  * interface provides simple and efficient ASN.1 encoder and decoder.
26  * The encoder directly encodes BER encoded data blocks from variable
27  * argument list of ASN.1 types.  Multiple trees can be encoded at once
28  * and multiple nodes can be encoded into the tree at once.  By default
29  * encoder does not allocate any memory during encoding but a pre-allocated
30  * SilcStack is used as memory.
31  *
32  * The decoder directly decodes BER encoded data blocks into the correct
33  * types dictated by the variable argument list of ASN.1 types.  By
34  * default decoder does not allocate any memory during decoding but a
35  * pre-allocated SilcStack is used as memory.
36  *
37  * The encoding and decoding interface is simple.  silc_asn1_encode is used
38  * to encode and silc_asn1_decode to decode.  The actual ASN.1 is defined
39  * as variable argument list to the function.  Various macros can be used
40  * to encode and decode different ASN.1 types.  All types may also be used
41  * to encode and decode with various options (such as implicit and explicit
42  * tagging and defining specific class option).
43  *
44  * The implementation supports all the common ASN.1 types.  This
45  * implementation does not support advanced ASN.1 features like macros.
46  *
47  * References: ITU-T X.680 - X.693
48  * http://www.itu.int/ITU-T/studygroups/com17/languages/
49  *
50  ***/
51
52 #ifndef SILCASN1_H
53 #define SILCASN1_H
54
55 /****s* silcasn1/SilcASN1API/SilcAsn1
56  *
57  * NAME
58  *
59  *    typedef struct SilcAsn1Object *SilcAsn1;
60  *
61  * DESCRIPTION
62  *
63  *    This context is the actual ASN.1 encoder/decoder and is allocated
64  *    by silc_asn1_alloc and given as argument to all silc_asn1_*
65  *    functions.  It is freed by the silc_asn1_free function.  It is
66  *    also possible to use pre-allocated ASN.1 context by using the
67  *    SilcAsn1Struct instead of SilcAsn1.
68  *
69  ***/
70 typedef struct SilcAsn1Object *SilcAsn1;
71
72 /****s* silcasn1/SilcASN1API/SilcAsn1Struct
73  *
74  * NAME
75  *
76  *    typedef struct SilcAsn1Object SilcAsn1Struct;
77  *
78  * DESCRIPTION
79  *
80  *    This context is the actual ASN.1 encoder/decoder and can be
81  *    used as pre-allocated ASN.1 context instead of SilcAsn1 context.
82  *    This context is initialized with silc_asn1_init and uninitialized
83  *    with silc_asn1_uninit.
84  *
85  ***/
86 typedef struct SilcAsn1Object SilcAsn1Struct;
87
88 /****d* silcasn1/SilcASN1API/SilcAsn1Options
89  *
90  * NAME
91  *
92  *    typedef enum { ... } SilcAsn1Options;
93  *
94  * DESCRIPTION
95  *
96  *    Options for ASN.1 encoder and decoder.  The ASN.1 options can be
97  *    given to the SILC_ASN1_*_T macros and/or SILC_ASN1_OPTS macro.
98  *
99  * NOTES
100  *
101  *    The SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags can be given only
102  *    with SILC_ASN1_OPTS macro.  Other options can be given with various
103  *    SILC_ASN1_*_T macros.
104  *
105  * EXAMPLE
106  *
107  *    // Encodes boolean value with explicit tag and private class, and
108  *    // the result is allocated into `dest'.
109  *    silc_asn1_encode(asn1, &dest,
110  *                     SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
111  *                     SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE |
112  *                                         SILC_ASN1_EXPLICIT, 100, boolval),
113  *                     SILC_ASN1_END);
114  *
115  * SOURCE
116  */
117 typedef enum {
118   /* Default. If only this is set then defaults are implied. */
119   SILC_ASN1_DEFAULT      = 0x0000,
120
121   /* Class options.  User does not need to set these unless specificly
122      wanted to do so.  If SILC_ASN1_DEFAULT is set the SILC_ASN1_CONTEXT is
123      implied if any of the tag options are set.  Otherwise SILC_ASN1_UNIVERSAL
124      is implied. Only one of these can bet set at once. */
125   SILC_ASN1_UNIVERSAL    = 0x0001,       /* Universal class (default) */
126   SILC_ASN1_APP          = 0x0002,       /* Application specific class */
127   SILC_ASN1_CONTEXT      = 0x0003,       /* Context specific class */
128   SILC_ASN1_PRIVATE      = 0x0004,       /* Private class */
129
130   /* Tag options (bitmask) */
131   SILC_ASN1_IMPLICIT     = 0x0010,       /* Tag is implicit (default) */
132   SILC_ASN1_EXPLICIT     = 0x0020,       /* Tag is explicit */
133   SILC_ASN1_DEFINITE     = 0x0040,       /* Length is definite (default) */
134   SILC_ASN1_INDEFINITE   = 0x0080,       /* Length is indefinite */
135
136   /* Decoding options (bitmask) */
137   SILC_ASN1_OPTIONAL     = 0x0100,       /* Zero or more may be found.  The
138                                             argument must be pointer to the
139                                             type pointer so that NULL can be
140                                             returned if type is not found. */
141
142   /* ASN.1 encoder/decoder options (bitmask).  These can be given
143      only with SILC_ASN1_OPTS macro at the start of encoding/decoding. */
144   SILC_ASN1_ALLOC        = 0x0400,       /* Dynamically allocate results */
145   SILC_ASN1_ACCUMUL      = 0x0800,       /* Accumulate memory for results,
146                                             next call to silc_asn1_decode
147                                             will not cancel old results. */
148 } SilcAsn1Options;
149 /***/
150
151 /****d* silcasn1/SilcASN1API/SilcAsn1Tag
152  *
153  * NAME
154  *
155  *    typedef enum { ... } SilcAsn1Tag;
156  *
157  * DESCRIPTION
158  *
159  *    Universal ASN.1 tags.  Usually these tags are given automatically
160  *    to the silc_asn1_encode and silc_asn1_decode by using the various
161  *    macros (such as SILC_ASN1_BOOLEAN).  Some macros may take the tag
162  *    as additional argument.
163  *
164  * SOURCE
165  */
166 typedef enum {
167   SILC_ASN1_TAG_BOOLEAN               = 1,  /* SILC_ASN1_BOOLEAN */
168   SILC_ASN1_TAG_INTEGER               = 2,  /* SILC_ASN1_INT */
169   SILC_ASN1_TAG_BIT_STRING            = 3,  /* SILC_ASN1_BIT_STRING */
170   SILC_ASN1_TAG_OCTET_STRING          = 4,  /* SILC_ASN1_OCTET_STRING */
171   SILC_ASN1_TAG_NULL                  = 5,  /* SILC_ASN1_NULL */
172   SILC_ASN1_TAG_OID                   = 6,  /* SILC_ASN1_OID */
173   SILC_ASN1_TAG_ODE                   = 7,  /* not supported */
174   SILC_ASN1_TAG_ETI                   = 8,  /* not supported */
175   SILC_ASN1_TAG_REAL                  = 9,  /* not supported */
176   SILC_ASN1_TAG_ENUM                  = 10, /* SILC_ASN1_ENUM */
177   SILC_ASN1_TAG_EMBEDDED              = 11, /* not supported */
178   SILC_ASN1_TAG_UTF8_STRING           = 12, /* SILC_ASN1_UTF8_STRING */
179   SILC_ASN1_TAG_ROI                   = 13, /* not supported */
180   SILC_ASN1_TAG_SEQUENCE              = 16, /* SILC_ASN1_SEQUENCE */
181   SILC_ASN1_TAG_SET                   = 17, /* SILC_ASN1_SET */
182   SILC_ASN1_TAG_NUMERIC_STRING        = 18, /* SILC_ASN1_NUMERIC_STRING */
183   SILC_ASN1_TAG_PRINTABLE_STRING      = 19, /* SILC_ASN1_PRINTABLE_STRING */
184   SILC_ASN1_TAG_TELETEX_STRING        = 20, /* SILC_ASN1_TELETEX_STRING */
185   SILC_ASN1_TAG_VIDEOTEX_STRING       = 21, /* not supported */
186   SILC_ASN1_TAG_IA5_STRING            = 22, /* SILC_ASN1_IA5_STRING */
187   SILC_ASN1_TAG_UTC_TIME              = 23, /* SILC_ASN1_UTC_TIME */
188   SILC_ASN1_TAG_GENERALIZED_TIME      = 24, /* SILC_ASN1_GENERAL_STRING */
189   SILC_ASN1_TAG_GRAPHIC_STRING        = 25, /* not supported */
190   SILC_ASN1_TAG_VISIBLE_STRING        = 26, /* SILC_ASN1_VISIBLE_STRING */
191   SILC_ASN1_TAG_GENERAL_STRING        = 27, /* SILC_ASN1_GENERAL_STRING */
192   SILC_ASN1_TAG_UNIVERSAL_STRING      = 28, /* SILC_ASN1_UNIVERSAL_STRING */
193   SILC_ASN1_TAG_UNRESTRICTED_STRING   = 29, /* SILC_ASN1_UNRESTRICTED_STRING */
194   SILC_ASN1_TAG_BMP_STRING            = 30, /* SILC_ASN1_BMP_STRING */
195 } SilcAsn1Tag;
196 /***/
197
198 #include "silcasn1_i.h"
199
200 /****f* silcasn1/SilcASN1API/silc_asn1_alloc
201  *
202  * SYNOPSIS
203  *
204  *    SilcAsn1 silc_asn1_alloc(SilcStack stack);
205  *
206  * DESCRIPTION
207  *
208  *    Allocates and initializes ASN.1 encoder/decoder and returns SilcAsn1
209  *    context or NULL on error.  This context can be used with both
210  *    silc_asn1_encode and silc_asn1_decode functions.  If `stack' is non-NULL
211  *    all memory will be allocated from `stack'.
212  *
213  *    Usually SilcAsn1 is allocated when encoder or decoder is needed,
214  *    however it is also possible to allocate long-lasting SilcAsn1 and
215  *    use that every time ASN.1 routines are needed.  Application could
216  *    for example allocate one SilcAsn1 and use that for all ASN.1 encoding
217  *    and decoding.
218  *
219  *    When this context is freed with silc_asn1_free all memory will be
220  *    freed, and all encoded ASN.1 buffers becomes invalid.  Also all
221  *    data that is returned by silc_asn1_decode function becomes invalid.
222  *
223  ***/
224 SilcAsn1 silc_asn1_alloc(SilcStack stack);
225
226 /****f* silcasn1/SilcASN1API/silc_asn1_free
227  *
228  * SYNOPSIS
229  *
230  *    void silc_asn1_free(SilcAsn1 asn1);
231  *
232  * DESCRIPTION
233  *
234  *    Frees the SilcAsn1 context and all allocated memory.  All encoded
235  *    buffers and all decoded buffers with this context becomes invalid
236  *    after this call.
237  *
238  ***/
239 void silc_asn1_free(SilcAsn1 asn1);
240
241 /****f* silcasn1/SilcASN1API/silc_asn1_init
242  *
243  * SYNOPSIS
244  *
245  *    SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack);
246  *
247  * DESCRIPTION
248  *
249  *    Initializes a pre-allocated SilcAsn1 context.  This call is
250  *    equivalent to silc_asn1_alloc except that this takes the pre-allocated
251  *    context as argument.
252  *
253  * EXAMPLE
254  *
255  *    SilcAsn1Struct asn1;
256  *    if (!silc_asn1_init(&asn1, NULL))
257  *      error;
258  *
259  ***/
260 SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack);
261
262 /****f* silcasn1/SilcASN1API/silc_asn1_uninit
263  *
264  * SYNOPSIS
265  *
266  *    void silc_asn1_uninit(SilcAsn1 asn1);
267  *
268  * DESCRIPTION
269  *
270  *    Uninitializes a pre-allocated SilcAsn1 context.  Use this function
271  *    instead of silc_asn1_free if you used silc_asn1_init.
272  *
273  ***/
274 void silc_asn1_uninit(SilcAsn1 asn1);
275
276 /****f* silcasn1/SilcASN1API/silc_asn1_encode
277  *
278  * SYNOPSIS
279  *
280  *    SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
281  *
282  * DESCRIPTION
283  *
284  *    Encodes ASN.1 encoded buffer into `dest', from variable argument
285  *    list of ASN.1 types.  The variable argument list forms the ASN.1
286  *    trees and nodes that are encoded into the `dest'.  By default, the
287  *    memory for `dest' is allocated from the `asn1', and the buffer becomes
288  *    invalid either by calling silc_asn1_free, silc_asn1_uninit, or when
289  *    silc_asn1_encode is called for the next time.
290  *
291  *    If the SILC_ASN1_OPTS macro with SILC_ASN1_ALLOC option is given then
292  *    the `dest' is dynamically allocated and caller must free it by itself.
293  *    Alternatively if SILC_ASN1_ACCUMUL is given then memory is accumulated
294  *    from `asn1' for `dest' and it is freed only when silc_asn1_free or
295  *    silc_asn1_uninit is called.  Next call to silc_asn1_encode will not
296  *    cancel the previous result, but will accumulate more memory for new
297  *    result.
298  *
299  *    The variable argument list is constructed by using various
300  *    macros, for example SILC_ASN1_SEQUENCE, etc.  The variable argument
301  *    list must always be ended with SILC_ASN1_END type.
302  *
303  *    If encoding is successful this returns TRUE, FALSE on error.
304  *
305  * EXAMPLE
306  *
307  *    silc_asn1_encode(asn1, buf,
308  *                     SILC_ASN1_SEQUENCE,
309  *                       SILC_ASN1_BOOLEAN(bool_val),
310  *                       SILC_ASN1_OCTET_STRING(string, string_len),
311  *                       SILC_ASN1_SEQUENCE_T(0, 2),
312  *                         SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 100, foo),
313  *                       SILC_ASN1_END,
314  *                       SILC_ASN1_OCTET_STRING_T(0, 1, string2, string2_len),
315  *                     SILC_ASN1_END, SILC_ASN1_END);
316  *
317  *    Creates ASN.1 tree that looks something like:
318  *
319  *    buf ::= SEQUENCE {
320  *      bool_val      BOOLEAN,
321  *      string        OCTET-STRING,
322  *               [2]  SEQUENCE {
323  *                      foo   [100] EXPLICIT BOOLEAN }
324  *      string2  [1]  OCTET-STRING }
325  *
326  ***/
327 SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
328
329 /****f* silcasn1/SilcASN1API/silc_asn1_decode
330  *
331  * SYNOPSIS
332  *
333  *    SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
334  *
335  * DESCRIPTION
336  *
337  *    Decodes the ASN.1 encoded buffer `src' by the ASN.1 types sent
338  *    as argument.  The ASN.1 types sent as argument must be found from
339  *    the `src' for this function to decode successfully.
340  *
341  *    The memory allocated for the results are allocated from `asn1' and
342  *    they become invalid if `asn1' becomes invalid.  Next (second) call
343  *    to this function does NOT invalidate the previous results.  However,
344  *    third call to this function does invalidate the results of the first
345  *    call but not second.  On the other hand, fourth call invalidates
346  *    the results of the second call but not third, fifth call invalidates
347  *    the results of the third call but not fourth, and so on.  This allows
348  *    efficient decoding, when silc_asn1_decode must be called multiple times
349  *    to decode all data, without new memory allocations.  However, caller
350  *    must be cautios and understand that the every second call invalidates
351  *    the results of every second previous results.
352  *
353  *    If the SILC_ASN1_OPTS macro with SILC_ASN1_ALLOC option is given then
354  *    all results are dynamically allocated and caller must free them by
355  *    itself. Alternatively if SILC_ASN1_ACCUMUL is given then memory is
356  *    accumulated from `asn1' for results and they are freed only when the
357  *    silc_asn1_free or silc_asn1_uninit is called.  Next calls to the
358  *    silc_asn1_decode will NOT invalidate the old results, but will
359  *    accumulate more memory for new results.  If the SILC_ASN1_OPTS is not
360  *    given at all then the default allocation method (decribed above)
361  *    applies.
362  *
363  *    If caller needs to store the results even after `asn1' becomes invalid
364  *    then call must either use SILC_ASN1_ALLOC option or duplicate the
365  *    results by itself.
366  *
367  * EXAMPLE
368  *
369  *    SilcBool bool_val, foo;
370  *    unsigned char *string, string2;
371  *    SilcUInt32 string_len, string2_len;
372  *
373  *    silc_asn1_decode(asn1, tree,
374  *                     SILC_ASN1_SEQUENCE,
375  *                       SILC_ASN1_BOOLEAN(&bool_val),
376  *                       SILC_ASN1_OCTET_STRING(&string, &string_len),
377  *                       SILC_ASN1_SEQUENCE_T(0, 2),
378  *                         SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 100, &foo),
379  *                       SILC_ASN1_END,
380  *                       SILC_ASN1_OCTET_STRING_T(0, 1, &str2, &str2_len),
381  *                     SILC_ASN1_END, SILC_ASN1_END);
382  *
383  ***/
384 SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
385
386 /****f* silcasn1/SilcASN1API/SILC_ASN1_OPTS
387  *
388  * SYNOPSIS
389  *
390  *    SILC_ASN1_OPTS(opts)
391  *
392  * DESCRIPTION
393  *
394  *    The `opts' is SilcAsn1Options.  This macro can be used to set
395  *    options for silc_asn1_encode and silc_asn1_decode functions.
396  *
397  * NOTES
398  *
399  *    Only the SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags may be
400  *    set with this macro.
401  *
402  *    This macro must be the first macro in the variable argument list
403  *    in the function.
404  *
405  * EXAMPLE
406  *
407  *    silc_asn1_decode(asn1, tree,
408  *                     SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
409  *                     SILC_ASN1_SEQUENCE,
410  *                       SILC_ASN1_BOOLEAN(&bool_val),
411  *                       SILC_ASN1_OCTET_STRING(&string, &string_len),
412  *                     SILC_ASN1_END, SILC_ASN1_END);
413  *
414  ***/
415 #define SILC_ASN1_OPTS(opts) SILC_ASN1_TAG_OPTS, (opts)
416
417 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY
418  *
419  * SYNOPSIS
420  *
421  *    Encoding:
422  *    SILC_ASN1_ANY(buffer)
423  *    SILC_ASN1_ANY_T(opts, tag, buffer)
424  *
425  *    Decoding:
426  *    SILC_ASN1_ANY(&buffer)
427  *    SILC_ASN1_ANY_T(opts, tag, buffer)
428  *
429  * DESCRIPTION
430  *
431  *    Macro used to encode or decode another ASN.1 node.  The buffer type
432  *    is SilcBuffer.  This macro can be used for example to split large
433  *    tree into multiple nodes, and then decoding the nodes separately from
434  *    the buffers.
435  *
436  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
437  *
438  * EXAMPLE
439  *
440  *    // Encode node of two boolean values
441  *    silc_asn1_encode(asn1, node,
442  *                     SILC_ASN1_BOOLEAN(val1),
443  *                     SILC_ASN1_BOOLEAN(val2),
444  *                     SILC_ASN1_END);
445  *
446  *    // Encode tree with the node
447  *    silc_asn1_encode(asn1, tree,
448  *                     SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
449  *                       SILC_ASN1_ANY(node),
450  *                       SILC_ASN1_BOOLEAN(boolval),
451  *                     SILC_ASN1_END, SILC_ASN1_END);
452  *
453  ***/
454 #define SILC_ASN1_ANY(x) SILC_ASN1_U1(ANY, x)
455 #define SILC_ASN1_ANY_T(o, t, x) SILC_ASN1_T1(ANY, o, t, x)
456
457 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY_PRIMITIVE
458  *
459  * SYNOPSIS
460  *
461  *    Encoding:
462  *    SILC_ASN1_ANY_PRIMITIVE(tag, buffer)
463  *    SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
464  *
465  *    Decoding:
466  *    SILC_ASN1_ANY_PRIMITIVE(tag, &buffer)
467  *    SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
468  *
469  * DESCRIPTION
470  *
471  *    Special macro used to encode pre-encoded primitive data blob.  The data
472  *    can be any primitive type that is already encoded in correct format.
473  *    The caller is responsible of making sure the data is formatted
474  *    correctly.  When decoding this returns the raw data blob and the caller
475  *    must know of what type and format it is.  The buffer type is SilcBuffer.
476  *
477  *    This macro can be used in cases when the data to be encoded is already
478  *    in encoded format, and it only needs to be added to ASN.1 tree.  The
479  *    SILC_ASN1_ANY cannot be used with primitives when tagging implicitly,
480  *    in these cases this macro can be used.
481  *
482  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
483  *
484  * EXAMPLE
485  *
486  *    // Get MP integer in encoded format
487  *    mpbuf = mp_get_octet_string(mp);
488  *
489  *    // Encode the MP integer data to the tree
490  *    silc_asn1_encode(asn1, tree,
491  *                     SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_INTEGER, mpbuf),
492  *                     SILC_ASN1_END);
493  *
494  *    // Decode the MP integer data from the tree
495  *    silc_asn1_decode(asn1, tree,
496  *                     SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_INTEGER, &buffer),
497  *                     SILC_ASN1_END);
498  *
499  ***/
500 #define SILC_ASN1_ANY_PRIMITIVE(t, x) SILC_ASN1_T1(ANY_PRIMITIVE, 0, t, x)
501 #define SILC_ASN1_ANY_PRIMITIVE_T(o, t, x) SILC_ASN1_T1(ANY_PRIMITIVE, o, t, x)
502
503 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE
504  *
505  * SYNOPSIS
506  *
507  *    Encoding:
508  *    SILC_ASN1_SEQUENCE
509  *    SILC_ASN1_SEQUENCE_T(opts, tag)
510  *
511  *    Decoding:
512  *    SILC_ASN1_SEQUENCE
513  *    SILC_ASN1_SEQUENCE_T(opts, tag)
514  *
515  * DESCRIPTION
516  *
517  *    Macro used to encode or decode sequence.  The sequence must be
518  *    terminated with SILC_ASN1_END.
519  *
520  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
521  *
522  * EXAMPLE
523  *
524  *    silc_asn1_encode(asn1, tree,
525  *                     SILC_ASN1_SEQUENCE,
526  *                       SILC_ASN1_ANY(node),
527  *                       SILC_ASN1_BOOLEAN(boolval),
528  *                     SILC_ASN1_END, SILC_ASN1_END);
529  *
530  ***/
531 #define SILC_ASN1_SEQUENCE SILC_ASN1_U0(SEQUENCE)
532 #define SILC_ASN1_SEQUENCE_T(o, t) SILC_ASN1_T0(SEQUENCE, o, t)
533
534 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET
535  *
536  * SYNOPSIS
537  *
538  *    Encoding:
539  *    SILC_ASN1_SET
540  *    SILC_ASN1_SET_T(opts, tag)
541  *
542  *    Decoding:
543  *    SILC_ASN1_SET
544  *    SILC_ASN1_SET_T(opts, tag)
545  *
546  * DESCRIPTION
547  *
548  *    Macro used to encode or decode set.  The set must be terminated
549  *    with SILC_ASN1_END.
550  *
551  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
552  *
553  * EXAMPLE
554  *
555  *    silc_asn1_encode(asn1, tree,
556  *                     SILC_ASN1_SET_T(SILC_ASN1_EXPLICIT, 0),
557  *                       SILC_ASN1_BOOLEAN(boolval),
558  *                     SILC_ASN1_END, SILC_ASN1_END);
559  *
560  ***/
561 #define SILC_ASN1_SET SILC_ASN1_U0(SET)
562 #define SILC_ASN1_SET_T(o, t) SILC_ASN1_T0(SET, o, t)
563
564 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE_OF
565  *
566  * SYNOPSIS
567  *
568  *    Decoding:
569  *    SILC_ASN1_SEQUENCE_OF(bufarray, numbufs)
570  *
571  * DESCRIPTION
572  *
573  *    Macro used to decode sequence of specified type.  This returns
574  *    an array of SilcBuffers and number of buffers in the array.  The
575  *    SILC_ASN1_CHOICE macro may also be used with this macro.
576  *
577  * NOTES
578  *
579  *    This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
580  *    flags.  Do not use this macro without flags.
581  *
582  * EXAMPLE
583  *
584  *     SilcBuffer bufs;
585  *     SilcUInt32 count;
586  *
587  *     // Decode sequence of sequences.  Each returned buffer in the array
588  *     // is a sequence.
589  *     silc_asn1_decode(asn1, exts,
590  *                      SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
591  *                      SILC_ASN1_SEQUENCE_OF(&bufs, &count),
592  *                        SILC_ASN1_TAG_SEQUENCE,
593  *                      SILC_ASN1_END, SILC_ASN1_END);
594  *
595  ***/
596 #define SILC_ASN1_SEQUENCE_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
597
598 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET_OF
599  *
600  * SYNOPSIS
601  *
602  *    Decoding:
603  *    SILC_ASN1_SET_OF(bufarray, numbufs)
604  *
605  * DESCRIPTION
606  *
607  *    Macro used to decode set of specified type.  This returns
608  *    an array of SilcBuffers and number of buffers in the array.  The
609  *    SILC_ASN1_CHOICE macro may also be used with this macro.
610  *
611  * NOTES
612  *
613  *    This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
614  *    flags.  Do not use this macro without flags.
615  *
616  * EXAMPLE
617  *
618  *     // Decode set of sequences.  Each returned buffer in the array
619  *     // is a sequence.
620  *     silc_asn1_decode(asn1, exts,
621  *                      SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
622  *                      SILC_ASN1_SET_OF(&bufs, &count),
623  *                        SILC_ASN1_TAG_SEQUENCE,
624  *                      SILC_ASN1_END, SILC_ASN1_END);
625  *
626  ***/
627 #define SILC_ASN1_SET_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
628
629 /****f* silcasn1/SilcASN1API/SILC_ASN1_CHOICE
630  *
631  * SYNOPSIS
632  *
633  *    Decoding:
634  *    SILC_ASN1_CHOICE
635  *
636  * DESCRIPTION
637  *
638  *    Macro used to specify choices in decoding.  The choice list must
639  *    be terminated with SILC_ASN1_END.  There is no limit how many choices
640  *    can be specified in the list.
641  *
642  * EXAMPLE
643  *
644  *    // Decode timeval that is either UTC or generalized time
645  *    silc_asn1_decode(asn1, tree,
646  *                     SILC_ASN1_SEQUENCE,
647  *                       SILC_ASN1_CHOICE,
648  *                         SILC_ASN1_UTC_TIME(&timeval),
649  *                         SILC_ASN1_GEN_TIME(&timeval),
650  *                       SILC_ASN1_END,
651  *                     SILC_ASN1_END, SILC_ASN1_END);
652  *
653  ***/
654 #define SILC_ASN1_CHOICE SILC_ASN1_U0(CHOICE)
655
656 /****f* silcasn1/SilcASN1API/SILC_ASN1_BOOLEAN
657  *
658  * SYNOPSIS
659  *
660  *    Encoding:
661  *    SILC_ASN1_BOOLEAN(boolval)
662  *    SILC_ASN1_BOOLEAN_T(opts, tag, boolval)
663  *
664  *    Decoding:
665  *    SILC_ASN1_BOOLEAN(&boolval)
666  *    SILC_ASN1_BOOLEAN_T(opts, tag, &boolval)
667  *
668  * DESCRIPTION
669  *
670  *    Macro used to encode or decode boolean value.  The boolean type
671  *    is SilcBool.
672  *
673  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
674  *
675  ***/
676 #define SILC_ASN1_BOOLEAN(x) SILC_ASN1_U1(BOOLEAN, x)
677 #define SILC_ASN1_BOOLEAN_T(o, t, x) SILC_ASN1_T1(BOOLEAN, o, t, x)
678
679 /****f* silcasn1/SilcASN1API/SILC_ASN1_INT
680  *
681  * SYNOPSIS
682  *
683  *    Encoding:
684  *    SILC_ASN1_INT(integer)
685  *    SILC_ASN1_INT_T(opts, tag, &integer)
686  *
687  *    Decoding:
688  *    SILC_ASN1_INT(&integer)
689  *    SILC_ASN1_INT_T(opts, tag, &integer);
690  *
691  * DESCRIPTION
692  *
693  *    Macro used to encode or decode multiple precision integer.  The
694  *    integer type is SilcMPInt.
695  *
696  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
697  *
698  ***/
699 #define SILC_ASN1_INT(x) SILC_ASN1_U1(INTEGER, x)
700 #define SILC_ASN1_INT_T(o, t, x) SILC_ASN1_T1(INTEGER, o, t, x)
701
702 /****f* silcasn1/SilcASN1API/SILC_ASN1_SHORT_INT
703  *
704  * SYNOPSIS
705  *
706  *    Encoding:
707  *    SILC_ASN1_SHORT_INT(integer)
708  *    SILC_ASN1_SHORT_INT_T(opts, tag, &integer)
709  *
710  *    Decoding:
711  *    SILC_ASN1_SHORT_INT(&integer)
712  *    SILC_ASN1_SHORT_INT_T(opts, tag, &integer);
713  *
714  * DESCRIPTION
715  *
716  *    Macro used to encode or decode short integer (32 bits).  The
717  *    integer type is SilcUInt32.
718  *
719  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
720  *
721  ***/
722 #define SILC_ASN1_SHORT_INT(x) SILC_ASN1_U1(SHORT_INTEGER, x)
723 #define SILC_ASN1_SHORT_INT_T(o, t, x) SILC_ASN1_T1(SHORT_INTEGER, o, t, x)
724
725 /****f* silcasn1/SilcASN1API/SILC_ASN1_ENUM
726  *
727  * SYNOPSIS
728  *
729  *    Encoding:
730  *    SILC_ASN1_ENUM(enum)
731  *    SILC_ASN1_ENUM_T(opts, tag, &enum)
732  *
733  *    Decoding:
734  *    SILC_ASN1_ENUM(&enum)
735  *    SILC_ASN1_ENUM_T(opts, tag, &enum);
736  *
737  * DESCRIPTION
738  *
739  *    Macro used to encode or decode enumeration value.  The enumeration
740  *    type is SilcMPInt.
741  *
742  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
743  *
744  ***/
745 #define SILC_ASN1_ENUM(x) SILC_ASN1_U1(ENUM, x)
746 #define SILC_ASN1_ENUM_T(o, t, x) SILC_ASN1_T1(ENUM, o, t, x)
747
748 /****f* silcasn1/SilcASN1API/SILC_ASN1_BIT_STRING
749  *
750  * SYNOPSIS
751  *
752  *    Encoding:
753  *    SILC_ASN1_BIT_STRING(str, str_len)
754  *    SILC_ASN1_BIT_STRING_T(opts, tag, str, str_len)
755  *
756  *    Decoding:
757  *    SILC_ASN1_BIT_STRING(&str, &str_len)
758  *    SILC_ASN1_BIT_STRING_T(opts, tag, &str, &str_len)
759  *
760  * DESCRIPTION
761  *
762  *    Macro used to encode or decode bit string.  The string length in
763  *    encoding must be in bits (bytes * 8).  The decoded length is in
764  *    bits as well.  The string type is unsigned char and string length
765  *    SilcUInt32.
766  *
767  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
768  *
769  ***/
770 #define SILC_ASN1_BIT_STRING(x, xl) SILC_ASN1_U2(BIT_STRING, x, xl)
771 #define SILC_ASN1_BIT_STRING_T(o, t, x, xl) SILC_ASN1_T2(BIT_STRING, o, t, x, xl)
772
773 /****f* silcasn1/SilcASN1API/SILC_ASN1_NULL
774  *
775  * SYNOPSIS
776  *
777  *    Encoding:
778  *    SILC_ASN1_NULL
779  *    SILC_ASN1_NULL_T(opts, tag)
780  *
781  *    Decoding:
782  *    SILC_ASN1_NULL
783  *    SILC_ASN1_NULL_T(opts, tag)
784  *
785  * DESCRIPTION
786  *
787  *    Macro used to encode or decode null value.
788  *
789  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
790  *
791  ***/
792 #define SILC_ASN1_NULL SILC_ASN1_U0(NULL)
793 #define SILC_ASN1_NULL_T(o, t) SILC_ASN1_T0(NULL, 0, t)
794
795 /****f* silcasn1/SilcASN1API/SILC_ASN1_OID
796  *
797  * SYNOPSIS
798  *
799  *    Encoding:
800  *    SILC_ASN1_OID(oid)
801  *    SILC_ASN1_OID_T(opts, tag, oid)
802  *
803  *    Decoding:
804  *    SILC_ASN1_OID(&oid)
805  *    SILC_ASN1_OID_T(opts, tag, &oid)
806  *
807  * DESCRIPTION
808  *
809  *    Macro used to encode or decode OID string.  The OID string type
810  *    is NULL terminated char.  Its length can be determinted with strlen().
811  *
812  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
813  *
814  ***/
815 #define SILC_ASN1_OID(x) SILC_ASN1_U1(OID, x)
816 #define SILC_ASN1_OID_T(o, t, x) SILC_ASN1_UT(OID, o, t, x)
817
818 /****f* silcasn1/SilcASN1API/SILC_ASN1_OCTET_STRING
819  *
820  * SYNOPSIS
821  *
822  *    Encoding:
823  *    SILC_ASN1_OCTET_STRING(str, str_len)
824  *    SILC_ASN1_OCTET_STRING_T(opts, tag, str, str_len)
825  *
826  *    Decoding:
827  *    SILC_ASN1_OCTET_STRING(&str, &str_len)
828  *    SILC_ASN1_OCTET_STRING_T(opts, tag, &str, &str_len)
829  *
830  * DESCRIPTION
831  *
832  *    Macro used to encode or decode octet string.  The string type is
833  *    unsigned char and string length SilcUInt32.  Octet string is
834  *    considered to be 8-bit unsigned binary data.
835  *
836  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
837  *
838  ***/
839 #define SILC_ASN1_OCTET_STRING(x, xl) SILC_ASN1_U2(OCTET_STRING, x, xl)
840 #define SILC_ASN1_OCTET_STRING_T(o, t, x, xl) SILC_ASN1_T2(OCTET_STRING, o, t, x, xl)
841
842 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTF8_STRING
843  *
844  * SYNOPSIS
845  *
846  *    Encoding:
847  *    SILC_ASN1_UTF8_STRING(str, str_len)
848  *    SILC_ASN1_UTF8_STRING_T(opts, tag, str, str_len)
849  *
850  *    Decoding:
851  *    SILC_ASN1_UTF8_STRING(&str, &str_len)
852  *    SILC_ASN1_UTF8_STRING_T(opts, tag, &str, &str_len)
853  *
854  * DESCRIPTION
855  *
856  *    Macro used to encode or decode UTF-8 string.  The string type is
857  *    unsigned char and string length SilcUInt32.
858  *
859  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
860  *
861  * NOTES
862  *
863  *    The string must be in UTF-8 encoding when encoding.  The decoded
864  *    string will be in UTF-8 encoding.  The data is also encoded to
865  *    or decoded from UTF-8.
866  *
867  ***/
868 #define SILC_ASN1_UTF8_STRING(x, xl) SILC_ASN1_U2(UTF8_STRING, x, xl)
869 #define SILC_ASN1_UTF8_STRING_T(o, t, x, xl) SILC_ASN1_T2(UTF8_STRING, o, t, x, xl)
870
871 /****f* silcasn1/SilcASN1API/SILC_ASN1_NUMERIC_STRING
872  *
873  * SYNOPSIS
874  *
875  *    Encoding:
876  *    SILC_ASN1_NUMERIC_STRING(str, str_len)
877  *    SILC_ASN1_NUMERIC_STRING_T(opts, tag, str, str_len)
878  *
879  *    Decoding:
880  *    SILC_ASN1_NUMERIC_STRING(&str, &str_len)
881  *    SILC_ASN1_NUMERIC_STRING_T(opts, tag, &str, &str_len)
882  *
883  * DESCRIPTION
884  *
885  *    Macro used to encode or decode numerical string.  The string type is
886  *    unsigned char and string length SilcUInt32.
887  *
888  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
889  *
890  * NOTES
891  *
892  *    The string must be in UTF-8 encoding when encoding.  The decoded
893  *    string will be in UTF-8 encoding.  The actual data is encoded to
894  *    or decoded from numerical.
895  *
896  ***/
897 #define SILC_ASN1_NUMERIC_STRING(x, xl) SILC_ASN1_U2(NUMERIC_STRING, x, xl)
898 #define SILC_ASN1_NUMERIC_STRING_T(o, t, x, xl) SILC_ASN1_T2(NUMERIC_STRING, o, t, x, xl)
899
900 /****f* silcasn1/SilcASN1API/SILC_ASN1_PRINTABLE_STRING
901  *
902  * SYNOPSIS
903  *
904  *    Encoding:
905  *    SILC_ASN1_PRINTABLE_STRING(str, str_len)
906  *    SILC_ASN1_PRINTABLE_STRING_T(opts, tag, str, str_len)
907  *
908  *    Decoding:
909  *    SILC_ASN1_PRINTABLE_STRING(&str, &str_len)
910  *    SILC_ASN1_PRINTABLE_STRING_T(opts, tag, &str, &str_len)
911  *
912  * DESCRIPTION
913  *
914  *    Macro used to encode or decode printable string.  The string type is
915  *    unsigned char and string length SilcUInt32.
916  *
917  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
918  *
919  * NOTES
920  *
921  *    The string must be in UTF-8 encoding when encoding.  The decoded
922  *    string will be in UTF-8 encoding.  The actual data is encoded to
923  *    or decoded from printable.
924  *
925  ***/
926 #define SILC_ASN1_PRINTABLE_STRING(x, xl) SILC_ASN1_U2(PRINTABLE_STRING, x, xl)
927 #define SILC_ASN1_PRINTABLE_STRING_T(o, t, x, xl) SILC_ASN1_T2(PRINTABLE_STRING, o, t, x, xl)
928
929 /****f* silcasn1/SilcASN1API/SILC_ASN1_TELETEX_STRING
930  *
931  * SYNOPSIS
932  *
933  *    Encoding:
934  *    SILC_ASN1_TELETEX_STRING(str, str_len)
935  *    SILC_ASN1_TELETEX_STRING_T(opts, tag, str, str_len)
936  *
937  *    Decoding:
938  *    SILC_ASN1_TELETEX_STRING(&str, &str_len)
939  *    SILC_ASN1_TELETEX_STRING_T(opts, tag, &str, &str_len)
940  *
941  * DESCRIPTION
942  *
943  *    Macro used to encode or decode teletex (T61) string.  The string type is
944  *    unsigned char and string length SilcUInt32.
945  *
946  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
947  *
948  * NOTES
949  *
950  *    The string must be in UTF-8 encoding when encoding.  The decoded
951  *    string will be in UTF-8 encoding.  The actual data is encoded to
952  *    or decoded from teletex (T61).
953  *
954  ***/
955 #define SILC_ASN1_TELETEX_STRING(x, xl) SILC_ASN1_U2(TELETEX_STRING, x, xl)
956 #define SILC_ASN1_TELETEX_STRING_T(o, t, x, xl) SILC_ASN1_T2(TELETEX_STRING, o, t, x, xl)
957
958 /****f* silcasn1/SilcASN1API/SILC_ASN1_IA5_STRING
959  *
960  * SYNOPSIS
961  *
962  *    Encoding:
963  *    SILC_ASN1_IA5_STRING(str, str_len)
964  *    SILC_ASN1_IA5_STRING_T(opts, tag, str, str_len)
965  *
966  *    Decoding:
967  *    SILC_ASN1_IA5_STRING(&str, &str_len)
968  *    SILC_ASN1_IA5_STRING_T(opts, tag, &str, &str_len)
969  *
970  * DESCRIPTION
971  *
972  *    Macro used to encode or decode US ASCII (IA5) string.  The string type
973  *    is unsigned char and string length SilcUInt32.
974  *
975  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
976  *
977  * NOTES
978  *
979  *    The string must be in UTF-8 encoding when encoding.  The decoded
980  *    string will be in UTF-8 encoding.  The actual data is encoded to
981  *    or decoded from US ASCII (IA5).
982  *
983  ***/
984 #define SILC_ASN1_IA5_STRING(x, xl) SILC_ASN1_U2(IA5_STRING, x, xl)
985 #define SILC_ASN1_IA5_STRING_T(o, t, x, xl) SILC_ASN1_T2(IA5_STRING, o, t, x, xl)
986
987 /****f* silcasn1/SilcASN1API/SILC_ASN1_VISIBLE_STRING
988  *
989  * SYNOPSIS
990  *
991  *    Encoding:
992  *    SILC_ASN1_VISIBLE_STRING(str, str_len)
993  *    SILC_ASN1_VISIBLE_STRING_T(opts, tag, str, str_len)
994  *
995  *    Decoding:
996  *    SILC_ASN1_VISIBLE_STRING(&str, &str_len)
997  *    SILC_ASN1_VISIBLE_STRING_T(opts, tag, &str, &str_len)
998  *
999  * DESCRIPTION
1000  *
1001  *    Macro used to encode or decode visible string.  The string type is
1002  *    unsigned char and string length SilcUInt32.
1003  *
1004  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1005  *
1006  * NOTES
1007  *
1008  *    The string must be in UTF-8 encoding when encoding.  The decoded
1009  *    string will be in UTF-8 encoding.  The actual data is encoded to
1010  *    or decoded from visible.
1011  *
1012  ***/
1013 #define SILC_ASN1_VISIBLE_STRING(x, xl) SILC_ASN1_U2(VISIBLE_STRING, x, xl)
1014 #define SILC_ASN1_VISIBLE_STRING_T(o, t, x, xl) SILC_ASN1_T2(VISIBLE_STRING, o, t, x, xl)
1015
1016 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNIVERSAL_STRING
1017  *
1018  * SYNOPSIS
1019  *
1020  *    Encoding:
1021  *    SILC_ASN1_UNIVERSAL_STRING(str, str_len)
1022  *    SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, str, str_len)
1023  *
1024  *    Decoding:
1025  *    SILC_ASN1_UNIVERSAL_STRING(&str, &str_len)
1026  *    SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, &str, &str_len)
1027  *
1028  * DESCRIPTION
1029  *
1030  *    Macro used to encode or decode universal (UCS-4) string.  The string
1031  *    type is unsigned char and string length SilcUInt32.
1032  *
1033  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1034  *
1035  * NOTES
1036  *
1037  *    The string must be in UTF-8 encoding when encoding.  The decoded
1038  *    string will be in UTF-8 encoding.  The actual data is encoded to
1039  *    or decoded from universal (UCS-4).
1040  *
1041  ***/
1042 #define SILC_ASN1_UNIVERSAL_STRING(x, xl) SILC_ASN1_U2(UNIVERSAL_STRING, x, xl)
1043 #define SILC_ASN1_UNIVERSAL_STRING_T(o, t, x, xl) SILC_ASN1_T2(UNIVERSAL_STRING, o, t, x, xl)
1044
1045 /****f* silcasn1/SilcASN1API/SILC_ASN1_BMP_STRING
1046  *
1047  * SYNOPSIS
1048  *
1049  *    Encoding:
1050  *    SILC_ASN1_BMP_STRING(str, str_len)
1051  *    SILC_ASN1_BMP_STRING_T(opts, tag, str, str_len)
1052  *
1053  *    Decoding:
1054  *    SILC_ASN1_BMP_STRING(&str, &str_len)
1055  *    SILC_ASN1_BMP_STRING_T(opts, tag, &str, &str_len)
1056  *
1057  * DESCRIPTION
1058  *
1059  *    Macro used to encode or decode BMP (UCS-2) string.  The string type is
1060  *    unsigned char and string length SilcUInt32.
1061  *
1062  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1063  *
1064  * NOTES
1065  *
1066  *    The string must be in UTF-8 encoding when encoding.  The decoded
1067  *    string will be in UTF-8 encoding.  The actual data is encoded to
1068  *    or decoded from BMP (UCS-2)
1069  *
1070  ***/
1071 #define SILC_ASN1_BMP_STRING(x, xl) SILC_ASN1_U2(BMP_STRING, x, xl)
1072 #define SILC_ASN1_BMP_STRING_T(o, t, x, xl) SILC_ASN1_T2(BMP_STRING, o, t, x, xl)
1073
1074 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNRESTRICTED_STRING
1075  *
1076  * SYNOPSIS
1077  *
1078  *    Encoding:
1079  *    SILC_ASN1_UNRESTRICTED_STRING(str, str_len)
1080  *    SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, str, str_len)
1081  *
1082  *    Decoding:
1083  *    SILC_ASN1_UNRESTRICTED_STRING(&str, &str_len)
1084  *    SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, &str, &str_len)
1085  *
1086  * DESCRIPTION
1087  *
1088  *    Macro used to encode or decode unrestricted string.  The string type is
1089  *    unsigned char and string length SilcUInt32.
1090  *
1091  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1092  *
1093  * NOTES
1094  *
1095  *    The string must be in UTF-8 encoding when encoding.  The decoded
1096  *    string will be in UTF-8 encoding.  The actual data is encoded to
1097  *    or decoded from unrestricted.  NOTE: this implementation use 8-bit ASCII.
1098  *
1099  ***/
1100 #define SILC_ASN1_UNRESTRICTED_STRING(x, xl) SILC_ASN1_U2(UNRESTRICTED_STRING, x, xl)
1101 #define SILC_ASN1_UNRESTRICTED_STRING_T(o, t, x, xl) SILC_ASN1_T2(UNRESTRICTED_STRING, o, t, x, xl)
1102
1103 /****f* silcasn1/SilcASN1API/SILC_ASN1_GENERAL_STRING
1104  *
1105  * SYNOPSIS
1106  *
1107  *    Encoding:
1108  *    SILC_ASN1_GENERAL_STRING(str, str_len)
1109  *    SILC_ASN1_GENERAL_STRING_T(opts, tag, str, str_len)
1110  *
1111  *    Decoding:
1112  *    SILC_ASN1_GENERAL_STRING(&str, &str_len)
1113  *    SILC_ASN1_GENERAL_STRING_T(opts, tag, &str, &str_len)
1114  *
1115  * DESCRIPTION
1116  *
1117  *    Macro used to encode or decode general string.  The string type is
1118  *    unsigned char and string length SilcUInt32.
1119  *
1120  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1121  *
1122  * NOTES
1123  *
1124  *    The string must be in UTF-8 encoding when encoding.  The decoded
1125  *    string will be in UTF-8 encoding.  The actual data is encoded to
1126  *    or decoded from general.  NOTE: this implementation use 8-bit ASCII.
1127  *
1128  ***/
1129 #define SILC_ASN1_GENERAL_STRING(x, xl) SILC_ASN1_U2(GENERAL_STRING, x, xl)
1130 #define SILC_ASN1_GENERAL_STRING_T(o, t, x, xl) SILC_ASN1_T2(GENERAL_STRING, o, t, x, xl)
1131
1132 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTC_TIME
1133  *
1134  * SYNOPSIS
1135  *
1136  *    Encoding:
1137  *    SILC_ASN1_UTC_TIME(timeval)
1138  *    SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1139  *
1140  *    Decoding:
1141  *    SILC_ASN1_UTC_TIME(&str, &timeval)
1142  *    SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1143  *
1144  * DESCRIPTION
1145  *
1146  *    Macro used to encode or decode universal (UTC) time value.  The
1147  *    time value type is SilcTime.
1148  *
1149  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1150  *
1151  ***/
1152 #define SILC_ASN1_UTC_TIME(x) SILC_ASN1_U1(UTC_TIME, x)
1153 #define SILC_ASN1_UTC_TIME_T(o, t, x) SILC_ASN1_T1(UTC_TIME, o, t, x)
1154
1155 /****f* silcasn1/SilcASN1API/SILC_ASN1_GEN_TIME
1156  *
1157  * SYNOPSIS
1158  *
1159  *    Encoding:
1160  *    SILC_ASN1_GEN_TIME(timeval)
1161  *    SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1162  *
1163  *    Decoding:
1164  *    SILC_ASN1_GEN_TIME(&str, &timeval)
1165  *    SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1166  *
1167  * DESCRIPTION
1168  *
1169  *    Macro used to encode or decode generalized time value.  The
1170  *    time value type is SilcTime.
1171  *
1172  *    The `opts' is SilcAsn1Options.  The `tag' is a tag number.
1173  *
1174  ***/
1175 #define SILC_ASN1_GEN_TIME(x) SILC_ASN1_U1(GENERALIZED_TIME, x)
1176 #define SILC_ASN1_GEN_TIME_T(o, t, x) SILC_ASN1_T1(GENERALIZED_TIME, o, t, x)
1177
1178 /****f* silcasn1/SilcASN1API/SILC_ASN1_END
1179  *
1180  * SYNOPSIS
1181  *
1182  *    SILC_ASN1_END
1183  *
1184  * DESCRIPTION
1185  *
1186  *    The SILC_ASN1_END is used to terminate the variable argument list in
1187  *    silc_asn1_encode and silc_asn1_decode functions.  It is also used to
1188  *    terminate SILC_ASN1_SEQUENCE, SILC_ASN1_SEQUENCE_T, SILC_ASN1_SET,
1189  *    SILC_ASN1_SET_T, SILC_ASN1_SEQUENCE_OF, SILC_ASN1_SET_OF and
1190  *    SILC_ASN1_CHOICE macros.
1191  *
1192  ***/
1193 #define SILC_ASN1_END 0
1194
1195 #endif /* SILCASN1_H */