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(void);
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.
212 * Usually SilcAsn1 is allocated when encoder or decoder is needed,
213 * however it is also possible to allocate long-lasting SilcAsn1 and
214 * use that every time ASN.1 routines are needed. Application could
215 * for example allocate one SilcAsn1 and use that for all ASN.1 encoding
218 * When this context is freed with silc_asn1_free all memory will be
219 * freed, and all encoded ASN.1 buffers becomes invalid. Also all
220 * data that is returned by silc_asn1_decode function becomes invalid.
223 SilcAsn1 silc_asn1_alloc(void);
225 /****f* silcasn1/SilcASN1API/silc_asn1_free
229 * void silc_asn1_free(SilcAsn1 asn1);
233 * Frees the SilcAsn1 context and all allocated memory. All encoded
234 * buffers and all decoded buffers with this context becomes invalid
238 void silc_asn1_free(SilcAsn1 asn1);
240 /****f* silcasn1/SilcASN1API/silc_asn1_init
244 * SilcBool silc_asn1_init(SilcAsn1 asn1);
248 * Initializes a pre-allocated SilcAsn1 context. This call is
249 * equivalent to silc_asn1_alloc except that this takes the pre-allocated
250 * context as argument.
254 * SilcAsn1Struct asn1;
255 * if (!silc_asn1_init(&asn1))
259 SilcBool silc_asn1_init(SilcAsn1 asn1);
261 /****f* silcasn1/SilcASN1API/silc_asn1_uninit
265 * void silc_asn1_uninit(SilcAsn1 asn1);
269 * Uninitializes a pre-allocated SilcAsn1 context. Use this function
270 * instead of silc_asn1_free if you used silc_asn1_init.
273 void silc_asn1_uninit(SilcAsn1 asn1);
275 /****f* silcasn1/SilcASN1API/silc_asn1_encode
279 * SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
283 * Encodes ASN.1 encoded buffer into `dest', from variable argument
284 * list of ASN.1 types. The variable argument list forms the ASN.1
285 * trees and nodes that are encoded into the `dest'. By default, the
286 * memory for `dest' is allocated from the `asn1', and the buffer becomes
287 * invalid either by calling silc_asn1_free, silc_asn1_uninit, or when
288 * silc_asn1_encode is called for the next time.
290 * If the SILC_ASN1_OPTS macro with SILC_ASN1_ALLOC option is given then
291 * the `dest' is dynamically allocated and caller must free it by itself.
292 * Alternatively if SILC_ASN1_ACCUMUL is given then memory is accumulated
293 * from `asn1' for `dest' and it is freed only when silc_asn1_free or
294 * silc_asn1_uninit is called. Next call to silc_asn1_encode will not
295 * cancel the previous result, but will accumulate more memory for new
298 * The variable argument list is constructed by using various
299 * macros, for example SILC_ASN1_SEQUENCE, etc. The variable argument
300 * list must always be ended with SILC_ASN1_END type.
302 * If encoding is successful this returns TRUE, FALSE on error.
306 * silc_asn1_encode(asn1, buf,
307 * SILC_ASN1_SEQUENCE,
308 * SILC_ASN1_BOOLEAN(bool_val),
309 * SILC_ASN1_OCTET_STRING(string, string_len),
310 * SILC_ASN1_SEQUENCE_T(0, 2),
311 * SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 100, foo),
313 * SILC_ASN1_OCTET_STRING_T(0, 1, string2, string2_len),
314 * SILC_ASN1_END, SILC_ASN1_END);
316 * Creates ASN.1 tree that looks something like:
320 * string OCTET-STRING,
322 * foo [100] EXPLICIT BOOLEAN }
323 * string2 [1] OCTET-STRING }
326 SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...);
328 /****f* silcasn1/SilcASN1API/silc_asn1_decode
332 * SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
336 * Decodes the ASN.1 encoded buffer `src' by the ASN.1 types sent
337 * as argument. The ASN.1 types sent as argument must be found from
338 * the `src' for this function to decode successfully.
340 * The memory allocated for the results are allocated from `asn1' and
341 * they become invalid if `asn1' becomes invalid. Next (second) call
342 * to this function does NOT invalidate the previous results. However,
343 * third call to this function does invalidate the results of the first
344 * call but not second. On the other hand, fourth call invalidates
345 * the results of the second call but not third, fifth call invalidates
346 * the results of the third call but not fourth, and so on. This allows
347 * efficient decoding, when silc_asn1_decode must be called multiple times
348 * to decode all data, without new memory allocations. However, caller
349 * must be cautios and understand that the every second call invalidates
350 * the results of every second previous results.
352 * If the SILC_ASN1_OPTS macro with SILC_ASN1_ALLOC option is given then
353 * all results are dynamically allocated and caller must free them by
354 * itself. Alternatively if SILC_ASN1_ACCUMUL is given then memory is
355 * accumulated from `asn1' for results and they are freed only when the
356 * silc_asn1_free or silc_asn1_uninit is called. Next calls to the
357 * silc_asn1_decode will NOT invalidate the old results, but will
358 * accumulate more memory for new results. If the SILC_ASN1_OPTS is not
359 * given at all then the default allocation method (decribed above)
362 * If caller needs to store the results even after `asn1' becomes invalid
363 * then call must either use SILC_ASN1_ALLOC option or duplicate the
368 * SilcBool bool_val, foo;
369 * unsigned char *string, string2;
370 * SilcUInt32 string_len, string2_len;
372 * silc_asn1_decode(asn1, tree,
373 * SILC_ASN1_SEQUENCE,
374 * SILC_ASN1_BOOLEAN(&bool_val),
375 * SILC_ASN1_OCTET_STRING(&string, &string_len),
376 * SILC_ASN1_SEQUENCE_T(0, 2),
377 * SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 100, &foo),
379 * SILC_ASN1_OCTET_STRING_T(0, 1, &str2, &str2_len),
380 * SILC_ASN1_END, SILC_ASN1_END);
383 SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
385 /****f* silcasn1/SilcASN1API/SILC_ASN1_OPTS
389 * SILC_ASN1_OPTS(opts)
393 * The `opts' is SilcAsn1Options. This macro can be used to set
394 * options for silc_asn1_encode and silc_asn1_decode functions.
398 * Only the SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags may be
399 * set with this macro.
401 * This macro must be the first macro in the variable argument list
406 * silc_asn1_decode(asn1, tree,
407 * SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
408 * SILC_ASN1_SEQUENCE,
409 * SILC_ASN1_BOOLEAN(&bool_val),
410 * SILC_ASN1_OCTET_STRING(&string, &string_len),
411 * SILC_ASN1_END, SILC_ASN1_END);
414 #define SILC_ASN1_OPTS(opts) SILC_ASN1_TAG_OPTS, (opts)
416 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY
421 * SILC_ASN1_ANY(buffer)
422 * SILC_ASN1_ANY_T(opts, tag, buffer)
425 * SILC_ASN1_ANY(&buffer)
426 * SILC_ASN1_ANY_T(opts, tag, buffer)
430 * Macro used to encode or decode another ASN.1 node. The buffer type
431 * is SilcBuffer. This macro can be used for example to split large
432 * tree into multiple nodes, and then decoding the nodes separately from
435 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
439 * // Encode node of two boolean values
440 * silc_asn1_encode(asn1, node,
441 * SILC_ASN1_BOOLEAN(val1),
442 * SILC_ASN1_BOOLEAN(val2),
445 * // Encode tree with the node
446 * silc_asn1_encode(asn1, tree,
447 * SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
448 * SILC_ASN1_ANY(node),
449 * SILC_ASN1_BOOLEAN(boolval),
450 * SILC_ASN1_END, SILC_ASN1_END);
453 #define SILC_ASN1_ANY(x) SILC_ASN1_U1(ANY, x)
454 #define SILC_ASN1_ANY_T(o, t, x) SILC_ASN1_T1(ANY, o, t, x)
456 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY_PRIMITIVE
461 * SILC_ASN1_ANY_PRIMITIVE(tag, buffer)
462 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
465 * SILC_ASN1_ANY_PRIMITIVE(tag, &buffer)
466 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer)
470 * Special macro used to encode pre-encoded primitive data blob. The data
471 * can be any primitive type that is already encoded in correct format.
472 * The caller is responsible of making sure the data is formatted
473 * correctly. When decoding this returns the raw data blob and the caller
474 * must know of what type and format it is. The buffer type is SilcBuffer.
476 * This macro can be used in cases when the data to be encoded is already
477 * in encoded format, and it only needs to be added to ASN.1 tree. The
478 * SILC_ASN1_ANY cannot be used with primitives when tagging implicitly,
479 * in these cases this macro can be used.
481 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
485 * // Get MP integer in encoded format
486 * mpbuf = mp_get_octet_string(mp);
488 * // Encode the MP integer data to the tree
489 * silc_asn1_encode(asn1, tree,
490 * SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_INTEGER, mpbuf),
493 * // Decode the MP integer data from the tree
494 * silc_asn1_decode(asn1, tree,
495 * SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_INTEGER, &buffer),
499 #define SILC_ASN1_ANY_PRIMITIVE(t, x) SILC_ASN1_T1(ANY_PRIMITIVE, 0, t, x)
500 #define SILC_ASN1_ANY_PRIMITIVE_T(o, t, x) SILC_ASN1_T1(ANY_PRIMITIVE, o, t, x)
502 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE
508 * SILC_ASN1_SEQUENCE_T(opts, tag)
512 * SILC_ASN1_SEQUENCE_T(opts, tag)
516 * Macro used to encode or decode sequence. The sequence must be
517 * terminated with SILC_ASN1_END.
519 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
523 * silc_asn1_encode(asn1, tree,
524 * SILC_ASN1_SEQUENCE,
525 * SILC_ASN1_ANY(node),
526 * SILC_ASN1_BOOLEAN(boolval),
527 * SILC_ASN1_END, SILC_ASN1_END);
530 #define SILC_ASN1_SEQUENCE SILC_ASN1_U0(SEQUENCE)
531 #define SILC_ASN1_SEQUENCE_T(o, t) SILC_ASN1_T0(SEQUENCE, o, t)
533 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET
539 * SILC_ASN1_SET_T(opts, tag)
543 * SILC_ASN1_SET_T(opts, tag)
547 * Macro used to encode or decode set. The set must be terminated
548 * with SILC_ASN1_END.
550 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
554 * silc_asn1_encode(asn1, tree,
555 * SILC_ASN1_SET_T(SILC_ASN1_EXPLICIT, 0),
556 * SILC_ASN1_BOOLEAN(boolval),
557 * SILC_ASN1_END, SILC_ASN1_END);
560 #define SILC_ASN1_SET SILC_ASN1_U0(SET)
561 #define SILC_ASN1_SET_T(o, t) SILC_ASN1_T0(SET, o, t)
563 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE_OF
568 * SILC_ASN1_SEQUENCE_OF(bufarray, numbufs)
572 * Macro used to decode sequence of specified type. This returns
573 * an array of SilcBuffers and number of buffers in the array. The
574 * SILC_ASN1_CHOICE macro may also be used with this macro.
578 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
579 * flags. Do not use this macro without flags.
586 * // Decode sequence of sequences. Each returned buffer in the array
588 * silc_asn1_decode(asn1, exts,
589 * SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
590 * SILC_ASN1_SEQUENCE_OF(&bufs, &count),
591 * SILC_ASN1_TAG_SEQUENCE,
592 * SILC_ASN1_END, SILC_ASN1_END);
595 #define SILC_ASN1_SEQUENCE_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
597 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET_OF
602 * SILC_ASN1_SET_OF(bufarray, numbufs)
606 * Macro used to decode set of specified type. This returns
607 * an array of SilcBuffers and number of buffers in the array. The
608 * SILC_ASN1_CHOICE macro may also be used with this macro.
612 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL
613 * flags. Do not use this macro without flags.
617 * // Decode set of sequences. Each returned buffer in the array
619 * silc_asn1_decode(asn1, exts,
620 * SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
621 * SILC_ASN1_SET_OF(&bufs, &count),
622 * SILC_ASN1_TAG_SEQUENCE,
623 * SILC_ASN1_END, SILC_ASN1_END);
626 #define SILC_ASN1_SET_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c)
628 /****f* silcasn1/SilcASN1API/SILC_ASN1_CHOICE
637 * Macro used to specify choices in decoding. The choice list must
638 * be terminated with SILC_ASN1_END. There is no limit how many choices
639 * can be specified in the list.
643 * // Decode timeval that is either UTC or generalized time
644 * silc_asn1_decode(asn1, tree,
645 * SILC_ASN1_SEQUENCE,
647 * SILC_ASN1_UTC_TIME(&timeval),
648 * SILC_ASN1_GEN_TIME(&timeval),
650 * SILC_ASN1_END, SILC_ASN1_END);
653 #define SILC_ASN1_CHOICE SILC_ASN1_U0(CHOICE)
655 /****f* silcasn1/SilcASN1API/SILC_ASN1_BOOLEAN
660 * SILC_ASN1_BOOLEAN(boolval)
661 * SILC_ASN1_BOOLEAN_T(opts, tag, boolval)
664 * SILC_ASN1_BOOLEAN(&boolval)
665 * SILC_ASN1_BOOLEAN_T(opts, tag, &boolval)
669 * Macro used to encode or decode boolean value. The boolean type
672 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
675 #define SILC_ASN1_BOOLEAN(x) SILC_ASN1_U1(BOOLEAN, x)
676 #define SILC_ASN1_BOOLEAN_T(o, t, x) SILC_ASN1_T1(BOOLEAN, o, t, x)
678 /****f* silcasn1/SilcASN1API/SILC_ASN1_INT
683 * SILC_ASN1_INT(integer)
684 * SILC_ASN1_INT_T(opts, tag, &integer)
687 * SILC_ASN1_INT(&integer)
688 * SILC_ASN1_INT_T(opts, tag, &integer);
692 * Macro used to encode or decode multiple precision integer. The
693 * integer type is SilcMPInt.
695 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
698 #define SILC_ASN1_INT(x) SILC_ASN1_U1(INTEGER, x)
699 #define SILC_ASN1_INT_T(o, t, x) SILC_ASN1_T1(INTEGER, o, t, x)
701 /****f* silcasn1/SilcASN1API/SILC_ASN1_SHORT_INT
706 * SILC_ASN1_SHORT_INT(integer)
707 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer)
710 * SILC_ASN1_SHORT_INT(&integer)
711 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer);
715 * Macro used to encode or decode short integer (32 bits). The
716 * integer type is SilcUInt32.
718 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
721 #define SILC_ASN1_SHORT_INT(x) SILC_ASN1_U1(SHORT_INTEGER, x)
722 #define SILC_ASN1_SHORT_INT_T(o, t, x) SILC_ASN1_T1(SHORT_INTEGER, o, t, x)
724 /****f* silcasn1/SilcASN1API/SILC_ASN1_ENUM
729 * SILC_ASN1_ENUM(enum)
730 * SILC_ASN1_ENUM_T(opts, tag, &enum)
733 * SILC_ASN1_ENUM(&enum)
734 * SILC_ASN1_ENUM_T(opts, tag, &enum);
738 * Macro used to encode or decode enumeration value. The enumeration
741 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
744 #define SILC_ASN1_ENUM(x) SILC_ASN1_U1(ENUM, x)
745 #define SILC_ASN1_ENUM_T(o, t, x) SILC_ASN1_T1(ENUM, o, t, x)
747 /****f* silcasn1/SilcASN1API/SILC_ASN1_BIT_STRING
752 * SILC_ASN1_BIT_STRING(str, str_len)
753 * SILC_ASN1_BIT_STRING_T(opts, tag, str, str_len)
756 * SILC_ASN1_BIT_STRING(&str, &str_len)
757 * SILC_ASN1_BIT_STRING_T(opts, tag, &str, &str_len)
761 * Macro used to encode or decode bit string. The string length in
762 * encoding must be in bits (bytes * 8). The decoded length is in
763 * bits as well. The string type is unsigned char and string length
766 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
769 #define SILC_ASN1_BIT_STRING(x, xl) SILC_ASN1_U2(BIT_STRING, x, xl)
770 #define SILC_ASN1_BIT_STRING_T(o, t, x, xl) SILC_ASN1_T2(BIT_STRING, o, t, x, xl)
772 /****f* silcasn1/SilcASN1API/SILC_ASN1_NULL
778 * SILC_ASN1_NULL_T(opts, tag)
782 * SILC_ASN1_NULL_T(opts, tag)
786 * Macro used to encode or decode null value.
788 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
791 #define SILC_ASN1_NULL SILC_ASN1_U0(NULL)
792 #define SILC_ASN1_NULL_T(o, t) SILC_ASN1_T0(NULL, 0, t)
794 /****f* silcasn1/SilcASN1API/SILC_ASN1_OID
800 * SILC_ASN1_OID_T(opts, tag, oid)
803 * SILC_ASN1_OID(&oid)
804 * SILC_ASN1_OID_T(opts, tag, &oid)
808 * Macro used to encode or decode OID string. The OID string type
809 * is NULL terminated char. Its length can be determinted with strlen().
811 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
814 #define SILC_ASN1_OID(x) SILC_ASN1_U1(OID, x)
815 #define SILC_ASN1_OID_T(o, t, x) SILC_ASN1_UT(OID, o, t, x)
817 /****f* silcasn1/SilcASN1API/SILC_ASN1_OCTET_STRING
822 * SILC_ASN1_OCTET_STRING(str, str_len)
823 * SILC_ASN1_OCTET_STRING_T(opts, tag, str, str_len)
826 * SILC_ASN1_OCTET_STRING(&str, &str_len)
827 * SILC_ASN1_OCTET_STRING_T(opts, tag, &str, &str_len)
831 * Macro used to encode or decode octet string. The string type is
832 * unsigned char and string length SilcUInt32. Octet string is
833 * considered to be 8-bit unsigned binary data.
835 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
838 #define SILC_ASN1_OCTET_STRING(x, xl) SILC_ASN1_U2(OCTET_STRING, x, xl)
839 #define SILC_ASN1_OCTET_STRING_T(o, t, x, xl) SILC_ASN1_T2(OCTET_STRING, o, t, x, xl)
841 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTF8_STRING
846 * SILC_ASN1_UTF8_STRING(str, str_len)
847 * SILC_ASN1_UTF8_STRING_T(opts, tag, str, str_len)
850 * SILC_ASN1_UTF8_STRING(&str, &str_len)
851 * SILC_ASN1_UTF8_STRING_T(opts, tag, &str, &str_len)
855 * Macro used to encode or decode UTF-8 string. The string type is
856 * unsigned char and string length SilcUInt32.
858 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
862 * The string must be in UTF-8 encoding when encoding. The decoded
863 * string will be in UTF-8 encoding. The data is also encoded to
864 * or decoded from UTF-8.
867 #define SILC_ASN1_UTF8_STRING(x, xl) SILC_ASN1_U2(UTF8_STRING, x, xl)
868 #define SILC_ASN1_UTF8_STRING_T(o, t, x, xl) SILC_ASN1_T2(UTF8_STRING, o, t, x, xl)
870 /****f* silcasn1/SilcASN1API/SILC_ASN1_NUMERIC_STRING
875 * SILC_ASN1_NUMERIC_STRING(str, str_len)
876 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, str, str_len)
879 * SILC_ASN1_NUMERIC_STRING(&str, &str_len)
880 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, &str, &str_len)
884 * Macro used to encode or decode numerical string. The string type is
885 * unsigned char and string length SilcUInt32.
887 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
891 * The string must be in UTF-8 encoding when encoding. The decoded
892 * string will be in UTF-8 encoding. The actual data is encoded to
893 * or decoded from numerical.
896 #define SILC_ASN1_NUMERIC_STRING(x, xl) SILC_ASN1_U2(NUMERIC_STRING, x, xl)
897 #define SILC_ASN1_NUMERIC_STRING_T(o, t, x, xl) SILC_ASN1_T2(NUMERIC_STRING, o, t, x, xl)
899 /****f* silcasn1/SilcASN1API/SILC_ASN1_PRINTABLE_STRING
904 * SILC_ASN1_PRINTABLE_STRING(str, str_len)
905 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, str, str_len)
908 * SILC_ASN1_PRINTABLE_STRING(&str, &str_len)
909 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, &str, &str_len)
913 * Macro used to encode or decode printable string. The string type is
914 * unsigned char and string length SilcUInt32.
916 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
920 * The string must be in UTF-8 encoding when encoding. The decoded
921 * string will be in UTF-8 encoding. The actual data is encoded to
922 * or decoded from printable.
925 #define SILC_ASN1_PRINTABLE_STRING(x, xl) SILC_ASN1_U2(PRINTABLE_STRING, x, xl)
926 #define SILC_ASN1_PRINTABLE_STRING_T(o, t, x, xl) SILC_ASN1_T2(PRINTABLE_STRING, o, t, x, xl)
928 /****f* silcasn1/SilcASN1API/SILC_ASN1_TELETEX_STRING
933 * SILC_ASN1_TELETEX_STRING(str, str_len)
934 * SILC_ASN1_TELETEX_STRING_T(opts, tag, str, str_len)
937 * SILC_ASN1_TELETEX_STRING(&str, &str_len)
938 * SILC_ASN1_TELETEX_STRING_T(opts, tag, &str, &str_len)
942 * Macro used to encode or decode teletex (T61) string. The string type is
943 * unsigned char and string length SilcUInt32.
945 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
949 * The string must be in UTF-8 encoding when encoding. The decoded
950 * string will be in UTF-8 encoding. The actual data is encoded to
951 * or decoded from teletex (T61).
954 #define SILC_ASN1_TELETEX_STRING(x, xl) SILC_ASN1_U2(TELETEX_STRING, x, xl)
955 #define SILC_ASN1_TELETEX_STRING_T(o, t, x, xl) SILC_ASN1_T2(TELETEX_STRING, o, t, x, xl)
957 /****f* silcasn1/SilcASN1API/SILC_ASN1_IA5_STRING
962 * SILC_ASN1_IA5_STRING(str, str_len)
963 * SILC_ASN1_IA5_STRING_T(opts, tag, str, str_len)
966 * SILC_ASN1_IA5_STRING(&str, &str_len)
967 * SILC_ASN1_IA5_STRING_T(opts, tag, &str, &str_len)
971 * Macro used to encode or decode US ASCII (IA5) string. The string type
972 * is unsigned char and string length SilcUInt32.
974 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
978 * The string must be in UTF-8 encoding when encoding. The decoded
979 * string will be in UTF-8 encoding. The actual data is encoded to
980 * or decoded from US ASCII (IA5).
983 #define SILC_ASN1_IA5_STRING(x, xl) SILC_ASN1_U2(IA5_STRING, x, xl)
984 #define SILC_ASN1_IA5_STRING_T(o, t, x, xl) SILC_ASN1_T2(IA5_STRING, o, t, x, xl)
986 /****f* silcasn1/SilcASN1API/SILC_ASN1_VISIBLE_STRING
991 * SILC_ASN1_VISIBLE_STRING(str, str_len)
992 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, str, str_len)
995 * SILC_ASN1_VISIBLE_STRING(&str, &str_len)
996 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, &str, &str_len)
1000 * Macro used to encode or decode visible string. The string type is
1001 * unsigned char and string length SilcUInt32.
1003 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1007 * The string must be in UTF-8 encoding when encoding. The decoded
1008 * string will be in UTF-8 encoding. The actual data is encoded to
1009 * or decoded from visible.
1012 #define SILC_ASN1_VISIBLE_STRING(x, xl) SILC_ASN1_U2(VISIBLE_STRING, x, xl)
1013 #define SILC_ASN1_VISIBLE_STRING_T(o, t, x, xl) SILC_ASN1_T2(VISIBLE_STRING, o, t, x, xl)
1015 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNIVERSAL_STRING
1020 * SILC_ASN1_UNIVERSAL_STRING(str, str_len)
1021 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, str, str_len)
1024 * SILC_ASN1_UNIVERSAL_STRING(&str, &str_len)
1025 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, &str, &str_len)
1029 * Macro used to encode or decode universal (UCS-4) string. The string
1030 * type is unsigned char and string length SilcUInt32.
1032 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1036 * The string must be in UTF-8 encoding when encoding. The decoded
1037 * string will be in UTF-8 encoding. The actual data is encoded to
1038 * or decoded from universal (UCS-4).
1041 #define SILC_ASN1_UNIVERSAL_STRING(x, xl) SILC_ASN1_U2(UNIVERSAL_STRING, x, xl)
1042 #define SILC_ASN1_UNIVERSAL_STRING_T(o, t, x, xl) SILC_ASN1_T2(UNIVERSAL_STRING, o, t, x, xl)
1044 /****f* silcasn1/SilcASN1API/SILC_ASN1_BMP_STRING
1049 * SILC_ASN1_BMP_STRING(str, str_len)
1050 * SILC_ASN1_BMP_STRING_T(opts, tag, str, str_len)
1053 * SILC_ASN1_BMP_STRING(&str, &str_len)
1054 * SILC_ASN1_BMP_STRING_T(opts, tag, &str, &str_len)
1058 * Macro used to encode or decode BMP (UCS-2) string. The string type is
1059 * unsigned char and string length SilcUInt32.
1061 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1065 * The string must be in UTF-8 encoding when encoding. The decoded
1066 * string will be in UTF-8 encoding. The actual data is encoded to
1067 * or decoded from BMP (UCS-2)
1070 #define SILC_ASN1_BMP_STRING(x, xl) SILC_ASN1_U2(BMP_STRING, x, xl)
1071 #define SILC_ASN1_BMP_STRING_T(o, t, x, xl) SILC_ASN1_T2(BMP_STRING, o, t, x, xl)
1073 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNRESTRICTED_STRING
1078 * SILC_ASN1_UNRESTRICTED_STRING(str, str_len)
1079 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, str, str_len)
1082 * SILC_ASN1_UNRESTRICTED_STRING(&str, &str_len)
1083 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, &str, &str_len)
1087 * Macro used to encode or decode unrestricted string. The string type is
1088 * unsigned char and string length SilcUInt32.
1090 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1094 * The string must be in UTF-8 encoding when encoding. The decoded
1095 * string will be in UTF-8 encoding. The actual data is encoded to
1096 * or decoded from unrestricted. NOTE: this implementation use 8-bit ASCII.
1099 #define SILC_ASN1_UNRESTRICTED_STRING(x, xl) SILC_ASN1_U2(UNRESTRICTED_STRING, x, xl)
1100 #define SILC_ASN1_UNRESTRICTED_STRING_T(o, t, x, xl) SILC_ASN1_T2(UNRESTRICTED_STRING, o, t, x, xl)
1102 /****f* silcasn1/SilcASN1API/SILC_ASN1_GENERAL_STRING
1107 * SILC_ASN1_GENERAL_STRING(str, str_len)
1108 * SILC_ASN1_GENERAL_STRING_T(opts, tag, str, str_len)
1111 * SILC_ASN1_GENERAL_STRING(&str, &str_len)
1112 * SILC_ASN1_GENERAL_STRING_T(opts, tag, &str, &str_len)
1116 * Macro used to encode or decode general string. The string type is
1117 * unsigned char and string length SilcUInt32.
1119 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1123 * The string must be in UTF-8 encoding when encoding. The decoded
1124 * string will be in UTF-8 encoding. The actual data is encoded to
1125 * or decoded from general. NOTE: this implementation use 8-bit ASCII.
1128 #define SILC_ASN1_GENERAL_STRING(x, xl) SILC_ASN1_U2(GENERAL_STRING, x, xl)
1129 #define SILC_ASN1_GENERAL_STRING_T(o, t, x, xl) SILC_ASN1_T2(GENERAL_STRING, o, t, x, xl)
1131 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTC_TIME
1136 * SILC_ASN1_UTC_TIME(timeval)
1137 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1140 * SILC_ASN1_UTC_TIME(&str, &timeval)
1141 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval)
1145 * Macro used to encode or decode universal (UTC) time value. The
1146 * time value type is SilcTime.
1148 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1151 #define SILC_ASN1_UTC_TIME(x) SILC_ASN1_U1(UTC_TIME, x)
1152 #define SILC_ASN1_UTC_TIME_T(o, t, x) SILC_ASN1_T1(UTC_TIME, o, t, x)
1154 /****f* silcasn1/SilcASN1API/SILC_ASN1_GEN_TIME
1159 * SILC_ASN1_GEN_TIME(timeval)
1160 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1163 * SILC_ASN1_GEN_TIME(&str, &timeval)
1164 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval)
1168 * Macro used to encode or decode generalized time value. The
1169 * time value type is SilcTime.
1171 * The `opts' is SilcAsn1Options. The `tag' is a tag number.
1174 #define SILC_ASN1_GEN_TIME(x) SILC_ASN1_U1(GENERALIZED_TIME, x)
1175 #define SILC_ASN1_GEN_TIME_T(o, t, x) SILC_ASN1_T1(GENERALIZED_TIME, o, t, x)
1177 /****f* silcasn1/SilcASN1API/SILC_ASN1_END
1185 * The SILC_ASN1_END is used to terminate the variable argument list in
1186 * silc_asn1_encode and silc_asn1_decode functions. It is also used to
1187 * terminate SILC_ASN1_SEQUENCE, SILC_ASN1_SEQUENCE_T, SILC_ASN1_SET,
1188 * SILC_ASN1_SET_T, SILC_ASN1_SEQUENCE_OF, SILC_ASN1_SET_OF and
1189 * SILC_ASN1_CHOICE macros.
1192 #define SILC_ASN1_END 0
1194 #endif /* SILCASN1_H */