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