5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2003 - 2007 Pekka Riikonen
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.
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.
20 /****h* silcasn1/ASN.1 Interface
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.
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.
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).
44 * The implementation supports all the common ASN.1 types. This
45 * implementation does not support advanced ASN.1 features like macros.
47 * References: ITU-T X.680 - X.693
48 * http://www.itu.int/ITU-T/studygroups/com17/languages/
55 /****s* silcasn1/SilcASN1API/SilcAsn1
59 * typedef struct SilcAsn1Object *SilcAsn1;
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.
70 typedef struct SilcAsn1Object *SilcAsn1;
72 /****s* silcasn1/SilcASN1API/SilcAsn1Struct
76 * typedef struct SilcAsn1Object SilcAsn1Struct;
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.
86 typedef struct SilcAsn1Object SilcAsn1Struct;
88 /****d* silcasn1/SilcASN1API/SilcAsn1Options
92 * typedef enum { ... } SilcAsn1Options;
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.
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.
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),
118 /* Default. If only this is set then defaults are implied. */
119 SILC_ASN1_DEFAULT = 0x0000,
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 */
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 */
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. */
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. */
151 /****d* silcasn1/SilcASN1API/SilcAsn1Tag
155 * typedef enum { ... } SilcAsn1Tag;
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.
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 */
198 #include "silcasn1_i.h"
200 /****f* silcasn1/SilcASN1API/silc_asn1_alloc
204 * SilcAsn1 silc_asn1_alloc(SilcStack stack);
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'.
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
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.
224 SilcAsn1 silc_asn1_alloc(SilcStack stack);
226 /****f* silcasn1/SilcASN1API/silc_asn1_free
230 * void silc_asn1_free(SilcAsn1 asn1);
234 * Frees the SilcAsn1 context and all allocated memory. All encoded
235 * buffers and all decoded buffers with this context becomes invalid
239 void silc_asn1_free(SilcAsn1 asn1);
241 /****f* silcasn1/SilcASN1API/silc_asn1_init
245 * SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack);
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.
255 * SilcAsn1Struct asn1;
256 * if (!silc_asn1_init(&asn1, NULL))
260 SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack);
262 /****f* silcasn1/SilcASN1API/silc_asn1_uninit
266 * void silc_asn1_uninit(SilcAsn1 asn1);
270 * Uninitializes a pre-allocated SilcAsn1 context. Use this function
271 * instead of silc_asn1_free if you used silc_asn1_init.
274 void silc_asn1_uninit(SilcAsn1 asn1);
276 /****f* silcasn1/SilcASN1API/silc_asn1_encode
280 * SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
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.
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
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.
303 * If encoding is successful this returns TRUE, FALSE on error.
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),
314 * SILC_ASN1_OCTET_STRING_T(0, 1, string2, string2_len),
315 * SILC_ASN1_END, SILC_ASN1_END);
317 * Creates ASN.1 tree that looks something like:
321 * string OCTET-STRING,
323 * foo [100] EXPLICIT BOOLEAN }
324 * string2 [1] OCTET-STRING }
327 SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
329 /****f* silcasn1/SilcASN1API/silc_asn1_decode
333 * SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
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.
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.
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)
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
369 * SilcBool bool_val, foo;
370 * unsigned char *string, string2;
371 * SilcUInt32 string_len, string2_len;
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),
380 * SILC_ASN1_OCTET_STRING_T(0, 1, &str2, &str2_len),
381 * SILC_ASN1_END, SILC_ASN1_END);
384 SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
386 /****f* silcasn1/SilcASN1API/SILC_ASN1_OPTS
390 * SILC_ASN1_OPTS(opts)
394 * The `opts' is SilcAsn1Options. This macro can be used to set
395 * options for silc_asn1_encode and silc_asn1_decode functions.
399 * Only the SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags may be
400 * set with this macro.
402 * This macro must be the first macro in the variable argument list
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);
415 #define SILC_ASN1_OPTS(opts) SILC_ASN1_TAG_OPTS, (opts)
417 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY
422 * SILC_ASN1_ANY(buffer)
423 * SILC_ASN1_ANY_T(opts, tag, buffer)
426 * SILC_ASN1_ANY(&buffer)
427 * SILC_ASN1_ANY_T(opts, tag, buffer)
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
436 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
440 * // Encode node of two boolean values
441 * silc_asn1_encode(asn1, node,
442 * SILC_ASN1_BOOLEAN(val1),
443 * SILC_ASN1_BOOLEAN(val2),
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);
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)
457 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY_PRIMITIVE
462 * SILC_ASN1_ANY_PRIMITIVE(tag, buffer)
463 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
466 * SILC_ASN1_ANY_PRIMITIVE(tag, &buffer)
467 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
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.
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.
482 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
486 * // Get MP integer in encoded format
487 * mpbuf = mp_get_octet_string(mp);
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),
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),
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)
503 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE
509 * SILC_ASN1_SEQUENCE_T(opts, tag)
513 * SILC_ASN1_SEQUENCE_T(opts, tag)
517 * Macro used to encode or decode sequence. The sequence must be
518 * terminated with SILC_ASN1_END.
520 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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);
531 #define SILC_ASN1_SEQUENCE SILC_ASN1_U0(SEQUENCE)
532 #define SILC_ASN1_SEQUENCE_T(o, t) SILC_ASN1_T0(SEQUENCE, o, t)
534 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET
540 * SILC_ASN1_SET_T(opts, tag)
544 * SILC_ASN1_SET_T(opts, tag)
548 * Macro used to encode or decode set. The set must be terminated
549 * with SILC_ASN1_END.
551 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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);
561 #define SILC_ASN1_SET SILC_ASN1_U0(SET)
562 #define SILC_ASN1_SET_T(o, t) SILC_ASN1_T0(SET, o, t)
564 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE_OF
569 * SILC_ASN1_SEQUENCE_OF(bufarray, numbufs)
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.
579 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
580 * flags. Do not use this macro without flags.
587 * // Decode sequence of sequences. Each returned buffer in the array
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);
596 #define SILC_ASN1_SEQUENCE_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
598 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET_OF
603 * SILC_ASN1_SET_OF(bufarray, numbufs)
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.
613 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
614 * flags. Do not use this macro without flags.
618 * // Decode set of sequences. Each returned buffer in the array
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);
627 #define SILC_ASN1_SET_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
629 /****f* silcasn1/SilcASN1API/SILC_ASN1_CHOICE
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.
644 * // Decode timeval that is either UTC or generalized time
645 * silc_asn1_decode(asn1, tree,
646 * SILC_ASN1_SEQUENCE,
648 * SILC_ASN1_UTC_TIME(&timeval),
649 * SILC_ASN1_GEN_TIME(&timeval),
651 * SILC_ASN1_END, SILC_ASN1_END);
654 #define SILC_ASN1_CHOICE SILC_ASN1_U0(CHOICE)
656 /****f* silcasn1/SilcASN1API/SILC_ASN1_BOOLEAN
661 * SILC_ASN1_BOOLEAN(boolval)
662 * SILC_ASN1_BOOLEAN_T(opts, tag, boolval)
665 * SILC_ASN1_BOOLEAN(&boolval)
666 * SILC_ASN1_BOOLEAN_T(opts, tag, &boolval)
670 * Macro used to encode or decode boolean value. The boolean type
673 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
679 /****f* silcasn1/SilcASN1API/SILC_ASN1_INT
684 * SILC_ASN1_INT(integer)
685 * SILC_ASN1_INT_T(opts, tag, &integer)
688 * SILC_ASN1_INT(&integer)
689 * SILC_ASN1_INT_T(opts, tag, &integer);
693 * Macro used to encode or decode multiple precision integer. The
694 * integer type is SilcMPInt.
696 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
702 /****f* silcasn1/SilcASN1API/SILC_ASN1_SHORT_INT
707 * SILC_ASN1_SHORT_INT(integer)
708 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer)
711 * SILC_ASN1_SHORT_INT(&integer)
712 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer);
716 * Macro used to encode or decode short integer (32 bits). The
717 * integer type is SilcUInt32.
719 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
725 /****f* silcasn1/SilcASN1API/SILC_ASN1_ENUM
730 * SILC_ASN1_ENUM(enum)
731 * SILC_ASN1_ENUM_T(opts, tag, &enum)
734 * SILC_ASN1_ENUM(&enum)
735 * SILC_ASN1_ENUM_T(opts, tag, &enum);
739 * Macro used to encode or decode enumeration value. The enumeration
742 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
748 /****f* silcasn1/SilcASN1API/SILC_ASN1_BIT_STRING
753 * SILC_ASN1_BIT_STRING(str, str_len)
754 * SILC_ASN1_BIT_STRING_T(opts, tag, str, str_len)
757 * SILC_ASN1_BIT_STRING(&str, &str_len)
758 * SILC_ASN1_BIT_STRING_T(opts, tag, &str, &str_len)
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
767 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
773 /****f* silcasn1/SilcASN1API/SILC_ASN1_NULL
779 * SILC_ASN1_NULL_T(opts, tag)
783 * SILC_ASN1_NULL_T(opts, tag)
787 * Macro used to encode or decode null value.
789 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
792 #define SILC_ASN1_NULL SILC_ASN1_U0(NULL)
793 #define SILC_ASN1_NULL_T(o, t) SILC_ASN1_T0(NULL, 0, t)
795 /****f* silcasn1/SilcASN1API/SILC_ASN1_OID
801 * SILC_ASN1_OID_T(opts, tag, oid)
804 * SILC_ASN1_OID(&oid)
805 * SILC_ASN1_OID_T(opts, tag, &oid)
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().
812 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
818 /****f* silcasn1/SilcASN1API/SILC_ASN1_OCTET_STRING
823 * SILC_ASN1_OCTET_STRING(str, str_len)
824 * SILC_ASN1_OCTET_STRING_T(opts, tag, str, str_len)
827 * SILC_ASN1_OCTET_STRING(&str, &str_len)
828 * SILC_ASN1_OCTET_STRING_T(opts, tag, &str, &str_len)
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.
836 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
842 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTF8_STRING
847 * SILC_ASN1_UTF8_STRING(str, str_len)
848 * SILC_ASN1_UTF8_STRING_T(opts, tag, str, str_len)
851 * SILC_ASN1_UTF8_STRING(&str, &str_len)
852 * SILC_ASN1_UTF8_STRING_T(opts, tag, &str, &str_len)
856 * Macro used to encode or decode UTF-8 string. The string type is
857 * unsigned char and string length SilcUInt32.
859 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
871 /****f* silcasn1/SilcASN1API/SILC_ASN1_NUMERIC_STRING
876 * SILC_ASN1_NUMERIC_STRING(str, str_len)
877 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, str, str_len)
880 * SILC_ASN1_NUMERIC_STRING(&str, &str_len)
881 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, &str, &str_len)
885 * Macro used to encode or decode numerical string. The string type is
886 * unsigned char and string length SilcUInt32.
888 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
900 /****f* silcasn1/SilcASN1API/SILC_ASN1_PRINTABLE_STRING
905 * SILC_ASN1_PRINTABLE_STRING(str, str_len)
906 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, str, str_len)
909 * SILC_ASN1_PRINTABLE_STRING(&str, &str_len)
910 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, &str, &str_len)
914 * Macro used to encode or decode printable string. The string type is
915 * unsigned char and string length SilcUInt32.
917 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
929 /****f* silcasn1/SilcASN1API/SILC_ASN1_TELETEX_STRING
934 * SILC_ASN1_TELETEX_STRING(str, str_len)
935 * SILC_ASN1_TELETEX_STRING_T(opts, tag, str, str_len)
938 * SILC_ASN1_TELETEX_STRING(&str, &str_len)
939 * SILC_ASN1_TELETEX_STRING_T(opts, tag, &str, &str_len)
943 * Macro used to encode or decode teletex (T61) string. The string type is
944 * unsigned char and string length SilcUInt32.
946 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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).
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)
958 /****f* silcasn1/SilcASN1API/SILC_ASN1_IA5_STRING
963 * SILC_ASN1_IA5_STRING(str, str_len)
964 * SILC_ASN1_IA5_STRING_T(opts, tag, str, str_len)
967 * SILC_ASN1_IA5_STRING(&str, &str_len)
968 * SILC_ASN1_IA5_STRING_T(opts, tag, &str, &str_len)
972 * Macro used to encode or decode US ASCII (IA5) string. The string type
973 * is unsigned char and string length SilcUInt32.
975 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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).
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)
987 /****f* silcasn1/SilcASN1API/SILC_ASN1_VISIBLE_STRING
992 * SILC_ASN1_VISIBLE_STRING(str, str_len)
993 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, str, str_len)
996 * SILC_ASN1_VISIBLE_STRING(&str, &str_len)
997 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, &str, &str_len)
1001 * Macro used to encode or decode visible string. The string type is
1002 * unsigned char and string length SilcUInt32.
1004 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
1016 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNIVERSAL_STRING
1021 * SILC_ASN1_UNIVERSAL_STRING(str, str_len)
1022 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, str, str_len)
1025 * SILC_ASN1_UNIVERSAL_STRING(&str, &str_len)
1026 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, &str, &str_len)
1030 * Macro used to encode or decode universal (UCS-4) string. The string
1031 * type is unsigned char and string length SilcUInt32.
1033 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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).
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)
1045 /****f* silcasn1/SilcASN1API/SILC_ASN1_BMP_STRING
1050 * SILC_ASN1_BMP_STRING(str, str_len)
1051 * SILC_ASN1_BMP_STRING_T(opts, tag, str, str_len)
1054 * SILC_ASN1_BMP_STRING(&str, &str_len)
1055 * SILC_ASN1_BMP_STRING_T(opts, tag, &str, &str_len)
1059 * Macro used to encode or decode BMP (UCS-2) string. The string type is
1060 * unsigned char and string length SilcUInt32.
1062 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
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)
1074 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNRESTRICTED_STRING
1079 * SILC_ASN1_UNRESTRICTED_STRING(str, str_len)
1080 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, str, str_len)
1083 * SILC_ASN1_UNRESTRICTED_STRING(&str, &str_len)
1084 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, &str, &str_len)
1088 * Macro used to encode or decode unrestricted string. The string type is
1089 * unsigned char and string length SilcUInt32.
1091 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
1103 /****f* silcasn1/SilcASN1API/SILC_ASN1_GENERAL_STRING
1108 * SILC_ASN1_GENERAL_STRING(str, str_len)
1109 * SILC_ASN1_GENERAL_STRING_T(opts, tag, str, str_len)
1112 * SILC_ASN1_GENERAL_STRING(&str, &str_len)
1113 * SILC_ASN1_GENERAL_STRING_T(opts, tag, &str, &str_len)
1117 * Macro used to encode or decode general string. The string type is
1118 * unsigned char and string length SilcUInt32.
1120 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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.
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)
1132 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTC_TIME
1137 * SILC_ASN1_UTC_TIME(timeval)
1138 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1141 * SILC_ASN1_UTC_TIME(&str, &timeval)
1142 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1146 * Macro used to encode or decode universal (UTC) time value. The
1147 * time value type is SilcTime.
1149 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
1155 /****f* silcasn1/SilcASN1API/SILC_ASN1_GEN_TIME
1160 * SILC_ASN1_GEN_TIME(timeval)
1161 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1164 * SILC_ASN1_GEN_TIME(&str, &timeval)
1165 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1169 * Macro used to encode or decode generalized time value. The
1170 * time value type is SilcTime.
1172 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
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)
1178 /****f* silcasn1/SilcASN1API/SILC_ASN1_END
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.
1193 #define SILC_ASN1_END 0
1195 #endif /* SILCASN1_H */