Added SILC_ASN1_ANY_PRIMITIVE to encode/decode any pre-encoded
[silc.git] / lib / silcasn1 / tests / test_silcasn1.c
1 #include "silc.h"
2
3 /*
4 silc_asn1_encode(asn1, node,
5                  SILC_ASN1_BOOLEAN(SilcBool),
6                  SILC_ASN1_END);
7 silc_asn1_encode(asn1, dest,
8                  SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
9                    SILC_ASN1_SEQUENCE_T(0, 9),
10                      SILC_ASN1_SEQUENCE,
11                        SILC_ASN1_ANY_T(0, 33, node),
12                        SILC_ASN1_BOOLEAN_T(0, 4, boolv),
13                        SILC_ASN1_BOOLEAN(SilcBool),
14                      SILC_ASN1_END,
15                    SILC_ASN1_END,
16                  SILC_ASN1_END);
17
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).
21 */
22
23
24 /*
25 silc_asn1_encode(asn1, node,
26                  SILC_ASN1_BOOLEAN(SilcBool),
27                  SILC_ASN1_END);
28 silc_asn1_encode(asn1, dest,
29                  SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
30                    SILC_ASN1_SEQUENCE_T(0, 9),
31                      SILC_ASN1_SEQUENCE,
32                        SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, node),
33                        SILC_ASN1_BOOLEAN_T(0, 4, boolv),
34                        SILC_ASN1_BOOLEAN(SilcBool),
35                      SILC_ASN1_END,
36                    SILC_ASN1_END,
37                  SILC_ASN1_END);
38
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.
42
43 */
44
45
46 int main(int argc, char **argv)
47 {
48   SilcBufferStruct node, node2;
49   SilcAsn1 asn1;
50   SilcBool success = FALSE;
51   SilcBool val = TRUE;
52   int i;
53   unsigned char *str;
54   SilcUInt32 str_len;
55   char tmp[32];
56
57   memset(&node, 0, sizeof(node));
58   memset(&node2, 0, sizeof(node2));
59
60   if (argc > 1 && !strcmp(argv[1], "-d")) {
61     silc_log_debug(TRUE);
62     silc_log_debug_hexdump(TRUE);
63     silc_log_set_debug_string("*asn1*,*ber*");
64   }
65
66   SILC_LOG_DEBUG(("Allocating ASN.1 context"));
67   asn1 = silc_asn1_alloc();
68   if (!asn1)
69     goto out;
70
71   SILC_LOG_DEBUG(("Encoding ASN.1 tree 1"));
72   val = 1;
73   success =
74     silc_asn1_encode(asn1, &node,
75                      SILC_ASN1_SEQUENCE,
76                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
77                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
78                                               SILC_ASN1_INDEFINITE, 0),
79                            SILC_ASN1_BOOLEAN_T(0, 4, val),
80                            SILC_ASN1_BOOLEAN(val),
81                          SILC_ASN1_END,
82                        SILC_ASN1_END,
83                      SILC_ASN1_END, SILC_ASN1_END);
84   if (!success) {
85     SILC_LOG_DEBUG(("Encoding failed"));
86     goto out;
87   }
88   SILC_LOG_DEBUG(("Encoding success"));
89   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
90   SILC_LOG_DEBUG(("Decoding ASN.1 tree 1"));
91   success =
92     silc_asn1_decode(asn1, &node,
93                      SILC_ASN1_SEQUENCE,
94                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
95                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
96                                               SILC_ASN1_INDEFINITE, 0),
97                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
98                            SILC_ASN1_BOOLEAN(&val),
99                          SILC_ASN1_END,
100                        SILC_ASN1_END,
101                      SILC_ASN1_END, SILC_ASN1_END);
102   if (!success) {
103     SILC_LOG_DEBUG(("Decoding failed"));
104     goto out;
105   }
106   SILC_LOG_DEBUG(("Decoding success"));
107   SILC_LOG_DEBUG(("Boolean val %d", val));
108
109 #if 1
110   memset(&node, 0, sizeof(node));
111   SILC_LOG_DEBUG(("Encoding ASN.1 tree 1"));
112   val = 0;
113   success =
114     silc_asn1_encode(asn1, &node,
115                      SILC_ASN1_SEQUENCE,
116                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
117                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
118                                               SILC_ASN1_INDEFINITE, 0),
119                            SILC_ASN1_BOOLEAN_T(0, 4, val),
120                            SILC_ASN1_BOOLEAN(val),
121                          SILC_ASN1_END,
122                        SILC_ASN1_END,
123                      SILC_ASN1_END, SILC_ASN1_END);
124   if (!success) {
125     SILC_LOG_DEBUG(("Encoding failed"));
126     goto out;
127   }
128   SILC_LOG_DEBUG(("Encoding success"));
129   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
130   SILC_LOG_DEBUG(("Decoding ASN.1 tree 1"));
131   success =
132     silc_asn1_decode(asn1, &node,
133                      SILC_ASN1_SEQUENCE,
134                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
135                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT |
136                                               SILC_ASN1_INDEFINITE, 0),
137                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
138                            SILC_ASN1_BOOLEAN(&val),
139                          SILC_ASN1_END,
140                        SILC_ASN1_END,
141                      SILC_ASN1_END, SILC_ASN1_END);
142   if (!success) {
143     SILC_LOG_DEBUG(("Decoding failed"));
144     goto out;
145   }
146   SILC_LOG_DEBUG(("Decoding success"));
147   SILC_LOG_DEBUG(("Boolean val %d", val));
148   printf("\n");
149
150
151   memset(&node, 0, sizeof(node));
152   SILC_LOG_DEBUG(("Encoding ASN.1 tree 2"));
153   val = 1;
154   success =
155     silc_asn1_encode(asn1, &node,
156                      SILC_ASN1_SEQUENCE,
157                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
158                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_INDEFINITE, 0),
159                            SILC_ASN1_BOOLEAN_T(0, 4, val),
160                            SILC_ASN1_BOOLEAN(val),
161                          SILC_ASN1_END,
162                        SILC_ASN1_END,
163                      SILC_ASN1_END, SILC_ASN1_END);
164   if (!success) {
165     SILC_LOG_DEBUG(("Encoding failed"));
166     goto out;
167   }
168   SILC_LOG_DEBUG(("Encoding success"));
169   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
170   SILC_LOG_DEBUG(("Decoding ASN.1 tree 2"));
171   success =
172     silc_asn1_decode(asn1, &node,
173                      SILC_ASN1_SEQUENCE,
174                        SILC_ASN1_SEQUENCE_T(SILC_ASN1_EXPLICIT, 9),
175                          SILC_ASN1_SEQUENCE_T(SILC_ASN1_INDEFINITE, 0),
176                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
177                            SILC_ASN1_BOOLEAN(&val),
178                          SILC_ASN1_END,
179                        SILC_ASN1_END,
180                      SILC_ASN1_END, SILC_ASN1_END);
181   if (!success) {
182     SILC_LOG_DEBUG(("Decoding failed"));
183     goto out;
184   }
185   SILC_LOG_DEBUG(("Decoding success"));
186   SILC_LOG_DEBUG(("Boolean val %d", val));
187   printf("\n");
188
189
190   memset(&node, 0, sizeof(node));
191   SILC_LOG_DEBUG(("Encoding ASN.1 tree 3"));
192   val = 0;
193   success =
194     silc_asn1_encode(asn1, &node,
195                      SILC_ASN1_SEQUENCE,
196                        SILC_ASN1_SEQUENCE_T(0, 9),
197                          SILC_ASN1_SEQUENCE,
198                            SILC_ASN1_BOOLEAN_T(0, 4, val),
199                            SILC_ASN1_BOOLEAN(val),
200                          SILC_ASN1_END,
201                        SILC_ASN1_END,
202                      SILC_ASN1_END, SILC_ASN1_END);
203   if (!success) {
204     SILC_LOG_DEBUG(("Encoding failed"));
205     goto out;
206   }
207   SILC_LOG_DEBUG(("Encoding success"));
208   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
209   SILC_LOG_DEBUG(("Decoding ASN.1 tree 3"));
210   success =
211     silc_asn1_decode(asn1, &node,
212                      SILC_ASN1_SEQUENCE,
213                        SILC_ASN1_SEQUENCE_T(0, 9),
214                          SILC_ASN1_SEQUENCE,
215                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
216                            SILC_ASN1_BOOLEAN(&val),
217                          SILC_ASN1_END,
218                        SILC_ASN1_END,
219                      SILC_ASN1_END, SILC_ASN1_END);
220   if (!success) {
221     SILC_LOG_DEBUG(("Decoding failed"));
222     goto out;
223   }
224   SILC_LOG_DEBUG(("Decoding success"));
225   SILC_LOG_DEBUG(("Boolean val %d", val));
226   printf("\n");
227
228
229   memset(&node, 0, sizeof(node));
230   SILC_LOG_DEBUG(("Encoding ASN.1 tree 4"));
231   val = 1;
232   success =
233     silc_asn1_encode(asn1, &node,
234                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
235                                           SILC_ASN1_EXPLICIT, 101),
236                        SILC_ASN1_SEQUENCE_T(0, 9),
237                          SILC_ASN1_SEQUENCE,
238                            SILC_ASN1_BOOLEAN_T(0, 4, val),
239                            SILC_ASN1_BOOLEAN(val),
240                          SILC_ASN1_END,
241                        SILC_ASN1_END,
242                      SILC_ASN1_END, SILC_ASN1_END);
243   if (!success) {
244     SILC_LOG_DEBUG(("Encoding failed"));
245     goto out;
246   }
247   SILC_LOG_DEBUG(("Encoding success"));
248   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
249   SILC_LOG_DEBUG(("Decoding ASN.1 tree 4"));
250   success =
251     silc_asn1_decode(asn1, &node,
252                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE |
253                                           SILC_ASN1_EXPLICIT, 101),
254                        SILC_ASN1_SEQUENCE_T(0, 9),
255                          SILC_ASN1_SEQUENCE,
256                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
257                            SILC_ASN1_BOOLEAN(&val),
258                          SILC_ASN1_END,
259                        SILC_ASN1_END,
260                      SILC_ASN1_END, SILC_ASN1_END);
261   if (!success) {
262     SILC_LOG_DEBUG(("Decoding failed"));
263     goto out;
264   }
265   SILC_LOG_DEBUG(("Decoding success"));
266   SILC_LOG_DEBUG(("Boolean val %d", val));
267   printf("\n");
268
269
270   memset(&node, 0, sizeof(node));
271   SILC_LOG_DEBUG(("Encoding ASN.1 tree 5"));
272   success =
273     silc_asn1_encode(asn1, &node2,
274                      SILC_ASN1_BOOLEAN(val),
275                      SILC_ASN1_END);
276   SILC_LOG_DEBUG(("Encoding success"));
277   success =
278     silc_asn1_encode(asn1, &node,
279                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
280                        SILC_ASN1_SEQUENCE_T(0, 9),
281                          SILC_ASN1_SEQUENCE,
282                            SILC_ASN1_ANY(&node2),
283                            SILC_ASN1_BOOLEAN_T(0, 4, val),
284                            SILC_ASN1_BOOLEAN(val),
285                          SILC_ASN1_END,
286                        SILC_ASN1_END,
287                      SILC_ASN1_END, SILC_ASN1_END);
288   if (!success) {
289     SILC_LOG_DEBUG(("Encoding failed"));
290     goto out;
291   }
292   SILC_LOG_DEBUG(("Encoding success"));
293   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
294   memset(&node2, 0, sizeof(node2));
295   SILC_LOG_DEBUG(("Decoding ASN.1 tree 5"));
296   success =
297     silc_asn1_decode(asn1, &node,
298                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
299                        SILC_ASN1_SEQUENCE_T(0, 9),
300                          SILC_ASN1_SEQUENCE,
301                            SILC_ASN1_ANY(&node2),
302                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
303                            SILC_ASN1_BOOLEAN(&val),
304                          SILC_ASN1_END,
305                        SILC_ASN1_END,
306                      SILC_ASN1_END, SILC_ASN1_END);
307   if (!success) {
308     SILC_LOG_DEBUG(("Decoding failed"));
309     goto out;
310   }
311   SILC_LOG_DEBUG(("Decoding success"));
312   SILC_LOG_DEBUG(("Boolean val %d", val));
313   success =
314     silc_asn1_decode(asn1, &node2,
315                      SILC_ASN1_BOOLEAN(&val),
316                      SILC_ASN1_END);
317   if (!success) {
318     SILC_LOG_DEBUG(("Decoding failed"));
319     goto out;
320   }
321   SILC_LOG_DEBUG(("Decoding success"));
322   SILC_LOG_DEBUG(("Boolean val %d", val));
323   memset(&node2, 0, sizeof(node2));
324   printf("\n");
325
326
327   memset(&node, 0, sizeof(node));
328   SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
329   memset(tmp, 0, sizeof(tmp));
330   tmp[0] = 0xff;
331   silc_buffer_set(&node2, tmp, 1);
332   SILC_LOG_DEBUG(("Encoding success"));
333   success =
334     silc_asn1_encode(asn1, &node,
335                      SILC_ASN1_SEQUENCE,
336                        SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
337                                                &node2),
338                      SILC_ASN1_END, SILC_ASN1_END);
339   if (!success) {
340     SILC_LOG_DEBUG(("Encoding failed"));
341     goto out;
342   }
343   SILC_LOG_DEBUG(("Encoding success"));
344   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
345   memset(&node2, 0, sizeof(node2));
346   SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
347   success =
348     silc_asn1_decode(asn1, &node,
349                      SILC_ASN1_SEQUENCE,
350                        SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
351                                                &node2),
352                      SILC_ASN1_END, SILC_ASN1_END);
353   if (!success) {
354     SILC_LOG_DEBUG(("Decoding failed"));
355     goto out;
356   }
357   SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
358   if (node2.data[0] != 0xff) {
359     SILC_LOG_DEBUG(("Decoding failed"));
360     goto out;
361   }
362   SILC_LOG_DEBUG(("Decoding success"));
363   memset(&node, 0, sizeof(node));
364   SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
365   memset(tmp, 0, sizeof(tmp));
366   tmp[0] = 0xff;
367   silc_buffer_set(&node2, tmp, 1);
368   SILC_LOG_DEBUG(("Encoding success"));
369   success =
370     silc_asn1_encode(asn1, &node,
371                      SILC_ASN1_SEQUENCE,
372                        SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
373                                                &node2),
374                      SILC_ASN1_END, SILC_ASN1_END);
375   if (!success) {
376     SILC_LOG_DEBUG(("Encoding failed"));
377     goto out;
378   }
379   SILC_LOG_DEBUG(("Encoding success"));
380   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
381   memset(&node2, 0, sizeof(node2));
382   SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
383   success =
384     silc_asn1_decode(asn1, &node,
385                      SILC_ASN1_SEQUENCE,
386                        SILC_ASN1_BOOLEAN(&val),
387                      SILC_ASN1_END, SILC_ASN1_END);
388   if (!success) {
389     SILC_LOG_DEBUG(("Decoding failed"));
390     goto out;
391   }
392   SILC_LOG_DEBUG(("Decoding success"));
393   SILC_LOG_DEBUG(("Boolean val %d", val));
394   memset(&node, 0, sizeof(node));
395   SILC_LOG_DEBUG(("Encoding ASN.1 tree (ANY_PRIMITIVE)"));
396   memset(tmp, 0, sizeof(tmp));
397   tmp[0] = 0xff;
398   silc_buffer_set(&node2, tmp, 1);
399   SILC_LOG_DEBUG(("Encoding success"));
400   success =
401     silc_asn1_encode(asn1, &node,
402                      SILC_ASN1_SEQUENCE,
403                        SILC_ASN1_BOOLEAN(val),
404                      SILC_ASN1_END, SILC_ASN1_END);
405   if (!success) {
406     SILC_LOG_DEBUG(("Encoding failed"));
407     goto out;
408   }
409   SILC_LOG_DEBUG(("Encoding success"));
410   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
411   memset(&node2, 0, sizeof(node2));
412   SILC_LOG_DEBUG(("Decoding ASN.1 tree (ANY_PRIMITIVE)"));
413   success =
414     silc_asn1_decode(asn1, &node,
415                      SILC_ASN1_SEQUENCE,
416                        SILC_ASN1_ANY_PRIMITIVE(SILC_ASN1_TAG_BOOLEAN,
417                                                &node2),
418                      SILC_ASN1_END, SILC_ASN1_END);
419   if (!success) {
420     SILC_LOG_DEBUG(("Decoding failed"));
421     goto out;
422   }
423   SILC_LOG_DEBUG(("Boolean val %d", node2.data[0]));
424   if (node2.data[0] != 0xff) {
425     SILC_LOG_DEBUG(("Decoding failed"));
426     goto out;
427   }
428   SILC_LOG_DEBUG(("Decoding success"));
429   memset(&node2, 0, sizeof(node2));
430   printf("\n");
431
432
433   memset(&node, 0, sizeof(node));
434   SILC_LOG_DEBUG(("Encoding ASN.1 tree 6"));
435   success =
436     silc_asn1_encode(asn1, &node2,
437                      SILC_ASN1_BOOLEAN(val),
438                      SILC_ASN1_END);
439   SILC_LOG_DEBUG(("Encoding success"));
440   success =
441     silc_asn1_encode(asn1, &node,
442                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
443                        SILC_ASN1_SEQUENCE_T(0, 9),
444                          SILC_ASN1_SEQUENCE,
445                            SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
446                            SILC_ASN1_BOOLEAN_T(0, 4, val),
447                            SILC_ASN1_BOOLEAN(val),
448                          SILC_ASN1_END,
449                        SILC_ASN1_END,
450                      SILC_ASN1_END, SILC_ASN1_END);
451   if (!success) {
452     SILC_LOG_DEBUG(("Encoding failed"));
453     goto out;
454   }
455   SILC_LOG_DEBUG(("Encoding success"));
456   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
457   memset(&node2, 0, sizeof(node2));
458   SILC_LOG_DEBUG(("Decoding ASN.1 tree 6"));
459   success =
460     silc_asn1_decode(asn1, &node,
461                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
462                        SILC_ASN1_SEQUENCE_T(0, 9),
463                          SILC_ASN1_SEQUENCE,
464                            SILC_ASN1_ANY_T(SILC_ASN1_EXPLICIT, 33, &node2),
465                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
466                            SILC_ASN1_BOOLEAN(&val),
467                          SILC_ASN1_END,
468                        SILC_ASN1_END,
469                      SILC_ASN1_END, SILC_ASN1_END);
470   if (!success) {
471     SILC_LOG_DEBUG(("Decoding failed"));
472     goto out;
473   }
474   SILC_LOG_DEBUG(("Decoding success"));
475   SILC_LOG_DEBUG(("Boolean val %d", val));
476   success =
477     silc_asn1_decode(asn1, &node2,
478                      SILC_ASN1_BOOLEAN(&val),
479                      SILC_ASN1_END);
480   if (!success) {
481     SILC_LOG_DEBUG(("Decoding failed"));
482     goto out;
483   }
484   SILC_LOG_DEBUG(("Decoding success"));
485   SILC_LOG_DEBUG(("Boolean val %d", val));
486   memset(&node2, 0, sizeof(node2));
487   printf("\n");
488
489
490   memset(&node, 0, sizeof(node));
491   SILC_LOG_DEBUG(("Encoding ASN.1 tree 7"));
492   val = 0;
493   success =
494     silc_asn1_encode(asn1, &node2,
495                      SILC_ASN1_SEQUENCE,
496                        SILC_ASN1_BOOLEAN(val),
497                        SILC_ASN1_BOOLEAN(val),
498                        SILC_ASN1_BOOLEAN(val),
499                        SILC_ASN1_BOOLEAN(val),
500                      SILC_ASN1_END, SILC_ASN1_END);
501   SILC_LOG_DEBUG(("Encoding success"));
502   val = 1;
503   success =
504     silc_asn1_encode(asn1, &node,
505                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
506                        SILC_ASN1_SEQUENCE_T(0, 9),
507                          SILC_ASN1_SEQUENCE,
508                            SILC_ASN1_ANY_T(0, 11, &node2),
509                            SILC_ASN1_BOOLEAN_T(0, 4, val),
510                            SILC_ASN1_BOOLEAN(val),
511                          SILC_ASN1_END,
512                        SILC_ASN1_END,
513                      SILC_ASN1_END, SILC_ASN1_END);
514   if (!success) {
515     SILC_LOG_DEBUG(("Encoding failed"));
516     goto out;
517   }
518   SILC_LOG_DEBUG(("Encoding success"));
519   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
520   memset(&node2, 0, sizeof(node2));
521   SILC_LOG_DEBUG(("Decoding ASN.1 tree 7"));
522   success =
523     silc_asn1_decode(asn1, &node,
524                      SILC_ASN1_SEQUENCE_T(SILC_ASN1_PRIVATE, 101),
525                        SILC_ASN1_SEQUENCE_T(0, 9),
526                          SILC_ASN1_SEQUENCE,
527                            SILC_ASN1_ANY_T(0, 11, &node2), /* NOTE: tag */
528                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
529                            SILC_ASN1_BOOLEAN(&val),
530                          SILC_ASN1_END,
531                        SILC_ASN1_END,
532                      SILC_ASN1_END, SILC_ASN1_END);
533   if (!success) {
534     SILC_LOG_DEBUG(("Decoding failed"));
535     goto out;
536   }
537   SILC_LOG_DEBUG(("Decoding success"));
538   SILC_LOG_DEBUG(("Boolean val %d", val));
539   success =
540     silc_asn1_decode(asn1, &node2,
541                      SILC_ASN1_SEQUENCE_T(0, 11), /* NOTE: using implicit
542                                                      tag! */
543                        SILC_ASN1_BOOLEAN(&val),
544                        SILC_ASN1_BOOLEAN(&val),
545                        SILC_ASN1_BOOLEAN(&val),
546                        SILC_ASN1_BOOLEAN(&val),
547                      SILC_ASN1_END, SILC_ASN1_END);
548   if (!success) {
549     SILC_LOG_DEBUG(("Decoding failed"));
550     goto out;
551   }
552   SILC_LOG_DEBUG(("Decoding success"));
553   SILC_LOG_DEBUG(("Boolean val %d", val));
554   memset(&node2, 0, sizeof(node2));
555   printf("\n");
556
557
558   memset(&node, 0, sizeof(node));
559   SILC_LOG_DEBUG(("Encoding ASN.1 tree 8"));
560   success =
561     silc_asn1_encode(asn1, &node,
562                      SILC_ASN1_SEQUENCE,
563                        SILC_ASN1_BOOLEAN_T(SILC_ASN1_IMPLICIT, 9999, val),
564                      SILC_ASN1_END, SILC_ASN1_END);
565   if (!success) {
566     SILC_LOG_DEBUG(("Encoding failed"));
567     goto out;
568   }
569   SILC_LOG_DEBUG(("Encoding success"));
570   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
571   SILC_LOG_DEBUG(("Decoding ASN.1 tree 8"));
572   success =
573     silc_asn1_decode(asn1, &node,
574                      SILC_ASN1_SEQUENCE,
575                        SILC_ASN1_BOOLEAN_T(0, 9999, &val),
576                      SILC_ASN1_END, SILC_ASN1_END);
577   if (!success) {
578     SILC_LOG_DEBUG(("Decoding failed"));
579     goto out;
580   }
581   SILC_LOG_DEBUG(("Decoding success"));
582   SILC_LOG_DEBUG(("Boolean val %d", val));
583   memset(&node, 0, sizeof(node));
584   printf("\n");
585
586   memset(&node, 0, sizeof(node));
587   SILC_LOG_DEBUG(("Encoding ASN.1 tree 9"));
588   success =
589     silc_asn1_encode(asn1, &node,
590                      SILC_ASN1_SEQUENCE,
591                        SILC_ASN1_SEQUENCE_T(0, 9),
592                          SILC_ASN1_SEQUENCE,
593                            SILC_ASN1_BOOLEAN_T(0, 4, val),
594                            SILC_ASN1_BOOLEAN(val),
595                          SILC_ASN1_END,
596                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, val),
597                          SILC_ASN1_BOOLEAN_T(0, 100, val),
598                        SILC_ASN1_END,
599                        SILC_ASN1_SEQUENCE,
600                          SILC_ASN1_NULL,
601                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, val),
602                          SILC_ASN1_OCTET_STRING("foobar", 6),
603                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, val),
604                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
605                                              SILC_ASN1_EXPLICIT, 1, val),
606                        SILC_ASN1_END,
607                      SILC_ASN1_END, SILC_ASN1_END);
608   if (!success) {
609     SILC_LOG_DEBUG(("Encoding failed"));
610     goto out;
611   }
612   SILC_LOG_DEBUG(("Encoding success"));
613   SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
614   SILC_LOG_DEBUG(("Decoding ASN.1 tree 9"));
615   success =
616     silc_asn1_decode(asn1, &node,
617                      SILC_ASN1_SEQUENCE,
618                        SILC_ASN1_SEQUENCE_T(0, 9),
619                          SILC_ASN1_SEQUENCE,
620                            SILC_ASN1_BOOLEAN_T(0, 4, &val),
621                            SILC_ASN1_BOOLEAN(&val),
622                          SILC_ASN1_END,
623                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 99, &val),
624                          SILC_ASN1_BOOLEAN_T(0, 100, &val),
625                        SILC_ASN1_END,
626                        SILC_ASN1_SEQUENCE,
627                          SILC_ASN1_NULL,
628                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 0, &val),
629                          SILC_ASN1_OCTET_STRING(&str, &str_len),
630                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_PRIVATE, 43, &val),
631                          SILC_ASN1_BOOLEAN_T(SILC_ASN1_APP |
632                                              SILC_ASN1_EXPLICIT, 1, &val),
633                        SILC_ASN1_END,
634                      SILC_ASN1_END, SILC_ASN1_END);
635   if (!success) {
636     SILC_LOG_DEBUG(("Decoding failed"));
637     goto out;
638   }
639   SILC_LOG_DEBUG(("Decoding success"));
640   SILC_LOG_DEBUG(("Boolean val %d", val));
641   SILC_LOG_DEBUG(("Ooctet-string %s, len %d", str, str_len));
642   printf("\n");
643
644 #endif
645   silc_asn1_free(asn1);
646
647  out:
648   exit(success);
649 }