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;
51 SilcBool val = TRUE, nval;
53 unsigned char *str, buf[512];
54 SilcUInt32 str_len, tmpint, choice;
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_CHOICE(&choice),
187 SILC_ASN1_SHORT_INT(&tmpint),
188 SILC_ASN1_BOOLEAN(&val),
192 SILC_ASN1_END, SILC_ASN1_END);
194 SILC_LOG_DEBUG(("Decoding failed"));
197 SILC_LOG_DEBUG(("Decoding success"));
198 SILC_LOG_DEBUG(("Boolean val %d", val));
199 SILC_LOG_DEBUG(("Choice index %d", choice));
205 memset(&node, 0, sizeof(node));
206 SILC_LOG_DEBUG(("Encoding ASN.1 tree 3"));
209 silc_asn1_encode(asn1, &node,
211 SILC_ASN1_SEQUENCE_T(0, 9),
213 SILC_ASN1_BOOLEAN_T(0, 4, val),
214 SILC_ASN1_BOOLEAN(val),
217 SILC_ASN1_END, SILC_ASN1_END);
219 SILC_LOG_DEBUG(("Encoding failed"));
222 SILC_LOG_DEBUG(("Encoding success"));
223 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
224 SILC_LOG_DEBUG(("Decoding ASN.1 tree 3"));
226 silc_asn1_decode(asn1, &node,
228 SILC_ASN1_SEQUENCE_T(0, 9),
230 SILC_ASN1_BOOLEAN_T(0, 4, &val),
231 SILC_ASN1_BOOLEAN(&val),
234 SILC_ASN1_END, SILC_ASN1_END);
236 SILC_LOG_DEBUG(("Decoding failed"));
239 SILC_LOG_DEBUG(("Decoding success"));
240 SILC_LOG_DEBUG(("Boolean val %d", val));
244 memset(&node, 0, sizeof(node));
245 SILC_LOG_DEBUG(("Encoding ASN.1 tree 4"));
248 silc_asn1_encode(asn1, &node,
249 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
250 SILC_ASN1_EXPLICIT, 101),
251 SILC_ASN1_SEQUENCE_T(0, 9),
253 SILC_ASN1_BOOLEAN_T(0, 4, val),
254 SILC_ASN1_BOOLEAN(val),
257 SILC_ASN1_END, SILC_ASN1_END);
259 SILC_LOG_DEBUG(("Encoding failed"));
262 SILC_LOG_DEBUG(("Encoding success"));
263 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
264 SILC_LOG_DEBUG(("Decoding ASN.1 tree 4"));
266 silc_asn1_decode(asn1, &node,
267 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
268 SILC_ASN1_EXPLICIT, 101),
269 SILC_ASN1_SEQUENCE_T(0, 9),
271 SILC_ASN1_BOOLEAN_T(0, 4, &val),
272 SILC_ASN1_BOOLEAN(&val),
275 SILC_ASN1_END, SILC_ASN1_END);
277 SILC_LOG_DEBUG(("Decoding failed"));
280 SILC_LOG_DEBUG(("Decoding success"));
281 SILC_LOG_DEBUG(("Boolean val %d", val));
285 memset(&node, 0, sizeof(node));
286 SILC_LOG_DEBUG(("Encoding ASN.1 tree 5"));
288 silc_asn1_encode(asn1, &node2,
289 SILC_ASN1_BOOLEAN(val),
291 SILC_LOG_DEBUG(("Encoding success"));
293 silc_asn1_encode(asn1, &node,
294 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
295 SILC_ASN1_SEQUENCE_T(0, 9),
297 SILC_ASN1_ANY(&node2),
298 SILC_ASN1_BOOLEAN_T(0, 4, val),
299 SILC_ASN1_BOOLEAN(val),
302 SILC_ASN1_END, SILC_ASN1_END);
304 SILC_LOG_DEBUG(("Encoding failed"));
307 SILC_LOG_DEBUG(("Encoding success"));
308 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
309 memset(&node2, 0, sizeof(node2));
310 SILC_LOG_DEBUG(("Decoding ASN.1 tree 5"));
312 silc_asn1_decode(asn1, &node,
313 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
314 SILC_ASN1_SEQUENCE_T(0, 9),
316 SILC_ASN1_ANY(&node2),
317 SILC_ASN1_BOOLEAN_T(0, 4, &val),
318 SILC_ASN1_BOOLEAN(&val),
321 SILC_ASN1_END, SILC_ASN1_END);
323 SILC_LOG_DEBUG(("Decoding failed"));
326 SILC_LOG_DEBUG(("Decoding success"));
327 SILC_LOG_DEBUG(("Boolean val %d", val));
329 silc_asn1_decode(asn1, &node2,
330 SILC_ASN1_BOOLEAN(&val),
333 SILC_LOG_DEBUG(("Decoding failed"));
336 SILC_LOG_DEBUG(("Decoding success"));
337 SILC_LOG_DEBUG(("Boolean val %d", val));
338 memset(&node2, 0, sizeof(node2));
342 memset(&node, 0, sizeof(node));
343 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
344 memset(tmp, 0, sizeof(tmp));
346 silc_buffer_set(&node2, tmp, 1);
347 SILC_LOG_DEBUG(("Encoding success"));
349 silc_asn1_encode(asn1, &node,
351 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
353 SILC_ASN1_END, SILC_ASN1_END);
355 SILC_LOG_DEBUG(("Encoding failed"));
358 SILC_LOG_DEBUG(("Encoding success"));
359 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
360 memset(&node2, 0, sizeof(node2));
361 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
363 silc_asn1_decode(asn1, &node,
365 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
367 SILC_ASN1_END, SILC_ASN1_END);
369 SILC_LOG_DEBUG(("Decoding failed"));
372 SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
373 if (node2.data[0] != 0xff) {
374 SILC_LOG_DEBUG(("Decoding failed"));
377 SILC_LOG_DEBUG(("Decoding success"));
378 memset(&node, 0, sizeof(node));
379 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
380 memset(tmp, 0, sizeof(tmp));
382 silc_buffer_set(&node2, tmp, 1);
383 SILC_LOG_DEBUG(("Encoding success"));
385 silc_asn1_encode(asn1, &node,
387 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
389 SILC_ASN1_END, SILC_ASN1_END);
391 SILC_LOG_DEBUG(("Encoding failed"));
394 SILC_LOG_DEBUG(("Encoding success"));
395 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
396 memset(&node2, 0, sizeof(node2));
397 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
399 silc_asn1_decode(asn1, &node,
401 SILC_ASN1_BOOLEAN(&val),
402 SILC_ASN1_END, SILC_ASN1_END);
404 SILC_LOG_DEBUG(("Decoding failed"));
407 SILC_LOG_DEBUG(("Decoding success"));
408 SILC_LOG_DEBUG(("Boolean val %d", val));
409 memset(&node, 0, sizeof(node));
410 SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
411 memset(tmp, 0, sizeof(tmp));
413 silc_buffer_set(&node2, tmp, 1);
414 SILC_LOG_DEBUG(("Encoding success"));
416 silc_asn1_encode(asn1, &node,
418 SILC_ASN1_BOOLEAN(val),
419 SILC_ASN1_END, SILC_ASN1_END);
421 SILC_LOG_DEBUG(("Encoding failed"));
424 SILC_LOG_DEBUG(("Encoding success"));
425 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
426 memset(&node2, 0, sizeof(node2));
427 SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
429 silc_asn1_decode(asn1, &node,
431 SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
433 SILC_ASN1_END, SILC_ASN1_END);
435 SILC_LOG_DEBUG(("Decoding failed"));
438 SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
439 if (node2.data[0] != 0xff) {
440 SILC_LOG_DEBUG(("Decoding failed"));
443 SILC_LOG_DEBUG(("Decoding success"));
444 memset(&node2, 0, sizeof(node2));
448 memset(&node, 0, sizeof(node));
449 SILC_LOG_DEBUG(("Encoding ASN.1 tree 6"));
451 silc_asn1_encode(asn1, &node2,
452 SILC_ASN1_BOOLEAN(val),
454 SILC_LOG_DEBUG(("Encoding success"));
456 silc_asn1_encode(asn1, &node,
457 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
458 SILC_ASN1_SEQUENCE_T(0, 9),
460 SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
461 SILC_ASN1_BOOLEAN_T(0, 4, val),
462 SILC_ASN1_BOOLEAN(val),
465 SILC_ASN1_END, SILC_ASN1_END);
467 SILC_LOG_DEBUG(("Encoding failed"));
470 SILC_LOG_DEBUG(("Encoding success"));
471 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
472 memset(&node2, 0, sizeof(node2));
473 SILC_LOG_DEBUG(("Decoding ASN.1 tree 6"));
475 silc_asn1_decode(asn1, &node,
476 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
477 SILC_ASN1_SEQUENCE_T(0, 9),
479 SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
480 SILC_ASN1_BOOLEAN_T(0, 4, &val),
481 SILC_ASN1_BOOLEAN(&val),
484 SILC_ASN1_END, SILC_ASN1_END);
486 SILC_LOG_DEBUG(("Decoding failed"));
489 SILC_LOG_DEBUG(("Decoding success"));
490 SILC_LOG_DEBUG(("Boolean val %d", val));
492 silc_asn1_decode(asn1, &node2,
493 SILC_ASN1_BOOLEAN(&val),
496 SILC_LOG_DEBUG(("Decoding failed"));
499 SILC_LOG_DEBUG(("Decoding success"));
500 SILC_LOG_DEBUG(("Boolean val %d", val));
501 memset(&node2, 0, sizeof(node2));
505 memset(&node, 0, sizeof(node));
506 SILC_LOG_DEBUG(("Encoding ASN.1 tree 7"));
509 silc_asn1_encode(asn1, &node2,
511 SILC_ASN1_BOOLEAN(val),
512 SILC_ASN1_BOOLEAN(val),
513 SILC_ASN1_BOOLEAN(val),
514 SILC_ASN1_BOOLEAN(val),
515 SILC_ASN1_END, SILC_ASN1_END);
516 SILC_LOG_DEBUG(("Encoding success"));
519 silc_asn1_encode(asn1, &node,
520 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
521 SILC_ASN1_SEQUENCE_T(0, 9),
523 SILC_ASN1_ANY_T(0, 11, &node2),
524 SILC_ASN1_BOOLEAN_T(0, 4, val),
525 SILC_ASN1_BOOLEAN(val),
528 SILC_ASN1_END, SILC_ASN1_END);
530 SILC_LOG_DEBUG(("Encoding failed"));
533 SILC_LOG_DEBUG(("Encoding success"));
534 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
535 memset(&node2, 0, sizeof(node2));
536 SILC_LOG_DEBUG(("Decoding ASN.1 tree 7"));
538 silc_asn1_decode(asn1, &node,
539 SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
540 SILC_ASN1_SEQUENCE_T(0, 9),
542 SILC_ASN1_ANY_T(0, 11, &node2), /* NOTE: tag */
543 SILC_ASN1_BOOLEAN_T(0, 4, &val),
544 SILC_ASN1_BOOLEAN(&val),
547 SILC_ASN1_END, SILC_ASN1_END);
549 SILC_LOG_DEBUG(("Decoding failed"));
552 SILC_LOG_DEBUG(("Decoding success"));
553 SILC_LOG_DEBUG(("Boolean val %d", val));
555 silc_asn1_decode(asn1, &node2,
556 SILC_ASN1_SEQUENCE_T(0, 11), /* NOTE: using implicit
558 SILC_ASN1_BOOLEAN(&val),
559 SILC_ASN1_BOOLEAN(&val),
560 SILC_ASN1_BOOLEAN(&val),
561 SILC_ASN1_BOOLEAN(&val),
562 SILC_ASN1_END, SILC_ASN1_END);
564 SILC_LOG_DEBUG(("Decoding failed"));
567 SILC_LOG_DEBUG(("Decoding success"));
568 SILC_LOG_DEBUG(("Boolean val %d", val));
569 memset(&node2, 0, sizeof(node2));
573 memset(&node, 0, sizeof(node));
574 SILC_LOG_DEBUG(("Encoding ASN.1 tree 8"));
576 silc_asn1_encode(asn1, &node,
578 SILC_ASN1_BOOLEAN_T(SILC_ASN1_IMPLICIT, 9999, val),
579 SILC_ASN1_END, SILC_ASN1_END);
581 SILC_LOG_DEBUG(("Encoding failed"));
584 SILC_LOG_DEBUG(("Encoding success"));
585 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
586 SILC_LOG_DEBUG(("Decoding ASN.1 tree 8"));
588 silc_asn1_decode(asn1, &node,
590 SILC_ASN1_BOOLEAN_T(0, 9999, &val),
591 SILC_ASN1_END, SILC_ASN1_END);
593 SILC_LOG_DEBUG(("Decoding failed"));
596 SILC_LOG_DEBUG(("Decoding success"));
597 SILC_LOG_DEBUG(("Boolean val %d", val));
598 memset(&node, 0, sizeof(node));
602 memset(&node, 0, sizeof(node));
603 SILC_LOG_DEBUG(("Encoding ASN.1 tree 9"));
605 silc_asn1_encode(asn1, &node,
607 SILC_ASN1_SEQUENCE_T(0, 9),
609 SILC_ASN1_BOOLEAN_T(0, 4, val),
610 SILC_ASN1_BOOLEAN(val),
612 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, val),
613 SILC_ASN1_BOOLEAN_T(0, 100, val),
616 SILC_ASN1_NULL(TRUE),
617 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, val),
618 SILC_ASN1_OCTET_STRING("foobar", 6),
619 SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, val),
620 SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
621 SILC_ASN1_EXPLICIT, 1, val),
623 SILC_ASN1_END, SILC_ASN1_END);
625 SILC_LOG_DEBUG(("Encoding failed"));
628 SILC_LOG_DEBUG(("Encoding success"));
629 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
630 SILC_LOG_DEBUG(("Decoding ASN.1 tree 9"));
632 silc_asn1_decode(asn1, &node,
634 SILC_ASN1_SEQUENCE_T(0, 9),
636 SILC_ASN1_BOOLEAN_T(0, 4, &val),
637 SILC_ASN1_BOOLEAN(&val),
639 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, &val),
640 SILC_ASN1_BOOLEAN_T(0, 100, &val),
643 SILC_ASN1_NULL(&nval),
644 SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, &val),
645 SILC_ASN1_OCTET_STRING(&str, &str_len),
646 SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, &val),
647 SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
648 SILC_ASN1_EXPLICIT, 1, &val),
650 SILC_ASN1_END, SILC_ASN1_END);
652 SILC_LOG_DEBUG(("Decoding failed"));
655 SILC_LOG_DEBUG(("Decoding success"));
656 SILC_LOG_DEBUG(("Boolean val %d", val));
657 SILC_LOG_DEBUG(("NULL is present %s", nval ? "yes" : "no"));
658 SILC_LOG_DEBUG(("Ooctet-string %s, len %d", str, str_len));
662 memset(&node, 0, sizeof(node));
663 SILC_LOG_DEBUG(("Encoding ASN.1 tree 10 (INTEGER)"));
664 silc_rng_get_rn_data(rng, 256, buf, sizeof(buf));
665 silc_mp_init(&mpint);
666 silc_mp_init(&mpint2);
667 silc_mp_bin2mp(buf, 256, &mpint);
669 silc_asn1_encode(asn1, &node,
670 SILC_ASN1_INT(&mpint),
673 SILC_LOG_DEBUG(("Encoding failed"));
676 SILC_LOG_DEBUG(("Encoding success"));
677 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
678 SILC_LOG_DEBUG(("Decoding ASN.1 tree 10 (INTEGER)"));
680 silc_asn1_decode(asn1, &node,
681 SILC_ASN1_INT(&mpint2),
683 if (silc_mp_cmp(&mpint, &mpint2) != 0) {
684 SILC_LOG_DEBUG(("INTEGER MISMATCH"));
688 SILC_LOG_DEBUG(("Decoding failed"));
691 SILC_LOG_DEBUG(("Decoding success"));
695 memset(&node, 0, sizeof(node));
696 SILC_LOG_DEBUG(("Encoding ASN.1 tree 11 (OID)"));
698 silc_asn1_encode(asn1, &node,
699 SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
700 SILC_ASN1_OID("1.2.840.113549"),
703 SILC_LOG_DEBUG(("Encoding failed"));
706 SILC_LOG_DEBUG(("Encoding success"));
707 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
708 SILC_LOG_DEBUG(("Decoding ASN.1 tree 11 (OID)"));
710 silc_asn1_decode(asn1, &node,
711 SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
715 SILC_LOG_DEBUG(("Decoding failed"));
718 SILC_LOG_DEBUG(("Decoding success"));
719 SILC_LOG_DEBUG(("OID %s", str));
723 memset(&node, 0, sizeof(node));
724 SILC_LOG_DEBUG(("Encoding ASN.1 tree 12 (SHORT INTEGER)"));
727 SILC_LOG_DEBUG(("Short integer: %d", str_len));
728 SILC_LOG_DEBUG(("Short integer: %d", tmpint));
730 silc_asn1_encode(asn1, &node,
731 SILC_ASN1_SHORT_INT(str_len),
732 SILC_ASN1_SHORT_INT_T(SILC_ASN1_IMPLICIT, 100, tmpint),
735 SILC_LOG_DEBUG(("Encoding failed"));
738 SILC_LOG_DEBUG(("Encoding success"));
739 SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
740 SILC_LOG_DEBUG(("Decoding ASN.1 tree 12 (SHORT INTEGER)"));
742 silc_asn1_decode(asn1, &node,
743 SILC_ASN1_SHORT_INT(&str_len),
744 SILC_ASN1_SHORT_INT_T(SILC_ASN1_IMPLICIT, 100, &tmpint),
747 SILC_LOG_DEBUG(("Decoding failed"));
750 SILC_LOG_DEBUG(("Short integer: %d", str_len));
751 SILC_LOG_DEBUG(("Short integer: %d", tmpint));
752 SILC_LOG_DEBUG(("Decoding success"));
756 silc_asn1_free(asn1);
758 silc_hash_unregister_all();
759 silc_stack_free(stack);
763 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
764 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");