4 silc_asn1_encode(asn1, node,
5 SILC_ASN1_BOOLEAN(SilcBool),
7 silc_asn1_encode(asn1, dest,
8 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
9 SILC_ASN1_SEQUENCE_T(0, 9),
11 SILC_ASN1_ANY_T(0, 33, node),
12 SILC_ASN1_BOOLEAN_T(0, 4, boolv),
13 SILC_ASN1_BOOLEAN(SilcBool),
18 FATAL ERROR: Adding primitive node with implicit tagging is not possible.
19 The node either must be constructed (SEQUENCE or SET), or the tagging
20 must be explicit (in which case end result is same).
25 silc_asn1_encode(asn1, node,
26 SILC_ASN1_BOOLEAN(SilcBool),
28 silc_asn1_encode(asn1, dest,
29 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
30 SILC_ASN1_SEQUENCE_T(0, 9),
32 SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, node),
33 SILC_ASN1_BOOLEAN_T(0, 4, boolv),
34 SILC_ASN1_BOOLEAN(SilcBool),
39 CORRECT: the tagging is now explicit. Also note that tagging primitive
40 node explicitly is analougous of having a constructed node and tagging
41 that implicitly: the end result is same.
46 int main(int argc, char **argv)
48 SilcBufferStruct node, node2;
50 SilcBool success = FALSE;
54 SilcUInt32 str_len, tmpint;
57 SilcMPInt mpint, mpint2;
60 memset(&node, 0, sizeof(node));
61 memset(&node2, 0, sizeof(node2));
63 if (argc > 1 && !strcmp(argv[1], "-d")) {
65 silc_log_debug_hexdump(TRUE);
66 silc_log_set_debug_string("*asn1*,*ber*,*stack*");
69 silc_hash_register_default();
70 rng = silc_rng_alloc();
73 stack = silc_stack_alloc(0, NULL);
75 SILC_LOG_DEBUG(("Allocating ASN.1 context"));
76 asn1 = silc_asn1_alloc(stack);
80 SILC_LOG_DEBUG(("Encoding ASN.1 tree 1"));
83 silc_asn1_encode(asn1, &node,
85 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
86 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
87 SILC_ASN1_INDEFINITE, 0),
88 SILC_ASN1_BOOLEAN_T(0, 4, val),
89 SILC_ASN1_BOOLEAN(val),
92 SILC_ASN1_END, SILC_ASN1_END);
94 SILC_LOG_DEBUG(("Encoding failed"));
97 SILC_LOG_DEBUG(("Encoding success"));
98 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
99 SILC_LOG_DEBUG(("Decoding ASN.1 tree 1"));
101 silc_asn1_decode(asn1, &node,
103 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
104 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
105 SILC_ASN1_INDEFINITE, 0),
106 SILC_ASN1_BOOLEAN_T(0, 4, &val),
107 SILC_ASN1_BOOLEAN(&val),
110 SILC_ASN1_END, SILC_ASN1_END);
112 SILC_LOG_DEBUG(("Decoding failed"));
115 SILC_LOG_DEBUG(("Decoding success"));
116 SILC_LOG_DEBUG(("Boolean val %d", val));
119 memset(&node, 0, sizeof(node));
120 SILC_LOG_DEBUG(("Encoding ASN.1 tree 1"));
123 silc_asn1_encode(asn1, &node,
125 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
126 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
127 SILC_ASN1_INDEFINITE, 0),
128 SILC_ASN1_BOOLEAN_T(0, 4, val),
129 SILC_ASN1_BOOLEAN(val),
132 SILC_ASN1_END, SILC_ASN1_END);
134 SILC_LOG_DEBUG(("Encoding failed"));
137 SILC_LOG_DEBUG(("Encoding success"));
138 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
139 SILC_LOG_DEBUG(("Decoding ASN.1 tree 1"));
141 silc_asn1_decode(asn1, &node,
143 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
144 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
145 SILC_ASN1_INDEFINITE, 0),
146 SILC_ASN1_BOOLEAN_T(0, 4, &val),
147 SILC_ASN1_BOOLEAN(&val),
150 SILC_ASN1_END, SILC_ASN1_END);
152 SILC_LOG_DEBUG(("Decoding failed"));
155 SILC_LOG_DEBUG(("Decoding success"));
156 SILC_LOG_DEBUG(("Boolean val %d", val));
160 memset(&node, 0, sizeof(node));
161 SILC_LOG_DEBUG(("Encoding ASN.1 tree 2"));
164 silc_asn1_encode(asn1, &node,
166 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
167 SILC_ASN1_SEQUENCE_T(SILC_ASN1_INDEFINITE, 0),
168 SILC_ASN1_BOOLEAN_T(0, 4, val),
169 SILC_ASN1_BOOLEAN(val),
172 SILC_ASN1_END, SILC_ASN1_END);
174 SILC_LOG_DEBUG(("Encoding failed"));
177 SILC_LOG_DEBUG(("Encoding success"));
178 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
179 SILC_LOG_DEBUG(("Decoding ASN.1 tree 2"));
181 silc_asn1_decode(asn1, &node,
183 SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
184 SILC_ASN1_SEQUENCE_T(SILC_ASN1_INDEFINITE, 0),
185 SILC_ASN1_BOOLEAN_T(0, 4, &val),
186 SILC_ASN1_BOOLEAN(&val),
189 SILC_ASN1_END, SILC_ASN1_END);
191 SILC_LOG_DEBUG(("Decoding failed"));
194 SILC_LOG_DEBUG(("Decoding success"));
195 SILC_LOG_DEBUG(("Boolean val %d", val));
199 memset(&node, 0, sizeof(node));
200 SILC_LOG_DEBUG(("Encoding ASN.1 tree 3"));
203 silc_asn1_encode(asn1, &node,
205 SILC_ASN1_SEQUENCE_T(0, 9),
207 SILC_ASN1_BOOLEAN_T(0, 4, val),
208 SILC_ASN1_BOOLEAN(val),
211 SILC_ASN1_END, SILC_ASN1_END);
213 SILC_LOG_DEBUG(("Encoding failed"));
216 SILC_LOG_DEBUG(("Encoding success"));
217 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
218 SILC_LOG_DEBUG(("Decoding ASN.1 tree 3"));
220 silc_asn1_decode(asn1, &node,
222 SILC_ASN1_SEQUENCE_T(0, 9),
224 SILC_ASN1_BOOLEAN_T(0, 4, &val),
225 SILC_ASN1_BOOLEAN(&val),
228 SILC_ASN1_END, SILC_ASN1_END);
230 SILC_LOG_DEBUG(("Decoding failed"));
233 SILC_LOG_DEBUG(("Decoding success"));
234 SILC_LOG_DEBUG(("Boolean val %d", val));
238 memset(&node, 0, sizeof(node));
239 SILC_LOG_DEBUG(("Encoding ASN.1 tree 4"));
242 silc_asn1_encode(asn1, &node,
243 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
244 SILC_ASN1_EXPLICIT, 101),
245 SILC_ASN1_SEQUENCE_T(0, 9),
247 SILC_ASN1_BOOLEAN_T(0, 4, val),
248 SILC_ASN1_BOOLEAN(val),
251 SILC_ASN1_END, SILC_ASN1_END);
253 SILC_LOG_DEBUG(("Encoding failed"));
256 SILC_LOG_DEBUG(("Encoding success"));
257 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
258 SILC_LOG_DEBUG(("Decoding ASN.1 tree 4"));
260 silc_asn1_decode(asn1, &node,
261 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
262 SILC_ASN1_EXPLICIT, 101),
263 SILC_ASN1_SEQUENCE_T(0, 9),
265 SILC_ASN1_BOOLEAN_T(0, 4, &val),
266 SILC_ASN1_BOOLEAN(&val),
269 SILC_ASN1_END, SILC_ASN1_END);
271 SILC_LOG_DEBUG(("Decoding failed"));
274 SILC_LOG_DEBUG(("Decoding success"));
275 SILC_LOG_DEBUG(("Boolean val %d", val));
279 memset(&node, 0, sizeof(node));
280 SILC_LOG_DEBUG(("Encoding ASN.1 tree 5"));
282 silc_asn1_encode(asn1, &node2,
283 SILC_ASN1_BOOLEAN(val),
285 SILC_LOG_DEBUG(("Encoding success"));
287 silc_asn1_encode(asn1, &node,
288 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
289 SILC_ASN1_SEQUENCE_T(0, 9),
291 SILC_ASN1_ANY(&node2),
292 SILC_ASN1_BOOLEAN_T(0, 4, val),
293 SILC_ASN1_BOOLEAN(val),
296 SILC_ASN1_END, SILC_ASN1_END);
298 SILC_LOG_DEBUG(("Encoding failed"));
301 SILC_LOG_DEBUG(("Encoding success"));
302 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
303 memset(&node2, 0, sizeof(node2));
304 SILC_LOG_DEBUG(("Decoding ASN.1 tree 5"));
306 silc_asn1_decode(asn1, &node,
307 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
308 SILC_ASN1_SEQUENCE_T(0, 9),
310 SILC_ASN1_ANY(&node2),
311 SILC_ASN1_BOOLEAN_T(0, 4, &val),
312 SILC_ASN1_BOOLEAN(&val),
315 SILC_ASN1_END, SILC_ASN1_END);
317 SILC_LOG_DEBUG(("Decoding failed"));
320 SILC_LOG_DEBUG(("Decoding success"));
321 SILC_LOG_DEBUG(("Boolean val %d", val));
323 silc_asn1_decode(asn1, &node2,
324 SILC_ASN1_BOOLEAN(&val),
327 SILC_LOG_DEBUG(("Decoding failed"));
330 SILC_LOG_DEBUG(("Decoding success"));
331 SILC_LOG_DEBUG(("Boolean val %d", val));
332 memset(&node2, 0, sizeof(node2));
336 memset(&node, 0, sizeof(node));
337 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
338 memset(tmp, 0, sizeof(tmp));
340 silc_buffer_set(&node2, tmp, 1);
341 SILC_LOG_DEBUG(("Encoding success"));
343 silc_asn1_encode(asn1, &node,
345 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
347 SILC_ASN1_END, SILC_ASN1_END);
349 SILC_LOG_DEBUG(("Encoding failed"));
352 SILC_LOG_DEBUG(("Encoding success"));
353 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
354 memset(&node2, 0, sizeof(node2));
355 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
357 silc_asn1_decode(asn1, &node,
359 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
361 SILC_ASN1_END, SILC_ASN1_END);
363 SILC_LOG_DEBUG(("Decoding failed"));
366 SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
367 if (node2.data[0] != 0xff) {
368 SILC_LOG_DEBUG(("Decoding failed"));
371 SILC_LOG_DEBUG(("Decoding success"));
372 memset(&node, 0, sizeof(node));
373 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
374 memset(tmp, 0, sizeof(tmp));
376 silc_buffer_set(&node2, tmp, 1);
377 SILC_LOG_DEBUG(("Encoding success"));
379 silc_asn1_encode(asn1, &node,
381 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
383 SILC_ASN1_END, SILC_ASN1_END);
385 SILC_LOG_DEBUG(("Encoding failed"));
388 SILC_LOG_DEBUG(("Encoding success"));
389 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
390 memset(&node2, 0, sizeof(node2));
391 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
393 silc_asn1_decode(asn1, &node,
395 SILC_ASN1_BOOLEAN(&val),
396 SILC_ASN1_END, SILC_ASN1_END);
398 SILC_LOG_DEBUG(("Decoding failed"));
401 SILC_LOG_DEBUG(("Decoding success"));
402 SILC_LOG_DEBUG(("Boolean val %d", val));
403 memset(&node, 0, sizeof(node));
404 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
405 memset(tmp, 0, sizeof(tmp));
407 silc_buffer_set(&node2, tmp, 1);
408 SILC_LOG_DEBUG(("Encoding success"));
410 silc_asn1_encode(asn1, &node,
412 SILC_ASN1_BOOLEAN(val),
413 SILC_ASN1_END, SILC_ASN1_END);
415 SILC_LOG_DEBUG(("Encoding failed"));
418 SILC_LOG_DEBUG(("Encoding success"));
419 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
420 memset(&node2, 0, sizeof(node2));
421 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
423 silc_asn1_decode(asn1, &node,
425 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
427 SILC_ASN1_END, SILC_ASN1_END);
429 SILC_LOG_DEBUG(("Decoding failed"));
432 SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
433 if (node2.data[0] != 0xff) {
434 SILC_LOG_DEBUG(("Decoding failed"));
437 SILC_LOG_DEBUG(("Decoding success"));
438 memset(&node2, 0, sizeof(node2));
442 memset(&node, 0, sizeof(node));
443 SILC_LOG_DEBUG(("Encoding ASN.1 tree 6"));
445 silc_asn1_encode(asn1, &node2,
446 SILC_ASN1_BOOLEAN(val),
448 SILC_LOG_DEBUG(("Encoding success"));
450 silc_asn1_encode(asn1, &node,
451 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
452 SILC_ASN1_SEQUENCE_T(0, 9),
454 SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
455 SILC_ASN1_BOOLEAN_T(0, 4, val),
456 SILC_ASN1_BOOLEAN(val),
459 SILC_ASN1_END, SILC_ASN1_END);
461 SILC_LOG_DEBUG(("Encoding failed"));
464 SILC_LOG_DEBUG(("Encoding success"));
465 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
466 memset(&node2, 0, sizeof(node2));
467 SILC_LOG_DEBUG(("Decoding ASN.1 tree 6"));
469 silc_asn1_decode(asn1, &node,
470 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
471 SILC_ASN1_SEQUENCE_T(0, 9),
473 SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
474 SILC_ASN1_BOOLEAN_T(0, 4, &val),
475 SILC_ASN1_BOOLEAN(&val),
478 SILC_ASN1_END, SILC_ASN1_END);
480 SILC_LOG_DEBUG(("Decoding failed"));
483 SILC_LOG_DEBUG(("Decoding success"));
484 SILC_LOG_DEBUG(("Boolean val %d", val));
486 silc_asn1_decode(asn1, &node2,
487 SILC_ASN1_BOOLEAN(&val),
490 SILC_LOG_DEBUG(("Decoding failed"));
493 SILC_LOG_DEBUG(("Decoding success"));
494 SILC_LOG_DEBUG(("Boolean val %d", val));
495 memset(&node2, 0, sizeof(node2));
499 memset(&node, 0, sizeof(node));
500 SILC_LOG_DEBUG(("Encoding ASN.1 tree 7"));
503 silc_asn1_encode(asn1, &node2,
505 SILC_ASN1_BOOLEAN(val),
506 SILC_ASN1_BOOLEAN(val),
507 SILC_ASN1_BOOLEAN(val),
508 SILC_ASN1_BOOLEAN(val),
509 SILC_ASN1_END, SILC_ASN1_END);
510 SILC_LOG_DEBUG(("Encoding success"));
513 silc_asn1_encode(asn1, &node,
514 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
515 SILC_ASN1_SEQUENCE_T(0, 9),
517 SILC_ASN1_ANY_T(0, 11, &node2),
518 SILC_ASN1_BOOLEAN_T(0, 4, val),
519 SILC_ASN1_BOOLEAN(val),
522 SILC_ASN1_END, SILC_ASN1_END);
524 SILC_LOG_DEBUG(("Encoding failed"));
527 SILC_LOG_DEBUG(("Encoding success"));
528 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
529 memset(&node2, 0, sizeof(node2));
530 SILC_LOG_DEBUG(("Decoding ASN.1 tree 7"));
532 silc_asn1_decode(asn1, &node,
533 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
534 SILC_ASN1_SEQUENCE_T(0, 9),
536 SILC_ASN1_ANY_T(0, 11, &node2), /* NOTE: tag */
537 SILC_ASN1_BOOLEAN_T(0, 4, &val),
538 SILC_ASN1_BOOLEAN(&val),
541 SILC_ASN1_END, SILC_ASN1_END);
543 SILC_LOG_DEBUG(("Decoding failed"));
546 SILC_LOG_DEBUG(("Decoding success"));
547 SILC_LOG_DEBUG(("Boolean val %d", val));
549 silc_asn1_decode(asn1, &node2,
550 SILC_ASN1_SEQUENCE_T(0, 11), /* NOTE: using implicit
552 SILC_ASN1_BOOLEAN(&val),
553 SILC_ASN1_BOOLEAN(&val),
554 SILC_ASN1_BOOLEAN(&val),
555 SILC_ASN1_BOOLEAN(&val),
556 SILC_ASN1_END, SILC_ASN1_END);
558 SILC_LOG_DEBUG(("Decoding failed"));
561 SILC_LOG_DEBUG(("Decoding success"));
562 SILC_LOG_DEBUG(("Boolean val %d", val));
563 memset(&node2, 0, sizeof(node2));
567 memset(&node, 0, sizeof(node));
568 SILC_LOG_DEBUG(("Encoding ASN.1 tree 8"));
570 silc_asn1_encode(asn1, &node,
572 SILC_ASN1_BOOLEAN_T(SILC_ASN1_IMPLICIT, 9999, val),
573 SILC_ASN1_END, SILC_ASN1_END);
575 SILC_LOG_DEBUG(("Encoding failed"));
578 SILC_LOG_DEBUG(("Encoding success"));
579 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
580 SILC_LOG_DEBUG(("Decoding ASN.1 tree 8"));
582 silc_asn1_decode(asn1, &node,
584 SILC_ASN1_BOOLEAN_T(0, 9999, &val),
585 SILC_ASN1_END, SILC_ASN1_END);
587 SILC_LOG_DEBUG(("Decoding failed"));
590 SILC_LOG_DEBUG(("Decoding success"));
591 SILC_LOG_DEBUG(("Boolean val %d", val));
592 memset(&node, 0, sizeof(node));
596 memset(&node, 0, sizeof(node));
597 SILC_LOG_DEBUG(("Encoding ASN.1 tree 9"));
599 silc_asn1_encode(asn1, &node,
601 SILC_ASN1_SEQUENCE_T(0, 9),
603 SILC_ASN1_BOOLEAN_T(0, 4, val),
604 SILC_ASN1_BOOLEAN(val),
606 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, val),
607 SILC_ASN1_BOOLEAN_T(0, 100, val),
611 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, val),
612 SILC_ASN1_OCTET_STRING("foobar", 6),
613 SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, val),
614 SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
615 SILC_ASN1_EXPLICIT, 1, val),
617 SILC_ASN1_END, SILC_ASN1_END);
619 SILC_LOG_DEBUG(("Encoding failed"));
622 SILC_LOG_DEBUG(("Encoding success"));
623 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
624 SILC_LOG_DEBUG(("Decoding ASN.1 tree 9"));
626 silc_asn1_decode(asn1, &node,
628 SILC_ASN1_SEQUENCE_T(0, 9),
630 SILC_ASN1_BOOLEAN_T(0, 4, &val),
631 SILC_ASN1_BOOLEAN(&val),
633 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, &val),
634 SILC_ASN1_BOOLEAN_T(0, 100, &val),
638 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, &val),
639 SILC_ASN1_OCTET_STRING(&str, &str_len),
640 SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, &val),
641 SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
642 SILC_ASN1_EXPLICIT, 1, &val),
644 SILC_ASN1_END, SILC_ASN1_END);
646 SILC_LOG_DEBUG(("Decoding failed"));
649 SILC_LOG_DEBUG(("Decoding success"));
650 SILC_LOG_DEBUG(("Boolean val %d", val));
651 SILC_LOG_DEBUG(("Ooctet-string %s, len %d", str, str_len));
655 memset(&node, 0, sizeof(node));
656 SILC_LOG_DEBUG(("Encoding ASN.1 tree 10 (INTEGER)"));
657 str = silc_rng_get_rn_data(rng, 256);
658 silc_mp_init(&mpint);
659 silc_mp_init(&mpint2);
660 silc_mp_bin2mp(str, 256, &mpint);
662 silc_asn1_encode(asn1, &node,
663 SILC_ASN1_INT(&mpint),
666 SILC_LOG_DEBUG(("Encoding failed"));
669 SILC_LOG_DEBUG(("Encoding success"));
670 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
671 SILC_LOG_DEBUG(("Decoding ASN.1 tree 10 (INTEGER)"));
673 silc_asn1_decode(asn1, &node,
674 SILC_ASN1_INT(&mpint2),
676 if (silc_mp_cmp(&mpint, &mpint2) != 0) {
677 SILC_LOG_DEBUG(("INTEGER MISMATCH"));
681 SILC_LOG_DEBUG(("Decoding failed"));
684 SILC_LOG_DEBUG(("Decoding success"));
688 memset(&node, 0, sizeof(node));
689 SILC_LOG_DEBUG(("Encoding ASN.1 tree 11 (OID)"));
691 silc_asn1_encode(asn1, &node,
692 SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
693 SILC_ASN1_OID("1.2.840.113549"),
696 SILC_LOG_DEBUG(("Encoding failed"));
699 SILC_LOG_DEBUG(("Encoding success"));
700 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
701 SILC_LOG_DEBUG(("Decoding ASN.1 tree 11 (OID)"));
703 silc_asn1_decode(asn1, &node,
704 SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
708 SILC_LOG_DEBUG(("Decoding failed"));
711 SILC_LOG_DEBUG(("Decoding success"));
712 SILC_LOG_DEBUG(("OID %s", str));
716 memset(&node, 0, sizeof(node));
717 SILC_LOG_DEBUG(("Encoding ASN.1 tree 12 (SHORT INTEGER)"));
720 SILC_LOG_DEBUG(("Short integer: %d", str_len));
721 SILC_LOG_DEBUG(("Short integer: %d", tmpint));
723 silc_asn1_encode(asn1, &node,
724 SILC_ASN1_SHORT_INT(str_len),
725 SILC_ASN1_SHORT_INT_T(SILC_ASN1_IMPLICIT, 100, tmpint),
728 SILC_LOG_DEBUG(("Encoding failed"));
731 SILC_LOG_DEBUG(("Encoding success"));
732 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
733 SILC_LOG_DEBUG(("Decoding ASN.1 tree 12 (SHORT INTEGER)"));
735 silc_asn1_decode(asn1, &node,
736 SILC_ASN1_SHORT_INT(&str_len),
737 SILC_ASN1_SHORT_INT_T(SILC_ASN1_IMPLICIT, 100, &tmpint),
740 SILC_LOG_DEBUG(("Decoding failed"));
743 SILC_LOG_DEBUG(("Short integer: %d", str_len));
744 SILC_LOG_DEBUG(("Short integer: %d", tmpint));
745 SILC_LOG_DEBUG(("Decoding success"));
749 silc_asn1_free(asn1);
751 silc_hash_unregister_all();
752 silc_stack_free(stack);
756 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
757 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");