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