1 /* 2 3 silcasn1.h 4 5 Author: Pekka Riikonen <priikone@silcnet.org> 6 7 Copyright (C) 2003 - 2007 Pekka Riikonen 8 9 The contents of this file are subject to one of the Licenses specified 10 in the COPYING file; You may not use this file except in compliance 11 with the License. 12 13 The software distributed under the License is distributed on an "AS IS" 14 basis, in the hope that it will be useful, but WITHOUT WARRANTY OF ANY 15 KIND, either expressed or implied. See the COPYING file for more 16 information. 17 18 */ 19 20 /****h* silcasn1/ASN.1 Interface 21 * 22 * DESCRIPTION 23 * 24 * Efficient Abstract Syntax Notation One (ASN.1) implementation. This 25 * interface provides simple and efficient ASN.1 encoder and decoder. 26 * The encoder directly encodes BER encoded data blocks from variable 27 * argument list of ASN.1 types. Multiple trees can be encoded at once 28 * and multiple nodes can be encoded into the tree at once. By default 29 * encoder does not allocate any memory during encoding but a pre-allocated 30 * SilcStack is used as memory. 31 * 32 * The decoder directly decodes BER encoded data blocks into the correct 33 * types dictated by the variable argument list of ASN.1 types. By 34 * default decoder does not allocate any memory during decoding but a 35 * pre-allocated SilcStack is used as memory. 36 * 37 * The encoding and decoding interface is simple. silc_asn1_encode is used 38 * to encode and silc_asn1_decode to decode. The actual ASN.1 is defined 39 * as variable argument list to the function. Various macros can be used 40 * to encode and decode different ASN.1 types. All types may also be used 41 * to encode and decode with various options (such as implicit and explicit 42 * tagging and defining specific class option). 43 * 44 * The implementation supports all the common ASN.1 types. This 45 * implementation does not support advanced ASN.1 features like macros. 46 * 47 * References: ITU-T X.680 - X.693 48 * http://www.itu.int/ITU-T/studygroups/com17/languages/ 49 * 50 ***/ 51 52 #ifndef SILCASN1_H 53 #define SILCASN1_H 54 55 /****s* silcasn1/SilcASN1API/SilcAsn1 56 * 57 * NAME 58 * 59 * typedef struct SilcAsn1Object *SilcAsn1; 60 * 61 * DESCRIPTION 62 * 63 * This context is the actual ASN.1 encoder/decoder and is allocated 64 * by silc_asn1_alloc and given as argument to all silc_asn1_* 65 * functions. It is freed by the silc_asn1_free function. It is 66 * also possible to use pre-allocated ASN.1 context by using the 67 * SilcAsn1Struct instead of SilcAsn1. 68 * 69 ***/ 70 typedef struct SilcAsn1Object *SilcAsn1; 71 72 /****s* silcasn1/SilcASN1API/SilcAsn1Struct 73 * 74 * NAME 75 * 76 * typedef struct SilcAsn1Object SilcAsn1Struct; 77 * 78 * DESCRIPTION 79 * 80 * This context is the actual ASN.1 encoder/decoder and can be 81 * used as pre-allocated ASN.1 context instead of SilcAsn1 context. 82 * This context is initialized with silc_asn1_init and uninitialized 83 * with silc_asn1_uninit. 84 * 85 ***/ 86 typedef struct SilcAsn1Object SilcAsn1Struct; 87 88 /****d* silcasn1/SilcASN1API/SilcAsn1Options 89 * 90 * NAME 91 * 92 * typedef enum { ... } SilcAsn1Options; 93 * 94 * DESCRIPTION 95 * 96 * Options for ASN.1 encoder and decoder. The ASN.1 options can be 97 * given to the SILC_ASN1_*_T macros and/or SILC_ASN1_OPTS macro. 98 * 99 * NOTES 100 * 101 * The SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags can be given only 102 * with SILC_ASN1_OPTS macro. Other options can be given with various 103 * SILC_ASN1_*_T macros. 104 * 105 * EXAMPLE 106 * 107 * // Encodes boolean value with explicit tag and private class, and 108 * // the result is allocated into `dest'. 109 * silc_asn1_encode(asn1, &dest, 110 * SILC_ASN1_OPTS(SILC_ASN1_ALLOC), 111 * SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE | 112 * SILC_ASN1_EXPLICIT, 100, boolval), 113 * SILC_ASN1_END); 114 * 115 * SOURCE 116 */ 117 typedef enum { 118 /* Default. If only this is set then defaults are implied. */ 119 SILC_ASN1_DEFAULT = 0x0000, 120 121 /* Class options. User does not need to set these unless specificly 122 wanted to do so. If SILC_ASN1_DEFAULT is set the SILC_ASN1_CONTEXT is 123 implied if any of the tag options are set. Otherwise SILC_ASN1_UNIVERSAL 124 is implied. Only one of these can bet set at once. */ 125 SILC_ASN1_UNIVERSAL = 0x0001, /* Universal class (default) */ 126 SILC_ASN1_APP = 0x0002, /* Application specific class */ 127 SILC_ASN1_CONTEXT = 0x0003, /* Context specific class */ 128 SILC_ASN1_PRIVATE = 0x0004, /* Private class */ 129 130 /* Tag options (bitmask) */ 131 SILC_ASN1_IMPLICIT = 0x0010, /* Tag is implicit (default) */ 132 SILC_ASN1_EXPLICIT = 0x0020, /* Tag is explicit */ 133 SILC_ASN1_DEFINITE = 0x0040, /* Length is definite (default) */ 134 SILC_ASN1_INDEFINITE = 0x0080, /* Length is indefinite */ 135 136 /* Decoding options (bitmask) */ 137 SILC_ASN1_OPTIONAL = 0x0100, /* Zero or more may be found. The 138 argument must be pointer to the 139 type pointer so that NULL can be 140 returned if type is not found. */ 141 142 /* ASN.1 encoder/decoder options (bitmask). These can be given 143 only with SILC_ASN1_OPTS macro at the start of encoding/decoding. */ 144 SILC_ASN1_ALLOC = 0x0400, /* Dynamically allocate results */ 145 SILC_ASN1_ACCUMUL = 0x0800, /* Accumulate memory for results, 146 next call to silc_asn1_decode 147 will not cancel old results. */ 148 } SilcAsn1Options; 149 /***/ 150 151 /****d* silcasn1/SilcASN1API/SilcAsn1Tag 152 * 153 * NAME 154 * 155 * typedef enum { ... } SilcAsn1Tag; 156 * 157 * DESCRIPTION 158 * 159 * Universal ASN.1 tags. Usually these tags are given automatically 160 * to the silc_asn1_encode and silc_asn1_decode by using the various 161 * macros (such as SILC_ASN1_BOOLEAN). Some macros may take the tag 162 * as additional argument. 163 * 164 * SOURCE 165 */ 166 typedef enum { 167 SILC_ASN1_TAG_BOOLEAN = 1, /* SILC_ASN1_BOOLEAN */ 168 SILC_ASN1_TAG_INTEGER = 2, /* SILC_ASN1_INT */ 169 SILC_ASN1_TAG_BIT_STRING = 3, /* SILC_ASN1_BIT_STRING */ 170 SILC_ASN1_TAG_OCTET_STRING = 4, /* SILC_ASN1_OCTET_STRING */ 171 SILC_ASN1_TAG_NULL = 5, /* SILC_ASN1_NULL */ 172 SILC_ASN1_TAG_OID = 6, /* SILC_ASN1_OID */ 173 SILC_ASN1_TAG_ODE = 7, /* not supported */ 174 SILC_ASN1_TAG_ETI = 8, /* not supported */ 175 SILC_ASN1_TAG_REAL = 9, /* not supported */ 176 SILC_ASN1_TAG_ENUM = 10, /* SILC_ASN1_ENUM */ 177 SILC_ASN1_TAG_EMBEDDED = 11, /* not supported */ 178 SILC_ASN1_TAG_UTF8_STRING = 12, /* SILC_ASN1_UTF8_STRING */ 179 SILC_ASN1_TAG_ROI = 13, /* not supported */ 180 SILC_ASN1_TAG_SEQUENCE = 16, /* SILC_ASN1_SEQUENCE */ 181 SILC_ASN1_TAG_SET = 17, /* SILC_ASN1_SET */ 182 SILC_ASN1_TAG_NUMERIC_STRING = 18, /* SILC_ASN1_NUMERIC_STRING */ 183 SILC_ASN1_TAG_PRINTABLE_STRING = 19, /* SILC_ASN1_PRINTABLE_STRING */ 184 SILC_ASN1_TAG_TELETEX_STRING = 20, /* SILC_ASN1_TELETEX_STRING */ 185 SILC_ASN1_TAG_VIDEOTEX_STRING = 21, /* not supported */ 186 SILC_ASN1_TAG_IA5_STRING = 22, /* SILC_ASN1_IA5_STRING */ 187 SILC_ASN1_TAG_UTC_TIME = 23, /* SILC_ASN1_UTC_TIME */ 188 SILC_ASN1_TAG_GENERALIZED_TIME = 24, /* SILC_ASN1_GENERAL_STRING */ 189 SILC_ASN1_TAG_GRAPHIC_STRING = 25, /* not supported */ 190 SILC_ASN1_TAG_VISIBLE_STRING = 26, /* SILC_ASN1_VISIBLE_STRING */ 191 SILC_ASN1_TAG_GENERAL_STRING = 27, /* SILC_ASN1_GENERAL_STRING */ 192 SILC_ASN1_TAG_UNIVERSAL_STRING = 28, /* SILC_ASN1_UNIVERSAL_STRING */ 193 SILC_ASN1_TAG_UNRESTRICTED_STRING = 29, /* SILC_ASN1_UNRESTRICTED_STRING */ 194 SILC_ASN1_TAG_BMP_STRING = 30, /* SILC_ASN1_BMP_STRING */ 195 } SilcAsn1Tag; 196 /***/ 197 198 #include "silcasn1_i.h" 199 200 /****f* silcasn1/SilcASN1API/silc_asn1_alloc 201 * 202 * SYNOPSIS 203 * 204 * SilcAsn1 silc_asn1_alloc(void); 205 * 206 * DESCRIPTION 207 * 208 * Allocates and initializes ASN.1 encoder/decoder and returns SilcAsn1 209 * context or NULL on error. This context can be used with both 210 * silc_asn1_encode and silc_asn1_decode functions. 211 * 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 216 * and decoding. 217 * 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. 221 * 222 ***/ 223 SilcAsn1 silc_asn1_alloc(void); 224 225 /****f* silcasn1/SilcASN1API/silc_asn1_free 226 * 227 * SYNOPSIS 228 * 229 * void silc_asn1_free(SilcAsn1 asn1); 230 * 231 * DESCRIPTION 232 * 233 * Frees the SilcAsn1 context and all allocated memory. All encoded 234 * buffers and all decoded buffers with this context becomes invalid 235 * after this call. 236 * 237 ***/ 238 void silc_asn1_free(SilcAsn1 asn1); 239 240 /****f* silcasn1/SilcASN1API/silc_asn1_init 241 * 242 * SYNOPSIS 243 * 244 * SilcBool silc_asn1_init(SilcAsn1 asn1); 245 * 246 * DESCRIPTION 247 * 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. 251 * 252 * EXAMPLE 253 * 254 * SilcAsn1Struct asn1; 255 * if (!silc_asn1_init(&asn1)) 256 * error; 257 * 258 ***/ 259 SilcBool silc_asn1_init(SilcAsn1 asn1); 260 261 /****f* silcasn1/SilcASN1API/silc_asn1_uninit 262 * 263 * SYNOPSIS 264 * 265 * void silc_asn1_uninit(SilcAsn1 asn1); 266 * 267 * DESCRIPTION 268 * 269 * Uninitializes a pre-allocated SilcAsn1 context. Use this function 270 * instead of silc_asn1_free if you used silc_asn1_init. 271 * 272 ***/ 273 void silc_asn1_uninit(SilcAsn1 asn1); 274 275 /****f* silcasn1/SilcASN1API/silc_asn1_encode 276 * 277 * SYNOPSIS 278 * 279 * SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...); 280 * 281 * DESCRIPTION 282 * 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. 289 * 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 296 * result. 297 * 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. 301 * 302 * If encoding is successful this returns TRUE, FALSE on error. 303 * 304 * EXAMPLE 305 * 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), 312 * SILC_ASN1_END, 313 * SILC_ASN1_OCTET_STRING_T(0, 1, string2, string2_len), 314 * SILC_ASN1_END, SILC_ASN1_END); 315 * 316 * Creates ASN.1 tree that looks something like: 317 * 318 * buf ::= SEQUENCE { 319 * bool_val BOOLEAN, 320 * string OCTET-STRING, 321 * [2] SEQUENCE { 322 * foo [100] EXPLICIT BOOLEAN } 323 * string2 [1] OCTET-STRING } 324 * 325 ***/ 326 SilcBool silc_asn1_encode(SilcAsn1 asn1, SilcBuffer dest, ...); 327 328 /****f* silcasn1/SilcASN1API/silc_asn1_decode 329 * 330 * SYNOPSIS 331 * 332 * SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...); 333 * 334 * DESCRIPTION 335 * 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. 339 * 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. 351 * 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) 360 * applies. 361 * 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 364 * results by itself. 365 * 366 * EXAMPLE 367 * 368 * SilcBool bool_val, foo; 369 * unsigned char *string, string2; 370 * SilcUInt32 string_len, string2_len; 371 * 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), 378 * SILC_ASN1_END, 379 * SILC_ASN1_OCTET_STRING_T(0, 1, &str2, &str2_len), 380 * SILC_ASN1_END, SILC_ASN1_END); 381 * 382 ***/ 383 SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...); 384 385 /****f* silcasn1/SilcASN1API/SILC_ASN1_OPTS 386 * 387 * SYNOPSIS 388 * 389 * SILC_ASN1_OPTS(opts) 390 * 391 * DESCRIPTION 392 * 393 * The `opts' is SilcAsn1Options. This macro can be used to set 394 * options for silc_asn1_encode and silc_asn1_decode functions. 395 * 396 * NOTES 397 * 398 * Only the SILC_ASN1_ALLOC and SILC_ASN1_ACCUMUL flags may be 399 * set with this macro. 400 * 401 * This macro must be the first macro in the variable argument list 402 * in the function. 403 * 404 * EXAMPLE 405 * 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); 412 * 413 ***/ 414 #define SILC_ASN1_OPTS(opts) SILC_ASN1_TAG_OPTS, (opts) 415 416 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY 417 * 418 * SYNOPSIS 419 * 420 * Encoding: 421 * SILC_ASN1_ANY(buffer) 422 * SILC_ASN1_ANY_T(opts, tag, buffer) 423 * 424 * Decoding: 425 * SILC_ASN1_ANY(&buffer) 426 * SILC_ASN1_ANY_T(opts, tag, buffer) 427 * 428 * DESCRIPTION 429 * 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 433 * the buffers. 434 * 435 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 436 * 437 * EXAMPLE 438 * 439 * // Encode node of two boolean values 440 * silc_asn1_encode(asn1, node, 441 * SILC_ASN1_BOOLEAN(val1), 442 * SILC_ASN1_BOOLEAN(val2), 443 * SILC_ASN1_END); 444 * 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); 451 * 452 ***/ 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) 455 456 /****f* silcasn1/SilcASN1API/SILC_ASN1_ANY_PRIMITIVE 457 * 458 * SYNOPSIS 459 * 460 * Encoding: 461 * SILC_ASN1_ANY_PRIMITIVE(tag, buffer) 462 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer) 463 * 464 * Decoding: 465 * SILC_ASN1_ANY_PRIMITIVE(tag, &buffer) 466 * SILC_ASN1_ANY_PRIMITIVE_T(opts, tag, buffer) 467 * 468 * DESCRIPTION 469 * 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. 475 * 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. 480 * 481 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 482 * 483 * EXAMPLE 484 * 485 * // Get MP integer in encoded format 486 * mpbuf = mp_get_octet_string(mp); 487 * 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), 491 * SILC_ASN1_END); 492 * 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), 496 * SILC_ASN1_END); 497 * 498 ***/ 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) 501 502 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE 503 * 504 * SYNOPSIS 505 * 506 * Encoding: 507 * SILC_ASN1_SEQUENCE 508 * SILC_ASN1_SEQUENCE_T(opts, tag) 509 * 510 * Decoding: 511 * SILC_ASN1_SEQUENCE 512 * SILC_ASN1_SEQUENCE_T(opts, tag) 513 * 514 * DESCRIPTION 515 * 516 * Macro used to encode or decode sequence. The sequence must be 517 * terminated with SILC_ASN1_END. 518 * 519 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 520 * 521 * EXAMPLE 522 * 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); 528 * 529 ***/ 530 #define SILC_ASN1_SEQUENCE SILC_ASN1_U0(SEQUENCE) 531 #define SILC_ASN1_SEQUENCE_T(o, t) SILC_ASN1_T0(SEQUENCE, o, t) 532 533 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET 534 * 535 * SYNOPSIS 536 * 537 * Encoding: 538 * SILC_ASN1_SET 539 * SILC_ASN1_SET_T(opts, tag) 540 * 541 * Decoding: 542 * SILC_ASN1_SET 543 * SILC_ASN1_SET_T(opts, tag) 544 * 545 * DESCRIPTION 546 * 547 * Macro used to encode or decode set. The set must be terminated 548 * with SILC_ASN1_END. 549 * 550 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 551 * 552 * EXAMPLE 553 * 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); 558 * 559 ***/ 560 #define SILC_ASN1_SET SILC_ASN1_U0(SET) 561 #define SILC_ASN1_SET_T(o, t) SILC_ASN1_T0(SET, o, t) 562 563 /****f* silcasn1/SilcASN1API/SILC_ASN1_SEQUENCE_OF 564 * 565 * SYNOPSIS 566 * 567 * Decoding: 568 * SILC_ASN1_SEQUENCE_OF(bufarray, numbufs) 569 * 570 * DESCRIPTION 571 * 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. 575 * 576 * NOTES 577 * 578 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL 579 * flags. Do not use this macro without flags. 580 * 581 * EXAMPLE 582 * 583 * SilcBuffer bufs; 584 * SilcUInt32 count; 585 * 586 * // Decode sequence of sequences. Each returned buffer in the array 587 * // is a sequence. 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); 593 * 594 ***/ 595 #define SILC_ASN1_SEQUENCE_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c) 596 597 /****f* silcasn1/SilcASN1API/SILC_ASN1_SET_OF 598 * 599 * SYNOPSIS 600 * 601 * Decoding: 602 * SILC_ASN1_SET_OF(bufarray, numbufs) 603 * 604 * DESCRIPTION 605 * 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. 609 * 610 * NOTES 611 * 612 * This macro must be used either with SILC_ASN1_ALLOC or SILC_ASN1_ACCUMUL 613 * flags. Do not use this macro without flags. 614 * 615 * EXAMPLE 616 * 617 * // Decode set of sequences. Each returned buffer in the array 618 * // is a sequence. 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); 624 * 625 ***/ 626 #define SILC_ASN1_SET_OF(x, c) SILC_ASN1_U2(SEQUENCE_OF, x, c) 627 628 /****f* silcasn1/SilcASN1API/SILC_ASN1_CHOICE 629 * 630 * SYNOPSIS 631 * 632 * Decoding: 633 * SILC_ASN1_CHOICE 634 * 635 * DESCRIPTION 636 * 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. 640 * 641 * EXAMPLE 642 * 643 * // Decode timeval that is either UTC or generalized time 644 * silc_asn1_decode(asn1, tree, 645 * SILC_ASN1_SEQUENCE, 646 * SILC_ASN1_CHOICE, 647 * SILC_ASN1_UTC_TIME(&timeval), 648 * SILC_ASN1_GEN_TIME(&timeval), 649 * SILC_ASN1_END, 650 * SILC_ASN1_END, SILC_ASN1_END); 651 * 652 ***/ 653 #define SILC_ASN1_CHOICE SILC_ASN1_U0(CHOICE) 654 655 /****f* silcasn1/SilcASN1API/SILC_ASN1_BOOLEAN 656 * 657 * SYNOPSIS 658 * 659 * Encoding: 660 * SILC_ASN1_BOOLEAN(boolval) 661 * SILC_ASN1_BOOLEAN_T(opts, tag, boolval) 662 * 663 * Decoding: 664 * SILC_ASN1_BOOLEAN(&boolval) 665 * SILC_ASN1_BOOLEAN_T(opts, tag, &boolval) 666 * 667 * DESCRIPTION 668 * 669 * Macro used to encode or decode boolean value. The boolean type 670 * is SilcBool. 671 * 672 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 673 * 674 ***/ 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) 677 678 /****f* silcasn1/SilcASN1API/SILC_ASN1_INT 679 * 680 * SYNOPSIS 681 * 682 * Encoding: 683 * SILC_ASN1_INT(integer) 684 * SILC_ASN1_INT_T(opts, tag, &integer) 685 * 686 * Decoding: 687 * SILC_ASN1_INT(&integer) 688 * SILC_ASN1_INT_T(opts, tag, &integer); 689 * 690 * DESCRIPTION 691 * 692 * Macro used to encode or decode multiple precision integer. The 693 * integer type is SilcMPInt. 694 * 695 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 696 * 697 ***/ 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) 700 701 /****f* silcasn1/SilcASN1API/SILC_ASN1_SHORT_INT 702 * 703 * SYNOPSIS 704 * 705 * Encoding: 706 * SILC_ASN1_SHORT_INT(integer) 707 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer) 708 * 709 * Decoding: 710 * SILC_ASN1_SHORT_INT(&integer) 711 * SILC_ASN1_SHORT_INT_T(opts, tag, &integer); 712 * 713 * DESCRIPTION 714 * 715 * Macro used to encode or decode short integer (32 bits). The 716 * integer type is SilcUInt32. 717 * 718 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 719 * 720 ***/ 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) 723 724 /****f* silcasn1/SilcASN1API/SILC_ASN1_ENUM 725 * 726 * SYNOPSIS 727 * 728 * Encoding: 729 * SILC_ASN1_ENUM(enum) 730 * SILC_ASN1_ENUM_T(opts, tag, &enum) 731 * 732 * Decoding: 733 * SILC_ASN1_ENUM(&enum) 734 * SILC_ASN1_ENUM_T(opts, tag, &enum); 735 * 736 * DESCRIPTION 737 * 738 * Macro used to encode or decode enumeration value. The enumeration 739 * type is SilcMPInt. 740 * 741 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 742 * 743 ***/ 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) 746 747 /****f* silcasn1/SilcASN1API/SILC_ASN1_BIT_STRING 748 * 749 * SYNOPSIS 750 * 751 * Encoding: 752 * SILC_ASN1_BIT_STRING(str, str_len) 753 * SILC_ASN1_BIT_STRING_T(opts, tag, str, str_len) 754 * 755 * Decoding: 756 * SILC_ASN1_BIT_STRING(&str, &str_len) 757 * SILC_ASN1_BIT_STRING_T(opts, tag, &str, &str_len) 758 * 759 * DESCRIPTION 760 * 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 764 * SilcUInt32. 765 * 766 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 767 * 768 ***/ 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) 771 772 /****f* silcasn1/SilcASN1API/SILC_ASN1_NULL 773 * 774 * SYNOPSIS 775 * 776 * Encoding: 777 * SILC_ASN1_NULL 778 * SILC_ASN1_NULL_T(opts, tag) 779 * 780 * Decoding: 781 * SILC_ASN1_NULL 782 * SILC_ASN1_NULL_T(opts, tag) 783 * 784 * DESCRIPTION 785 * 786 * Macro used to encode or decode null value. 787 * 788 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 789 * 790 ***/ 791 #define SILC_ASN1_NULL SILC_ASN1_U0(NULL) 792 #define SILC_ASN1_NULL_T(o, t) SILC_ASN1_T0(NULL, 0, t) 793 794 /****f* silcasn1/SilcASN1API/SILC_ASN1_OID 795 * 796 * SYNOPSIS 797 * 798 * Encoding: 799 * SILC_ASN1_OID(oid) 800 * SILC_ASN1_OID_T(opts, tag, oid) 801 * 802 * Decoding: 803 * SILC_ASN1_OID(&oid) 804 * SILC_ASN1_OID_T(opts, tag, &oid) 805 * 806 * DESCRIPTION 807 * 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(). 810 * 811 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 812 * 813 ***/ 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) 816 817 /****f* silcasn1/SilcASN1API/SILC_ASN1_OCTET_STRING 818 * 819 * SYNOPSIS 820 * 821 * Encoding: 822 * SILC_ASN1_OCTET_STRING(str, str_len) 823 * SILC_ASN1_OCTET_STRING_T(opts, tag, str, str_len) 824 * 825 * Decoding: 826 * SILC_ASN1_OCTET_STRING(&str, &str_len) 827 * SILC_ASN1_OCTET_STRING_T(opts, tag, &str, &str_len) 828 * 829 * DESCRIPTION 830 * 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. 834 * 835 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 836 * 837 ***/ 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) 840 841 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTF8_STRING 842 * 843 * SYNOPSIS 844 * 845 * Encoding: 846 * SILC_ASN1_UTF8_STRING(str, str_len) 847 * SILC_ASN1_UTF8_STRING_T(opts, tag, str, str_len) 848 * 849 * Decoding: 850 * SILC_ASN1_UTF8_STRING(&str, &str_len) 851 * SILC_ASN1_UTF8_STRING_T(opts, tag, &str, &str_len) 852 * 853 * DESCRIPTION 854 * 855 * Macro used to encode or decode UTF-8 string. The string type is 856 * unsigned char and string length SilcUInt32. 857 * 858 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 859 * 860 * NOTES 861 * 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. 865 * 866 ***/ 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) 869 870 /****f* silcasn1/SilcASN1API/SILC_ASN1_NUMERIC_STRING 871 * 872 * SYNOPSIS 873 * 874 * Encoding: 875 * SILC_ASN1_NUMERIC_STRING(str, str_len) 876 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, str, str_len) 877 * 878 * Decoding: 879 * SILC_ASN1_NUMERIC_STRING(&str, &str_len) 880 * SILC_ASN1_NUMERIC_STRING_T(opts, tag, &str, &str_len) 881 * 882 * DESCRIPTION 883 * 884 * Macro used to encode or decode numerical string. The string type is 885 * unsigned char and string length SilcUInt32. 886 * 887 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 888 * 889 * NOTES 890 * 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. 894 * 895 ***/ 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) 898 899 /****f* silcasn1/SilcASN1API/SILC_ASN1_PRINTABLE_STRING 900 * 901 * SYNOPSIS 902 * 903 * Encoding: 904 * SILC_ASN1_PRINTABLE_STRING(str, str_len) 905 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, str, str_len) 906 * 907 * Decoding: 908 * SILC_ASN1_PRINTABLE_STRING(&str, &str_len) 909 * SILC_ASN1_PRINTABLE_STRING_T(opts, tag, &str, &str_len) 910 * 911 * DESCRIPTION 912 * 913 * Macro used to encode or decode printable string. The string type is 914 * unsigned char and string length SilcUInt32. 915 * 916 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 917 * 918 * NOTES 919 * 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. 923 * 924 ***/ 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) 927 928 /****f* silcasn1/SilcASN1API/SILC_ASN1_TELETEX_STRING 929 * 930 * SYNOPSIS 931 * 932 * Encoding: 933 * SILC_ASN1_TELETEX_STRING(str, str_len) 934 * SILC_ASN1_TELETEX_STRING_T(opts, tag, str, str_len) 935 * 936 * Decoding: 937 * SILC_ASN1_TELETEX_STRING(&str, &str_len) 938 * SILC_ASN1_TELETEX_STRING_T(opts, tag, &str, &str_len) 939 * 940 * DESCRIPTION 941 * 942 * Macro used to encode or decode teletex (T61) string. The string type is 943 * unsigned char and string length SilcUInt32. 944 * 945 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 946 * 947 * NOTES 948 * 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). 952 * 953 ***/ 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) 956 957 /****f* silcasn1/SilcASN1API/SILC_ASN1_IA5_STRING 958 * 959 * SYNOPSIS 960 * 961 * Encoding: 962 * SILC_ASN1_IA5_STRING(str, str_len) 963 * SILC_ASN1_IA5_STRING_T(opts, tag, str, str_len) 964 * 965 * Decoding: 966 * SILC_ASN1_IA5_STRING(&str, &str_len) 967 * SILC_ASN1_IA5_STRING_T(opts, tag, &str, &str_len) 968 * 969 * DESCRIPTION 970 * 971 * Macro used to encode or decode US ASCII (IA5) string. The string type 972 * is unsigned char and string length SilcUInt32. 973 * 974 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 975 * 976 * NOTES 977 * 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). 981 * 982 ***/ 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) 985 986 /****f* silcasn1/SilcASN1API/SILC_ASN1_VISIBLE_STRING 987 * 988 * SYNOPSIS 989 * 990 * Encoding: 991 * SILC_ASN1_VISIBLE_STRING(str, str_len) 992 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, str, str_len) 993 * 994 * Decoding: 995 * SILC_ASN1_VISIBLE_STRING(&str, &str_len) 996 * SILC_ASN1_VISIBLE_STRING_T(opts, tag, &str, &str_len) 997 * 998 * DESCRIPTION 999 * 1000 * Macro used to encode or decode visible string. The string type is 1001 * unsigned char and string length SilcUInt32. 1002 * 1003 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1004 * 1005 * NOTES 1006 * 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. 1010 * 1011 ***/ 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) 1014 1015 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNIVERSAL_STRING 1016 * 1017 * SYNOPSIS 1018 * 1019 * Encoding: 1020 * SILC_ASN1_UNIVERSAL_STRING(str, str_len) 1021 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, str, str_len) 1022 * 1023 * Decoding: 1024 * SILC_ASN1_UNIVERSAL_STRING(&str, &str_len) 1025 * SILC_ASN1_UNIVERSAL_STRING_T(opts, tag, &str, &str_len) 1026 * 1027 * DESCRIPTION 1028 * 1029 * Macro used to encode or decode universal (UCS-4) string. The string 1030 * type is unsigned char and string length SilcUInt32. 1031 * 1032 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1033 * 1034 * NOTES 1035 * 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). 1039 * 1040 ***/ 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) 1043 1044 /****f* silcasn1/SilcASN1API/SILC_ASN1_BMP_STRING 1045 * 1046 * SYNOPSIS 1047 * 1048 * Encoding: 1049 * SILC_ASN1_BMP_STRING(str, str_len) 1050 * SILC_ASN1_BMP_STRING_T(opts, tag, str, str_len) 1051 * 1052 * Decoding: 1053 * SILC_ASN1_BMP_STRING(&str, &str_len) 1054 * SILC_ASN1_BMP_STRING_T(opts, tag, &str, &str_len) 1055 * 1056 * DESCRIPTION 1057 * 1058 * Macro used to encode or decode BMP (UCS-2) string. The string type is 1059 * unsigned char and string length SilcUInt32. 1060 * 1061 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1062 * 1063 * NOTES 1064 * 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) 1068 * 1069 ***/ 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) 1072 1073 /****f* silcasn1/SilcASN1API/SILC_ASN1_UNRESTRICTED_STRING 1074 * 1075 * SYNOPSIS 1076 * 1077 * Encoding: 1078 * SILC_ASN1_UNRESTRICTED_STRING(str, str_len) 1079 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, str, str_len) 1080 * 1081 * Decoding: 1082 * SILC_ASN1_UNRESTRICTED_STRING(&str, &str_len) 1083 * SILC_ASN1_UNRESTRICTED_STRING_T(opts, tag, &str, &str_len) 1084 * 1085 * DESCRIPTION 1086 * 1087 * Macro used to encode or decode unrestricted string. The string type is 1088 * unsigned char and string length SilcUInt32. 1089 * 1090 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1091 * 1092 * NOTES 1093 * 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. 1097 * 1098 ***/ 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) 1101 1102 /****f* silcasn1/SilcASN1API/SILC_ASN1_GENERAL_STRING 1103 * 1104 * SYNOPSIS 1105 * 1106 * Encoding: 1107 * SILC_ASN1_GENERAL_STRING(str, str_len) 1108 * SILC_ASN1_GENERAL_STRING_T(opts, tag, str, str_len) 1109 * 1110 * Decoding: 1111 * SILC_ASN1_GENERAL_STRING(&str, &str_len) 1112 * SILC_ASN1_GENERAL_STRING_T(opts, tag, &str, &str_len) 1113 * 1114 * DESCRIPTION 1115 * 1116 * Macro used to encode or decode general string. The string type is 1117 * unsigned char and string length SilcUInt32. 1118 * 1119 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1120 * 1121 * NOTES 1122 * 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. 1126 * 1127 ***/ 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) 1130 1131 /****f* silcasn1/SilcASN1API/SILC_ASN1_UTC_TIME 1132 * 1133 * SYNOPSIS 1134 * 1135 * Encoding: 1136 * SILC_ASN1_UTC_TIME(timeval) 1137 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval) 1138 * 1139 * Decoding: 1140 * SILC_ASN1_UTC_TIME(&str, &timeval) 1141 * SILC_ASN1_UTC_TIME_T(opts, tag, timeval) 1142 * 1143 * DESCRIPTION 1144 * 1145 * Macro used to encode or decode universal (UTC) time value. The 1146 * time value type is SilcTime. 1147 * 1148 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1149 * 1150 ***/ 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) 1153 1154 /****f* silcasn1/SilcASN1API/SILC_ASN1_GEN_TIME 1155 * 1156 * SYNOPSIS 1157 * 1158 * Encoding: 1159 * SILC_ASN1_GEN_TIME(timeval) 1160 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval) 1161 * 1162 * Decoding: 1163 * SILC_ASN1_GEN_TIME(&str, &timeval) 1164 * SILC_ASN1_GEN_TIME_T(opts, tag, timeval) 1165 * 1166 * DESCRIPTION 1167 * 1168 * Macro used to encode or decode generalized time value. The 1169 * time value type is SilcTime. 1170 * 1171 * The `opts' is SilcAsn1Options. The `tag' is a tag number. 1172 * 1173 ***/ 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) 1176 1177 /****f* silcasn1/SilcASN1API/SILC_ASN1_END 1178 * 1179 * SYNOPSIS 1180 * 1181 * SILC_ASN1_END 1182 * 1183 * DESCRIPTION 1184 * 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. 1190 * 1191 ***/ 1192 #define SILC_ASN1_END 0 1193 1194 #endif /* SILCASN1_H */ 1195