b6087c47ee50a785fe317d8a5fe93d64eaf11ea0
[openafs.git] / src / rxkad / v5gen.c
1 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2 /* Do not edit */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <time.h>
7 #include <string.h>
8 #include <errno.h>
9 #include "asn1_err.h"
10
11 #define BACK if (e) return e; p -= l; len -= l; ret += l
12
13 int
14 encode_Ticket(unsigned char *p, size_t len, const Ticket * data,
15               size_t * size)
16 {
17     size_t ret = 0;
18     size_t l;
19     int i, e;
20
21     i = 0;
22     {
23         int oldret = ret;
24         ret = 0;
25         e = encode_EncryptedData(p, len, &(data)->enc_part, &l);
26         BACK;
27         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 3, &l);
28         BACK;
29         ret += oldret;
30     }
31     {
32         int oldret = ret;
33         ret = 0;
34         e = encode_PrincipalName(p, len, &(data)->sname, &l);
35         BACK;
36         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 2, &l);
37         BACK;
38         ret += oldret;
39     }
40     {
41         int oldret = ret;
42         ret = 0;
43         e = encode_Realm(p, len, &(data)->realm, &l);
44         BACK;
45         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
46         BACK;
47         ret += oldret;
48     }
49     {
50         int oldret = ret;
51         ret = 0;
52         e = encode_integer(p, len, &(data)->tkt_vno, &l);
53         BACK;
54         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
55         BACK;
56         ret += oldret;
57     }
58     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
59     BACK;
60     e = der_put_length_and_tag(p, len, ret, APPL, CONS, 1, &l);
61     BACK;
62     *size = ret;
63     return 0;
64 }
65
66 #define FORW if(e) goto fail; p += l; len -= l; ret += l
67
68 int
69 decode_Ticket(const unsigned char *p, size_t len, Ticket * data,
70               size_t * size)
71 {
72     size_t ret = 0, reallen;
73     size_t l;
74     int e;
75
76     memset(data, 0, sizeof(*data));
77     reallen = 0;
78     e = der_match_tag_and_length(p, len, APPL, CONS, 1, &reallen, &l);
79     FORW;
80     {
81         int dce_fix;
82         if ((dce_fix = fix_dce(reallen, &len)) < 0)
83             return ASN1_BAD_FORMAT;
84         e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence,
85                                      &reallen, &l);
86         FORW;
87         {
88             int dce_fix;
89             if ((dce_fix = fix_dce(reallen, &len)) < 0)
90                 return ASN1_BAD_FORMAT;
91             {
92                 size_t newlen, oldlen;
93
94                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
95                 if (e)
96                     return e;
97                 else {
98                     p += l;
99                     len -= l;
100                     ret += l;
101                     e = der_get_length(p, len, &newlen, &l);
102                     FORW;
103                     {
104                         int dce_fix;
105                         oldlen = len;
106                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
107                             return ASN1_BAD_FORMAT;
108                         e = decode_integer(p, len, &(data)->tkt_vno, &l);
109                         FORW;
110                         if (dce_fix) {
111                             e = der_match_tag_and_length(p, len,
112                                                          (Der_class) 0,
113                                                          (Der_type) 0, 0,
114                                                          &reallen, &l);
115                             FORW;
116                         } else
117                             len = oldlen - newlen;
118                     }
119                 }
120             }
121             {
122                 size_t newlen, oldlen;
123
124                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
125                 if (e)
126                     return e;
127                 else {
128                     p += l;
129                     len -= l;
130                     ret += l;
131                     e = der_get_length(p, len, &newlen, &l);
132                     FORW;
133                     {
134                         int dce_fix;
135                         oldlen = len;
136                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
137                             return ASN1_BAD_FORMAT;
138                         e = decode_Realm(p, len, &(data)->realm, &l);
139                         FORW;
140                         if (dce_fix) {
141                             e = der_match_tag_and_length(p, len,
142                                                          (Der_class) 0,
143                                                          (Der_type) 0, 0,
144                                                          &reallen, &l);
145                             FORW;
146                         } else
147                             len = oldlen - newlen;
148                     }
149                 }
150             }
151             {
152                 size_t newlen, oldlen;
153
154                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 2, &l);
155                 if (e)
156                     return e;
157                 else {
158                     p += l;
159                     len -= l;
160                     ret += l;
161                     e = der_get_length(p, len, &newlen, &l);
162                     FORW;
163                     {
164                         int dce_fix;
165                         oldlen = len;
166                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
167                             return ASN1_BAD_FORMAT;
168                         e = decode_PrincipalName(p, len, &(data)->sname, &l);
169                         FORW;
170                         if (dce_fix) {
171                             e = der_match_tag_and_length(p, len,
172                                                          (Der_class) 0,
173                                                          (Der_type) 0, 0,
174                                                          &reallen, &l);
175                             FORW;
176                         } else
177                             len = oldlen - newlen;
178                     }
179                 }
180             }
181             {
182                 size_t newlen, oldlen;
183
184                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 3, &l);
185                 if (e)
186                     return e;
187                 else {
188                     p += l;
189                     len -= l;
190                     ret += l;
191                     e = der_get_length(p, len, &newlen, &l);
192                     FORW;
193                     {
194                         int dce_fix;
195                         oldlen = len;
196                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
197                             return ASN1_BAD_FORMAT;
198                         e = decode_EncryptedData(p, len, &(data)->enc_part,
199                                                  &l);
200                         FORW;
201                         if (dce_fix) {
202                             e = der_match_tag_and_length(p, len,
203                                                          (Der_class) 0,
204                                                          (Der_type) 0, 0,
205                                                          &reallen, &l);
206                             FORW;
207                         } else
208                             len = oldlen - newlen;
209                     }
210                 }
211             }
212             if (dce_fix) {
213                 e = der_match_tag_and_length(p, len, (Der_class) 0,
214                                              (Der_type) 0, 0, &reallen, &l);
215                 FORW;
216             }
217         }
218         if (dce_fix) {
219             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
220                                          0, &reallen, &l);
221             FORW;
222         }
223     }
224     if (size)
225         *size = ret;
226     return 0;
227   fail:
228     free_Ticket(data);
229     return e;
230 }
231
232 void
233 free_Ticket(Ticket * data)
234 {
235     free_Realm(&(data)->realm);
236     free_PrincipalName(&(data)->sname);
237     free_EncryptedData(&(data)->enc_part);
238 }
239
240 size_t
241 length_Ticket(const Ticket * data)
242 {
243     size_t ret = 0;
244     {
245         int oldret = ret;
246         ret = 0;
247         ret += length_integer(&(data)->tkt_vno);
248         ret += 1 + length_len(ret) + oldret;
249     }
250     {
251         int oldret = ret;
252         ret = 0;
253         ret += length_Realm(&(data)->realm);
254         ret += 1 + length_len(ret) + oldret;
255     }
256     {
257         int oldret = ret;
258         ret = 0;
259         ret += length_PrincipalName(&(data)->sname);
260         ret += 1 + length_len(ret) + oldret;
261     }
262     {
263         int oldret = ret;
264         ret = 0;
265         ret += length_EncryptedData(&(data)->enc_part);
266         ret += 1 + length_len(ret) + oldret;
267     }
268     ret += 1 + length_len(ret);
269     ret += 1 + length_len(ret);
270     return ret;
271 }
272
273 int
274 copy_Ticket(const Ticket * from, Ticket * to)
275 {
276     *(&(to)->tkt_vno) = *(&(from)->tkt_vno);
277     if (copy_Realm(&(from)->realm, &(to)->realm))
278         return ENOMEM;
279     if (copy_PrincipalName(&(from)->sname, &(to)->sname))
280         return ENOMEM;
281     if (copy_EncryptedData(&(from)->enc_part, &(to)->enc_part))
282         return ENOMEM;
283     return 0;
284 }
285
286 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
287 /* Do not edit */
288
289 #include <stdio.h>
290 #include <stdlib.h>
291 #include <time.h>
292 #include <string.h>
293 #include <errno.h>
294 #include <asn1_err.h>
295
296 #define BACK if (e) return e; p -= l; len -= l; ret += l
297
298 int
299 encode_EncryptedData(unsigned char *p, size_t len, const EncryptedData * data,
300                      size_t * size)
301 {
302     size_t ret = 0;
303     size_t l;
304     int i, e;
305
306     i = 0;
307     {
308         int oldret = ret;
309         ret = 0;
310         e = encode_octet_string(p, len, &(data)->cipher, &l);
311         BACK;
312         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 2, &l);
313         BACK;
314         ret += oldret;
315     }
316     if ((data)->kvno) {
317         int oldret = ret;
318         ret = 0;
319         e = encode_integer(p, len, (data)->kvno, &l);
320         BACK;
321         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
322         BACK;
323         ret += oldret;
324     }
325     {
326         int oldret = ret;
327         ret = 0;
328         e = encode_ENCTYPE(p, len, &(data)->etype, &l);
329         BACK;
330         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
331         BACK;
332         ret += oldret;
333     }
334     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
335     BACK;
336     *size = ret;
337     return 0;
338 }
339
340 #define FORW if(e) goto fail; p += l; len -= l; ret += l
341
342 int
343 decode_EncryptedData(const unsigned char *p, size_t len, EncryptedData * data,
344                      size_t * size)
345 {
346     size_t ret = 0, reallen;
347     size_t l;
348     int e;
349
350     memset(data, 0, sizeof(*data));
351     reallen = 0;
352     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
353                                  &l);
354     FORW;
355     {
356         int dce_fix;
357         if ((dce_fix = fix_dce(reallen, &len)) < 0)
358             return ASN1_BAD_FORMAT;
359         {
360             size_t newlen, oldlen;
361
362             e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
363             if (e)
364                 return e;
365             else {
366                 p += l;
367                 len -= l;
368                 ret += l;
369                 e = der_get_length(p, len, &newlen, &l);
370                 FORW;
371                 {
372                     int dce_fix;
373                     oldlen = len;
374                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
375                         return ASN1_BAD_FORMAT;
376                     e = decode_ENCTYPE(p, len, &(data)->etype, &l);
377                     FORW;
378                     if (dce_fix) {
379                         e = der_match_tag_and_length(p, len, (Der_class) 0,
380                                                      (Der_type) 0, 0,
381                                                      &reallen, &l);
382                         FORW;
383                     } else
384                         len = oldlen - newlen;
385                 }
386             }
387         }
388         {
389             size_t newlen, oldlen;
390
391             e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
392             if (e)
393                 (data)->kvno = NULL;
394             else {
395                 p += l;
396                 len -= l;
397                 ret += l;
398                 e = der_get_length(p, len, &newlen, &l);
399                 FORW;
400                 {
401                     int dce_fix;
402                     oldlen = len;
403                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
404                         return ASN1_BAD_FORMAT;
405                     (data)->kvno = malloc(sizeof(*(data)->kvno));
406                     if ((data)->kvno == NULL)
407                         return ENOMEM;
408                     e = decode_integer(p, len, (data)->kvno, &l);
409                     FORW;
410                     if (dce_fix) {
411                         e = der_match_tag_and_length(p, len, (Der_class) 0,
412                                                      (Der_type) 0, 0,
413                                                      &reallen, &l);
414                         FORW;
415                     } else
416                         len = oldlen - newlen;
417                 }
418             }
419         }
420         {
421             size_t newlen, oldlen;
422
423             e = der_match_tag(p, len, Der_CONTEXT, CONS, 2, &l);
424             if (e)
425                 return e;
426             else {
427                 p += l;
428                 len -= l;
429                 ret += l;
430                 e = der_get_length(p, len, &newlen, &l);
431                 FORW;
432                 {
433                     int dce_fix;
434                     oldlen = len;
435                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
436                         return ASN1_BAD_FORMAT;
437                     e = decode_octet_string(p, len, &(data)->cipher, &l);
438                     FORW;
439                     if (dce_fix) {
440                         e = der_match_tag_and_length(p, len, (Der_class) 0,
441                                                      (Der_type) 0, 0,
442                                                      &reallen, &l);
443                         FORW;
444                     } else
445                         len = oldlen - newlen;
446                 }
447             }
448         }
449         if (dce_fix) {
450             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
451                                          0, &reallen, &l);
452             FORW;
453         }
454     }
455     if (size)
456         *size = ret;
457     return 0;
458   fail:
459     free_EncryptedData(data);
460     return e;
461 }
462
463 void
464 free_EncryptedData(EncryptedData * data)
465 {
466     free_ENCTYPE(&(data)->etype);
467     if ((data)->kvno) {
468         free((data)->kvno);
469     }
470     free_octet_string(&(data)->cipher);
471 }
472
473 size_t
474 length_EncryptedData(const EncryptedData * data)
475 {
476     size_t ret = 0;
477     {
478         int oldret = ret;
479         ret = 0;
480         ret += length_ENCTYPE(&(data)->etype);
481         ret += 1 + length_len(ret) + oldret;
482     }
483     if ((data)->kvno) {
484         int oldret = ret;
485         ret = 0;
486         ret += length_integer((data)->kvno);
487         ret += 1 + length_len(ret) + oldret;
488     }
489     {
490         int oldret = ret;
491         ret = 0;
492         ret += length_octet_string(&(data)->cipher);
493         ret += 1 + length_len(ret) + oldret;
494     }
495     ret += 1 + length_len(ret);
496     return ret;
497 }
498
499 int
500 copy_EncryptedData(const EncryptedData * from, EncryptedData * to)
501 {
502     if (copy_ENCTYPE(&(from)->etype, &(to)->etype))
503         return ENOMEM;
504     if ((from)->kvno) {
505         (to)->kvno = malloc(sizeof(*(to)->kvno));
506         if ((to)->kvno == NULL)
507             return ENOMEM;
508         *((to)->kvno) = *((from)->kvno);
509     } else
510         (to)->kvno = NULL;
511     if (copy_octet_string(&(from)->cipher, &(to)->cipher))
512         return ENOMEM;
513     return 0;
514 }
515
516 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
517 /* Do not edit */
518
519 #include <stdio.h>
520 #include <stdlib.h>
521 #include <time.h>
522 #include <string.h>
523 #include <errno.h>
524 #include <asn1_err.h>
525
526 #define BACK if (e) return e; p -= l; len -= l; ret += l
527
528 int
529 encode_PrincipalName(unsigned char *p, size_t len, const PrincipalName * data,
530                      size_t * size)
531 {
532     size_t ret = 0;
533     size_t l;
534     int i, e;
535
536     i = 0;
537     {
538         int oldret = ret;
539         ret = 0;
540         for (i = (&(data)->name_string)->len - 1; i >= 0; --i) {
541             int oldret = ret;
542             ret = 0;
543             e = encode_general_string(p, len, &(&(data)->name_string)->val[i],
544                                       &l);
545             BACK;
546             ret += oldret;
547         }
548         e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
549         BACK;
550         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
551         BACK;
552         ret += oldret;
553     }
554     {
555         int oldret = ret;
556         ret = 0;
557         e = encode_NAME_TYPE(p, len, &(data)->name_type, &l);
558         BACK;
559         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
560         BACK;
561         ret += oldret;
562     }
563     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
564     BACK;
565     *size = ret;
566     return 0;
567 }
568
569 #define FORW if(e) goto fail; p += l; len -= l; ret += l
570
571 int
572 decode_PrincipalName(const unsigned char *p, size_t len, PrincipalName * data,
573                      size_t * size)
574 {
575     size_t ret = 0, reallen;
576     size_t l;
577     int e;
578
579     memset(data, 0, sizeof(*data));
580     reallen = 0;
581     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
582                                  &l);
583     FORW;
584     {
585         int dce_fix;
586         if ((dce_fix = fix_dce(reallen, &len)) < 0)
587             return ASN1_BAD_FORMAT;
588         {
589             size_t newlen, oldlen;
590
591             e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
592             if (e)
593                 return e;
594             else {
595                 p += l;
596                 len -= l;
597                 ret += l;
598                 e = der_get_length(p, len, &newlen, &l);
599                 FORW;
600                 {
601                     int dce_fix;
602                     oldlen = len;
603                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
604                         return ASN1_BAD_FORMAT;
605                     e = decode_NAME_TYPE(p, len, &(data)->name_type, &l);
606                     FORW;
607                     if (dce_fix) {
608                         e = der_match_tag_and_length(p, len, (Der_class) 0,
609                                                      (Der_type) 0, 0,
610                                                      &reallen, &l);
611                         FORW;
612                     } else
613                         len = oldlen - newlen;
614                 }
615             }
616         }
617         {
618             size_t newlen, oldlen;
619
620             e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
621             if (e)
622                 return e;
623             else {
624                 p += l;
625                 len -= l;
626                 ret += l;
627                 e = der_get_length(p, len, &newlen, &l);
628                 FORW;
629                 {
630                     int dce_fix;
631                     oldlen = len;
632                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
633                         return ASN1_BAD_FORMAT;
634                     e = der_match_tag_and_length(p, len, UNIV, CONS,
635                                                  UT_Sequence, &reallen, &l);
636                     FORW;
637                     if (len < reallen)
638                         return ASN1_OVERRUN;
639                     len = reallen;
640                     {
641                         size_t origlen = len;
642                         int oldret = ret;
643                         ret = 0;
644                         (&(data)->name_string)->len = 0;
645                         (&(data)->name_string)->val = NULL;
646                         while (ret < origlen) {
647                             (&(data)->name_string)->len++;
648                             (&(data)->name_string)->val =
649                                 realloc((&(data)->name_string)->val,
650                                         sizeof(*((&(data)->name_string)->val))
651                                         * (&(data)->name_string)->len);
652                             e = decode_general_string(p, len,
653                                                       &(&(data)->
654                                                         name_string)->
655                                                       val[(&(data)->
656                                                            name_string)->len -
657                                                           1], &l);
658                             FORW;
659                             len = origlen - ret;
660                         }
661                         ret += oldret;
662                     }
663                     if (dce_fix) {
664                         e = der_match_tag_and_length(p, len, (Der_class) 0,
665                                                      (Der_type) 0, 0,
666                                                      &reallen, &l);
667                         FORW;
668                     } else
669                         len = oldlen - newlen;
670                 }
671             }
672         }
673         if (dce_fix) {
674             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
675                                          0, &reallen, &l);
676             FORW;
677         }
678     }
679     if (size)
680         *size = ret;
681     return 0;
682   fail:
683     free_PrincipalName(data);
684     return e;
685 }
686
687 void
688 free_PrincipalName(PrincipalName * data)
689 {
690     free_NAME_TYPE(&(data)->name_type);
691     while ((&(data)->name_string)->len) {
692         free_general_string(&(&(data)->name_string)->
693                             val[(&(data)->name_string)->len - 1]);
694         (&(data)->name_string)->len--;
695     }
696     free((&(data)->name_string)->val);
697 }
698
699 size_t
700 length_PrincipalName(const PrincipalName * data)
701 {
702     size_t ret = 0;
703     {
704         int oldret = ret;
705         ret = 0;
706         ret += length_NAME_TYPE(&(data)->name_type);
707         ret += 1 + length_len(ret) + oldret;
708     }
709     {
710         int oldret = ret;
711         ret = 0;
712         {
713             int oldret = ret;
714             int i;
715             ret = 0;
716             for (i = (&(data)->name_string)->len - 1; i >= 0; --i) {
717                 ret += length_general_string(&(&(data)->name_string)->val[i]);
718             }
719             ret += 1 + length_len(ret) + oldret;
720         }
721         ret += 1 + length_len(ret) + oldret;
722     }
723     ret += 1 + length_len(ret);
724     return ret;
725 }
726
727 int
728 copy_PrincipalName(const PrincipalName * from, PrincipalName * to)
729 {
730     if (copy_NAME_TYPE(&(from)->name_type, &(to)->name_type))
731         return ENOMEM;
732     if (((&(to)->name_string)->val =
733          malloc((&(from)->name_string)->len *
734                 sizeof(*(&(to)->name_string)->val))) == NULL
735         && (&(from)->name_string)->len != 0)
736         return ENOMEM;
737     for ((&(to)->name_string)->len = 0;
738          (&(to)->name_string)->len < (&(from)->name_string)->len;
739          (&(to)->name_string)->len++) {
740         if (copy_general_string
741             (&(&(from)->name_string)->val[(&(to)->name_string)->len],
742              &(&(to)->name_string)->val[(&(to)->name_string)->len]))
743             return ENOMEM;
744     }
745     return 0;
746 }
747
748 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
749 /* Do not edit */
750
751 #include <stdio.h>
752 #include <stdlib.h>
753 #include <time.h>
754 #include <string.h>
755 #include <errno.h>
756 #include <asn1_err.h>
757
758 #define BACK if (e) return e; p -= l; len -= l; ret += l
759
760 int
761 encode_HostAddresses(unsigned char *p, size_t len, const HostAddresses * data,
762                      size_t * size)
763 {
764     size_t ret = 0;
765     size_t l;
766     int i, e;
767
768     i = 0;
769     for (i = (data)->len - 1; i >= 0; --i) {
770         int oldret = ret;
771         ret = 0;
772         e = encode_HostAddress(p, len, &(data)->val[i], &l);
773         BACK;
774         ret += oldret;
775     }
776     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
777     BACK;
778     *size = ret;
779     return 0;
780 }
781
782 #define FORW if(e) goto fail; p += l; len -= l; ret += l
783
784 int
785 decode_HostAddresses(const unsigned char *p, size_t len, HostAddresses * data,
786                      size_t * size)
787 {
788     size_t ret = 0, reallen;
789     size_t l;
790     int e;
791
792     memset(data, 0, sizeof(*data));
793     reallen = 0;
794     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
795                                  &l);
796     FORW;
797     if (len < reallen)
798         return ASN1_OVERRUN;
799     len = reallen;
800     {
801         size_t origlen = len;
802         int oldret = ret;
803         ret = 0;
804         (data)->len = 0;
805         (data)->val = NULL;
806         while (ret < origlen) {
807             (data)->len++;
808             (data)->val =
809                 realloc((data)->val, sizeof(*((data)->val)) * (data)->len);
810             e = decode_HostAddress(p, len, &(data)->val[(data)->len - 1], &l);
811             FORW;
812             len = origlen - ret;
813         }
814         ret += oldret;
815     }
816     if (size)
817         *size = ret;
818     return 0;
819   fail:
820     free_HostAddresses(data);
821     return e;
822 }
823
824 void
825 free_HostAddresses(HostAddresses * data)
826 {
827     while ((data)->len) {
828         free_HostAddress(&(data)->val[(data)->len - 1]);
829         (data)->len--;
830     }
831     free((data)->val);
832 }
833
834 size_t
835 length_HostAddresses(const HostAddresses * data)
836 {
837     size_t ret = 0;
838     {
839         int oldret = ret;
840         int i;
841         ret = 0;
842         for (i = (data)->len - 1; i >= 0; --i) {
843             ret += length_HostAddress(&(data)->val[i]);
844         }
845         ret += 1 + length_len(ret) + oldret;
846     }
847     return ret;
848 }
849
850 int
851 copy_HostAddresses(const HostAddresses * from, HostAddresses * to)
852 {
853     if (((to)->val = malloc((from)->len * sizeof(*(to)->val))) == NULL
854         && (from)->len != 0)
855         return ENOMEM;
856     for ((to)->len = 0; (to)->len < (from)->len; (to)->len++) {
857         if (copy_HostAddress(&(from)->val[(to)->len], &(to)->val[(to)->len]))
858             return ENOMEM;
859     }
860     return 0;
861 }
862
863 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
864 /* Do not edit */
865
866 #include <stdio.h>
867 #include <stdlib.h>
868 #include <time.h>
869 #include <string.h>
870 #include <errno.h>
871 #include <asn1_err.h>
872
873 #define BACK if (e) return e; p -= l; len -= l; ret += l
874
875 int
876 encode_HostAddress(unsigned char *p, size_t len, const HostAddress * data,
877                    size_t * size)
878 {
879     size_t ret = 0;
880     size_t l;
881     int i, e;
882
883     i = 0;
884     {
885         int oldret = ret;
886         ret = 0;
887         e = encode_octet_string(p, len, &(data)->address, &l);
888         BACK;
889         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
890         BACK;
891         ret += oldret;
892     }
893     {
894         int oldret = ret;
895         ret = 0;
896         e = encode_integer(p, len, &(data)->addr_type, &l);
897         BACK;
898         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
899         BACK;
900         ret += oldret;
901     }
902     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
903     BACK;
904     *size = ret;
905     return 0;
906 }
907
908 #define FORW if(e) goto fail; p += l; len -= l; ret += l
909
910 int
911 decode_HostAddress(const unsigned char *p, size_t len, HostAddress * data,
912                    size_t * size)
913 {
914     size_t ret = 0, reallen;
915     size_t l;
916     int e;
917
918     memset(data, 0, sizeof(*data));
919     reallen = 0;
920     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
921                                  &l);
922     FORW;
923     {
924         int dce_fix;
925         if ((dce_fix = fix_dce(reallen, &len)) < 0)
926             return ASN1_BAD_FORMAT;
927         {
928             size_t newlen, oldlen;
929
930             e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
931             if (e)
932                 return e;
933             else {
934                 p += l;
935                 len -= l;
936                 ret += l;
937                 e = der_get_length(p, len, &newlen, &l);
938                 FORW;
939                 {
940                     int dce_fix;
941                     oldlen = len;
942                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
943                         return ASN1_BAD_FORMAT;
944                     e = decode_integer(p, len, &(data)->addr_type, &l);
945                     FORW;
946                     if (dce_fix) {
947                         e = der_match_tag_and_length(p, len, (Der_class) 0,
948                                                      (Der_type) 0, 0,
949                                                      &reallen, &l);
950                         FORW;
951                     } else
952                         len = oldlen - newlen;
953                 }
954             }
955         }
956         {
957             size_t newlen, oldlen;
958
959             e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
960             if (e)
961                 return e;
962             else {
963                 p += l;
964                 len -= l;
965                 ret += l;
966                 e = der_get_length(p, len, &newlen, &l);
967                 FORW;
968                 {
969                     int dce_fix;
970                     oldlen = len;
971                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
972                         return ASN1_BAD_FORMAT;
973                     e = decode_octet_string(p, len, &(data)->address, &l);
974                     FORW;
975                     if (dce_fix) {
976                         e = der_match_tag_and_length(p, len, (Der_class) 0,
977                                                      (Der_type) 0, 0,
978                                                      &reallen, &l);
979                         FORW;
980                     } else
981                         len = oldlen - newlen;
982                 }
983             }
984         }
985         if (dce_fix) {
986             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
987                                          0, &reallen, &l);
988             FORW;
989         }
990     }
991     if (size)
992         *size = ret;
993     return 0;
994   fail:
995     free_HostAddress(data);
996     return e;
997 }
998
999 void
1000 free_HostAddress(HostAddress * data)
1001 {
1002     free_octet_string(&(data)->address);
1003 }
1004
1005 size_t
1006 length_HostAddress(const HostAddress * data)
1007 {
1008     size_t ret = 0;
1009     {
1010         int oldret = ret;
1011         ret = 0;
1012         ret += length_integer(&(data)->addr_type);
1013         ret += 1 + length_len(ret) + oldret;
1014     }
1015     {
1016         int oldret = ret;
1017         ret = 0;
1018         ret += length_octet_string(&(data)->address);
1019         ret += 1 + length_len(ret) + oldret;
1020     }
1021     ret += 1 + length_len(ret);
1022     return ret;
1023 }
1024
1025 int
1026 copy_HostAddress(const HostAddress * from, HostAddress * to)
1027 {
1028     *(&(to)->addr_type) = *(&(from)->addr_type);
1029     if (copy_octet_string(&(from)->address, &(to)->address))
1030         return ENOMEM;
1031     return 0;
1032 }
1033
1034 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
1035 /* Do not edit */
1036
1037 #include <stdio.h>
1038 #include <stdlib.h>
1039 #include <time.h>
1040 #include <string.h>
1041 #include <errno.h>
1042 #include <asn1_err.h>
1043
1044 #define BACK if (e) return e; p -= l; len -= l; ret += l
1045
1046 int
1047 encode_AuthorizationData(unsigned char *p, size_t len,
1048                          const AuthorizationData * data, size_t * size)
1049 {
1050     size_t ret = 0;
1051     size_t l;
1052     int i, e;
1053
1054     i = 0;
1055     for (i = (data)->len - 1; i >= 0; --i) {
1056         int oldret = ret;
1057         ret = 0;
1058         {
1059             int oldret = ret;
1060             ret = 0;
1061             e = encode_octet_string(p, len, &(&(data)->val[i])->ad_data, &l);
1062             BACK;
1063             e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
1064             BACK;
1065             ret += oldret;
1066         }
1067         {
1068             int oldret = ret;
1069             ret = 0;
1070             e = encode_integer(p, len, &(&(data)->val[i])->ad_type, &l);
1071             BACK;
1072             e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
1073             BACK;
1074             ret += oldret;
1075         }
1076         e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
1077         BACK;
1078         ret += oldret;
1079     }
1080     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
1081     BACK;
1082     *size = ret;
1083     return 0;
1084 }
1085
1086 #define FORW if(e) goto fail; p += l; len -= l; ret += l
1087
1088 int
1089 decode_AuthorizationData(const unsigned char *p, size_t len,
1090                          AuthorizationData * data, size_t * size)
1091 {
1092     size_t ret = 0, reallen;
1093     size_t l;
1094     int e;
1095
1096     memset(data, 0, sizeof(*data));
1097     reallen = 0;
1098     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
1099                                  &l);
1100     FORW;
1101     if (len < reallen)
1102         return ASN1_OVERRUN;
1103     len = reallen;
1104     {
1105         size_t origlen = len;
1106         int oldret = ret;
1107         ret = 0;
1108         (data)->len = 0;
1109         (data)->val = NULL;
1110         while (ret < origlen) {
1111             (data)->len++;
1112             (data)->val =
1113                 realloc((data)->val, sizeof(*((data)->val)) * (data)->len);
1114             e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence,
1115                                          &reallen, &l);
1116             FORW;
1117             {
1118                 int dce_fix;
1119                 if ((dce_fix = fix_dce(reallen, &len)) < 0)
1120                     return ASN1_BAD_FORMAT;
1121                 {
1122                     size_t newlen, oldlen;
1123
1124                     e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
1125                     if (e)
1126                         return e;
1127                     else {
1128                         p += l;
1129                         len -= l;
1130                         ret += l;
1131                         e = der_get_length(p, len, &newlen, &l);
1132                         FORW;
1133                         {
1134                             int dce_fix;
1135                             oldlen = len;
1136                             if ((dce_fix = fix_dce(newlen, &len)) < 0)
1137                                 return ASN1_BAD_FORMAT;
1138                             e = decode_integer(p, len,
1139                                                &(&(data)->
1140                                                  val[(data)->len -
1141                                                      1])->ad_type, &l);
1142                             FORW;
1143                             if (dce_fix) {
1144                                 e = der_match_tag_and_length(p, len,
1145                                                              (Der_class) 0,
1146                                                              (Der_type) 0, 0,
1147                                                              &reallen, &l);
1148                                 FORW;
1149                             } else
1150                                 len = oldlen - newlen;
1151                         }
1152                     }
1153                 }
1154                 {
1155                     size_t newlen, oldlen;
1156
1157                     e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
1158                     if (e)
1159                         return e;
1160                     else {
1161                         p += l;
1162                         len -= l;
1163                         ret += l;
1164                         e = der_get_length(p, len, &newlen, &l);
1165                         FORW;
1166                         {
1167                             int dce_fix;
1168                             oldlen = len;
1169                             if ((dce_fix = fix_dce(newlen, &len)) < 0)
1170                                 return ASN1_BAD_FORMAT;
1171                             e = decode_octet_string(p, len,
1172                                                     &(&(data)->
1173                                                       val[(data)->len -
1174                                                           1])->ad_data, &l);
1175                             FORW;
1176                             if (dce_fix) {
1177                                 e = der_match_tag_and_length(p, len,
1178                                                              (Der_class) 0,
1179                                                              (Der_type) 0, 0,
1180                                                              &reallen, &l);
1181                                 FORW;
1182                             } else
1183                                 len = oldlen - newlen;
1184                         }
1185                     }
1186                 }
1187                 if (dce_fix) {
1188                     e = der_match_tag_and_length(p, len, (Der_class) 0,
1189                                                  (Der_type) 0, 0, &reallen,
1190                                                  &l);
1191                     FORW;
1192                 }
1193             }
1194             len = origlen - ret;
1195         }
1196         ret += oldret;
1197     }
1198     if (size)
1199         *size = ret;
1200     return 0;
1201   fail:
1202     free_AuthorizationData(data);
1203     return e;
1204 }
1205
1206 void
1207 free_AuthorizationData(AuthorizationData * data)
1208 {
1209     while ((data)->len) {
1210         free_octet_string(&(&(data)->val[(data)->len - 1])->ad_data);
1211         (data)->len--;
1212     }
1213     free((data)->val);
1214 }
1215
1216 size_t
1217 length_AuthorizationData(const AuthorizationData * data)
1218 {
1219     size_t ret = 0;
1220     {
1221         int oldret = ret;
1222         int i;
1223         ret = 0;
1224         for (i = (data)->len - 1; i >= 0; --i) {
1225             {
1226                 int oldret = ret;
1227                 ret = 0;
1228                 ret += length_integer(&(&(data)->val[i])->ad_type);
1229                 ret += 1 + length_len(ret) + oldret;
1230             }
1231             {
1232                 int oldret = ret;
1233                 ret = 0;
1234                 ret += length_octet_string(&(&(data)->val[i])->ad_data);
1235                 ret += 1 + length_len(ret) + oldret;
1236             }
1237             ret += 1 + length_len(ret);
1238         }
1239         ret += 1 + length_len(ret) + oldret;
1240     }
1241     return ret;
1242 }
1243
1244 int
1245 copy_AuthorizationData(const AuthorizationData * from, AuthorizationData * to)
1246 {
1247     if (((to)->val = malloc((from)->len * sizeof(*(to)->val))) == NULL
1248         && (from)->len != 0)
1249         return ENOMEM;
1250     for ((to)->len = 0; (to)->len < (from)->len; (to)->len++) {
1251         *(&(&(to)->val[(to)->len])->ad_type) =
1252             *(&(&(from)->val[(to)->len])->ad_type);
1253         if (copy_octet_string
1254             (&(&(from)->val[(to)->len])->ad_data,
1255              &(&(to)->val[(to)->len])->ad_data))
1256             return ENOMEM;
1257     }
1258     return 0;
1259 }
1260
1261 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
1262 /* Do not edit */
1263
1264 #include <stdio.h>
1265 #include <stdlib.h>
1266 #include <time.h>
1267 #include <string.h>
1268 #include <errno.h>
1269 #include <asn1_err.h>
1270
1271 #define BACK if (e) return e; p -= l; len -= l; ret += l
1272
1273 int
1274 encode_EncTicketPart(unsigned char *p, size_t len, const EncTicketPart * data,
1275                      size_t * size)
1276 {
1277     size_t ret = 0;
1278     size_t l;
1279     int i, e;
1280
1281     i = 0;
1282     if ((data)->authorization_data) {
1283         int oldret = ret;
1284         ret = 0;
1285         e = encode_AuthorizationData(p, len, (data)->authorization_data, &l);
1286         BACK;
1287         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 10, &l);
1288         BACK;
1289         ret += oldret;
1290     }
1291     if ((data)->caddr) {
1292         int oldret = ret;
1293         ret = 0;
1294         e = encode_HostAddresses(p, len, (data)->caddr, &l);
1295         BACK;
1296         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 9, &l);
1297         BACK;
1298         ret += oldret;
1299     }
1300     if ((data)->renew_till) {
1301         int oldret = ret;
1302         ret = 0;
1303         e = encode_KerberosTime(p, len, (data)->renew_till, &l);
1304         BACK;
1305         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 8, &l);
1306         BACK;
1307         ret += oldret;
1308     }
1309     {
1310         int oldret = ret;
1311         ret = 0;
1312         e = encode_KerberosTime(p, len, &(data)->endtime, &l);
1313         BACK;
1314         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 7, &l);
1315         BACK;
1316         ret += oldret;
1317     }
1318     if ((data)->starttime) {
1319         int oldret = ret;
1320         ret = 0;
1321         e = encode_KerberosTime(p, len, (data)->starttime, &l);
1322         BACK;
1323         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 6, &l);
1324         BACK;
1325         ret += oldret;
1326     }
1327     {
1328         int oldret = ret;
1329         ret = 0;
1330         e = encode_KerberosTime(p, len, &(data)->authtime, &l);
1331         BACK;
1332         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 5, &l);
1333         BACK;
1334         ret += oldret;
1335     }
1336     {
1337         int oldret = ret;
1338         ret = 0;
1339         e = encode_TransitedEncoding(p, len, &(data)->transited, &l);
1340         BACK;
1341         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 4, &l);
1342         BACK;
1343         ret += oldret;
1344     }
1345     {
1346         int oldret = ret;
1347         ret = 0;
1348         e = encode_PrincipalName(p, len, &(data)->cname, &l);
1349         BACK;
1350         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 3, &l);
1351         BACK;
1352         ret += oldret;
1353     }
1354     {
1355         int oldret = ret;
1356         ret = 0;
1357         e = encode_Realm(p, len, &(data)->crealm, &l);
1358         BACK;
1359         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 2, &l);
1360         BACK;
1361         ret += oldret;
1362     }
1363     {
1364         int oldret = ret;
1365         ret = 0;
1366         e = encode_EncryptionKey(p, len, &(data)->key, &l);
1367         BACK;
1368         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
1369         BACK;
1370         ret += oldret;
1371     }
1372     {
1373         int oldret = ret;
1374         ret = 0;
1375         e = encode_TicketFlags(p, len, &(data)->flags, &l);
1376         BACK;
1377         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
1378         BACK;
1379         ret += oldret;
1380     }
1381     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
1382     BACK;
1383     e = der_put_length_and_tag(p, len, ret, APPL, CONS, 3, &l);
1384     BACK;
1385     *size = ret;
1386     return 0;
1387 }
1388
1389 #define FORW if(e) goto fail; p += l; len -= l; ret += l
1390
1391 int
1392 decode_EncTicketPart(const unsigned char *p, size_t len, EncTicketPart * data,
1393                      size_t * size)
1394 {
1395     size_t ret = 0, reallen;
1396     size_t l;
1397     int e;
1398
1399     memset(data, 0, sizeof(*data));
1400     reallen = 0;
1401     e = der_match_tag_and_length(p, len, APPL, CONS, 3, &reallen, &l);
1402     FORW;
1403     {
1404         int dce_fix;
1405         if ((dce_fix = fix_dce(reallen, &len)) < 0)
1406             return ASN1_BAD_FORMAT;
1407         e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence,
1408                                      &reallen, &l);
1409         FORW;
1410         {
1411             int dce_fix;
1412             if ((dce_fix = fix_dce(reallen, &len)) < 0)
1413                 return ASN1_BAD_FORMAT;
1414             {
1415                 size_t newlen, oldlen;
1416
1417                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
1418                 if (e)
1419                     return e;
1420                 else {
1421                     p += l;
1422                     len -= l;
1423                     ret += l;
1424                     e = der_get_length(p, len, &newlen, &l);
1425                     FORW;
1426                     {
1427                         int dce_fix;
1428                         oldlen = len;
1429                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1430                             return ASN1_BAD_FORMAT;
1431                         e = decode_TicketFlags(p, len, &(data)->flags, &l);
1432                         FORW;
1433                         if (dce_fix) {
1434                             e = der_match_tag_and_length(p, len,
1435                                                          (Der_class) 0,
1436                                                          (Der_type) 0, 0,
1437                                                          &reallen, &l);
1438                             FORW;
1439                         } else
1440                             len = oldlen - newlen;
1441                     }
1442                 }
1443             }
1444             {
1445                 size_t newlen, oldlen;
1446
1447                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
1448                 if (e)
1449                     return e;
1450                 else {
1451                     p += l;
1452                     len -= l;
1453                     ret += l;
1454                     e = der_get_length(p, len, &newlen, &l);
1455                     FORW;
1456                     {
1457                         int dce_fix;
1458                         oldlen = len;
1459                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1460                             return ASN1_BAD_FORMAT;
1461                         e = decode_EncryptionKey(p, len, &(data)->key, &l);
1462                         FORW;
1463                         if (dce_fix) {
1464                             e = der_match_tag_and_length(p, len,
1465                                                          (Der_class) 0,
1466                                                          (Der_type) 0, 0,
1467                                                          &reallen, &l);
1468                             FORW;
1469                         } else
1470                             len = oldlen - newlen;
1471                     }
1472                 }
1473             }
1474             {
1475                 size_t newlen, oldlen;
1476
1477                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 2, &l);
1478                 if (e)
1479                     return e;
1480                 else {
1481                     p += l;
1482                     len -= l;
1483                     ret += l;
1484                     e = der_get_length(p, len, &newlen, &l);
1485                     FORW;
1486                     {
1487                         int dce_fix;
1488                         oldlen = len;
1489                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1490                             return ASN1_BAD_FORMAT;
1491                         e = decode_Realm(p, len, &(data)->crealm, &l);
1492                         FORW;
1493                         if (dce_fix) {
1494                             e = der_match_tag_and_length(p, len,
1495                                                          (Der_class) 0,
1496                                                          (Der_type) 0, 0,
1497                                                          &reallen, &l);
1498                             FORW;
1499                         } else
1500                             len = oldlen - newlen;
1501                     }
1502                 }
1503             }
1504             {
1505                 size_t newlen, oldlen;
1506
1507                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 3, &l);
1508                 if (e)
1509                     return e;
1510                 else {
1511                     p += l;
1512                     len -= l;
1513                     ret += l;
1514                     e = der_get_length(p, len, &newlen, &l);
1515                     FORW;
1516                     {
1517                         int dce_fix;
1518                         oldlen = len;
1519                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1520                             return ASN1_BAD_FORMAT;
1521                         e = decode_PrincipalName(p, len, &(data)->cname, &l);
1522                         FORW;
1523                         if (dce_fix) {
1524                             e = der_match_tag_and_length(p, len,
1525                                                          (Der_class) 0,
1526                                                          (Der_type) 0, 0,
1527                                                          &reallen, &l);
1528                             FORW;
1529                         } else
1530                             len = oldlen - newlen;
1531                     }
1532                 }
1533             }
1534             {
1535                 size_t newlen, oldlen;
1536
1537                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 4, &l);
1538                 if (e)
1539                     return e;
1540                 else {
1541                     p += l;
1542                     len -= l;
1543                     ret += l;
1544                     e = der_get_length(p, len, &newlen, &l);
1545                     FORW;
1546                     {
1547                         int dce_fix;
1548                         oldlen = len;
1549                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1550                             return ASN1_BAD_FORMAT;
1551                         e = decode_TransitedEncoding(p, len,
1552                                                      &(data)->transited, &l);
1553                         FORW;
1554                         if (dce_fix) {
1555                             e = der_match_tag_and_length(p, len,
1556                                                          (Der_class) 0,
1557                                                          (Der_type) 0, 0,
1558                                                          &reallen, &l);
1559                             FORW;
1560                         } else
1561                             len = oldlen - newlen;
1562                     }
1563                 }
1564             }
1565             {
1566                 size_t newlen, oldlen;
1567
1568                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 5, &l);
1569                 if (e)
1570                     return e;
1571                 else {
1572                     p += l;
1573                     len -= l;
1574                     ret += l;
1575                     e = der_get_length(p, len, &newlen, &l);
1576                     FORW;
1577                     {
1578                         int dce_fix;
1579                         oldlen = len;
1580                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1581                             return ASN1_BAD_FORMAT;
1582                         e = decode_KerberosTime(p, len, &(data)->authtime,
1583                                                 &l);
1584                         FORW;
1585                         if (dce_fix) {
1586                             e = der_match_tag_and_length(p, len,
1587                                                          (Der_class) 0,
1588                                                          (Der_type) 0, 0,
1589                                                          &reallen, &l);
1590                             FORW;
1591                         } else
1592                             len = oldlen - newlen;
1593                     }
1594                 }
1595             }
1596             {
1597                 size_t newlen, oldlen;
1598
1599                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 6, &l);
1600                 if (e)
1601                     (data)->starttime = NULL;
1602                 else {
1603                     p += l;
1604                     len -= l;
1605                     ret += l;
1606                     e = der_get_length(p, len, &newlen, &l);
1607                     FORW;
1608                     {
1609                         int dce_fix;
1610                         oldlen = len;
1611                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1612                             return ASN1_BAD_FORMAT;
1613                         (data)->starttime =
1614                             malloc(sizeof(*(data)->starttime));
1615                         if ((data)->starttime == NULL)
1616                             return ENOMEM;
1617                         e = decode_KerberosTime(p, len, (data)->starttime,
1618                                                 &l);
1619                         FORW;
1620                         if (dce_fix) {
1621                             e = der_match_tag_and_length(p, len,
1622                                                          (Der_class) 0,
1623                                                          (Der_type) 0, 0,
1624                                                          &reallen, &l);
1625                             FORW;
1626                         } else
1627                             len = oldlen - newlen;
1628                     }
1629                 }
1630             }
1631             {
1632                 size_t newlen, oldlen;
1633
1634                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 7, &l);
1635                 if (e)
1636                     return e;
1637                 else {
1638                     p += l;
1639                     len -= l;
1640                     ret += l;
1641                     e = der_get_length(p, len, &newlen, &l);
1642                     FORW;
1643                     {
1644                         int dce_fix;
1645                         oldlen = len;
1646                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1647                             return ASN1_BAD_FORMAT;
1648                         e = decode_KerberosTime(p, len, &(data)->endtime, &l);
1649                         FORW;
1650                         if (dce_fix) {
1651                             e = der_match_tag_and_length(p, len,
1652                                                          (Der_class) 0,
1653                                                          (Der_type) 0, 0,
1654                                                          &reallen, &l);
1655                             FORW;
1656                         } else
1657                             len = oldlen - newlen;
1658                     }
1659                 }
1660             }
1661             {
1662                 size_t newlen, oldlen;
1663
1664                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 8, &l);
1665                 if (e)
1666                     (data)->renew_till = NULL;
1667                 else {
1668                     p += l;
1669                     len -= l;
1670                     ret += l;
1671                     e = der_get_length(p, len, &newlen, &l);
1672                     FORW;
1673                     {
1674                         int dce_fix;
1675                         oldlen = len;
1676                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1677                             return ASN1_BAD_FORMAT;
1678                         (data)->renew_till =
1679                             malloc(sizeof(*(data)->renew_till));
1680                         if ((data)->renew_till == NULL)
1681                             return ENOMEM;
1682                         e = decode_KerberosTime(p, len, (data)->renew_till,
1683                                                 &l);
1684                         FORW;
1685                         if (dce_fix) {
1686                             e = der_match_tag_and_length(p, len,
1687                                                          (Der_class) 0,
1688                                                          (Der_type) 0, 0,
1689                                                          &reallen, &l);
1690                             FORW;
1691                         } else
1692                             len = oldlen - newlen;
1693                     }
1694                 }
1695             }
1696             {
1697                 size_t newlen, oldlen;
1698
1699                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 9, &l);
1700                 if (e)
1701                     (data)->caddr = NULL;
1702                 else {
1703                     p += l;
1704                     len -= l;
1705                     ret += l;
1706                     e = der_get_length(p, len, &newlen, &l);
1707                     FORW;
1708                     {
1709                         int dce_fix;
1710                         oldlen = len;
1711                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1712                             return ASN1_BAD_FORMAT;
1713                         (data)->caddr = malloc(sizeof(*(data)->caddr));
1714                         if ((data)->caddr == NULL)
1715                             return ENOMEM;
1716                         e = decode_HostAddresses(p, len, (data)->caddr, &l);
1717                         FORW;
1718                         if (dce_fix) {
1719                             e = der_match_tag_and_length(p, len,
1720                                                          (Der_class) 0,
1721                                                          (Der_type) 0, 0,
1722                                                          &reallen, &l);
1723                             FORW;
1724                         } else
1725                             len = oldlen - newlen;
1726                     }
1727                 }
1728             }
1729             {
1730                 size_t newlen, oldlen;
1731
1732                 e = der_match_tag(p, len, Der_CONTEXT, CONS, 10, &l);
1733                 if (e)
1734                     (data)->authorization_data = NULL;
1735                 else {
1736                     p += l;
1737                     len -= l;
1738                     ret += l;
1739                     e = der_get_length(p, len, &newlen, &l);
1740                     FORW;
1741                     {
1742                         int dce_fix;
1743                         oldlen = len;
1744                         if ((dce_fix = fix_dce(newlen, &len)) < 0)
1745                             return ASN1_BAD_FORMAT;
1746                         (data)->authorization_data =
1747                             malloc(sizeof(*(data)->authorization_data));
1748                         if ((data)->authorization_data == NULL)
1749                             return ENOMEM;
1750                         e = decode_AuthorizationData(p, len,
1751                                                      (data)->
1752                                                      authorization_data, &l);
1753                         FORW;
1754                         if (dce_fix) {
1755                             e = der_match_tag_and_length(p, len,
1756                                                          (Der_class) 0,
1757                                                          (Der_type) 0, 0,
1758                                                          &reallen, &l);
1759                             FORW;
1760                         } else
1761                             len = oldlen - newlen;
1762                     }
1763                 }
1764             }
1765             if (dce_fix) {
1766                 e = der_match_tag_and_length(p, len, (Der_class) 0,
1767                                              (Der_type) 0, 0, &reallen, &l);
1768                 FORW;
1769             }
1770         }
1771         if (dce_fix) {
1772             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
1773                                          0, &reallen, &l);
1774             FORW;
1775         }
1776     }
1777     if (size)
1778         *size = ret;
1779     return 0;
1780   fail:
1781     free_EncTicketPart(data);
1782     return e;
1783 }
1784
1785 void
1786 free_EncTicketPart(EncTicketPart * data)
1787 {
1788     free_TicketFlags(&(data)->flags);
1789     free_EncryptionKey(&(data)->key);
1790     free_Realm(&(data)->crealm);
1791     free_PrincipalName(&(data)->cname);
1792     free_TransitedEncoding(&(data)->transited);
1793     free_KerberosTime(&(data)->authtime);
1794     if ((data)->starttime) {
1795         free_KerberosTime((data)->starttime);
1796         free((data)->starttime);
1797     }
1798     free_KerberosTime(&(data)->endtime);
1799     if ((data)->renew_till) {
1800         free_KerberosTime((data)->renew_till);
1801         free((data)->renew_till);
1802     }
1803     if ((data)->caddr) {
1804         free_HostAddresses((data)->caddr);
1805         free((data)->caddr);
1806     }
1807     if ((data)->authorization_data) {
1808         free_AuthorizationData((data)->authorization_data);
1809         free((data)->authorization_data);
1810     }
1811 }
1812
1813 size_t
1814 length_EncTicketPart(const EncTicketPart * data)
1815 {
1816     size_t ret = 0;
1817     {
1818         int oldret = ret;
1819         ret = 0;
1820         ret += length_TicketFlags(&(data)->flags);
1821         ret += 1 + length_len(ret) + oldret;
1822     }
1823     {
1824         int oldret = ret;
1825         ret = 0;
1826         ret += length_EncryptionKey(&(data)->key);
1827         ret += 1 + length_len(ret) + oldret;
1828     }
1829     {
1830         int oldret = ret;
1831         ret = 0;
1832         ret += length_Realm(&(data)->crealm);
1833         ret += 1 + length_len(ret) + oldret;
1834     }
1835     {
1836         int oldret = ret;
1837         ret = 0;
1838         ret += length_PrincipalName(&(data)->cname);
1839         ret += 1 + length_len(ret) + oldret;
1840     }
1841     {
1842         int oldret = ret;
1843         ret = 0;
1844         ret += length_TransitedEncoding(&(data)->transited);
1845         ret += 1 + length_len(ret) + oldret;
1846     }
1847     {
1848         int oldret = ret;
1849         ret = 0;
1850         ret += length_KerberosTime(&(data)->authtime);
1851         ret += 1 + length_len(ret) + oldret;
1852     }
1853     if ((data)->starttime) {
1854         int oldret = ret;
1855         ret = 0;
1856         ret += length_KerberosTime((data)->starttime);
1857         ret += 1 + length_len(ret) + oldret;
1858     }
1859     {
1860         int oldret = ret;
1861         ret = 0;
1862         ret += length_KerberosTime(&(data)->endtime);
1863         ret += 1 + length_len(ret) + oldret;
1864     }
1865     if ((data)->renew_till) {
1866         int oldret = ret;
1867         ret = 0;
1868         ret += length_KerberosTime((data)->renew_till);
1869         ret += 1 + length_len(ret) + oldret;
1870     }
1871     if ((data)->caddr) {
1872         int oldret = ret;
1873         ret = 0;
1874         ret += length_HostAddresses((data)->caddr);
1875         ret += 1 + length_len(ret) + oldret;
1876     }
1877     if ((data)->authorization_data) {
1878         int oldret = ret;
1879         ret = 0;
1880         ret += length_AuthorizationData((data)->authorization_data);
1881         ret += 1 + length_len(ret) + oldret;
1882     }
1883     ret += 1 + length_len(ret);
1884     ret += 1 + length_len(ret);
1885     return ret;
1886 }
1887
1888 int
1889 copy_EncTicketPart(const EncTicketPart * from, EncTicketPart * to)
1890 {
1891     if (copy_TicketFlags(&(from)->flags, &(to)->flags))
1892         return ENOMEM;
1893     if (copy_EncryptionKey(&(from)->key, &(to)->key))
1894         return ENOMEM;
1895     if (copy_Realm(&(from)->crealm, &(to)->crealm))
1896         return ENOMEM;
1897     if (copy_PrincipalName(&(from)->cname, &(to)->cname))
1898         return ENOMEM;
1899     if (copy_TransitedEncoding(&(from)->transited, &(to)->transited))
1900         return ENOMEM;
1901     if (copy_KerberosTime(&(from)->authtime, &(to)->authtime))
1902         return ENOMEM;
1903     if ((from)->starttime) {
1904         (to)->starttime = malloc(sizeof(*(to)->starttime));
1905         if ((to)->starttime == NULL)
1906             return ENOMEM;
1907         if (copy_KerberosTime((from)->starttime, (to)->starttime))
1908             return ENOMEM;
1909     } else
1910         (to)->starttime = NULL;
1911     if (copy_KerberosTime(&(from)->endtime, &(to)->endtime))
1912         return ENOMEM;
1913     if ((from)->renew_till) {
1914         (to)->renew_till = malloc(sizeof(*(to)->renew_till));
1915         if ((to)->renew_till == NULL)
1916             return ENOMEM;
1917         if (copy_KerberosTime((from)->renew_till, (to)->renew_till))
1918             return ENOMEM;
1919     } else
1920         (to)->renew_till = NULL;
1921     if ((from)->caddr) {
1922         (to)->caddr = malloc(sizeof(*(to)->caddr));
1923         if ((to)->caddr == NULL)
1924             return ENOMEM;
1925         if (copy_HostAddresses((from)->caddr, (to)->caddr))
1926             return ENOMEM;
1927     } else
1928         (to)->caddr = NULL;
1929     if ((from)->authorization_data) {
1930         (to)->authorization_data = malloc(sizeof(*(to)->authorization_data));
1931         if ((to)->authorization_data == NULL)
1932             return ENOMEM;
1933         if (copy_AuthorizationData
1934             ((from)->authorization_data, (to)->authorization_data))
1935             return ENOMEM;
1936     } else
1937         (to)->authorization_data = NULL;
1938     return 0;
1939 }
1940
1941 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
1942 /* Do not edit */
1943
1944 #include <stdio.h>
1945 #include <stdlib.h>
1946 #include <time.h>
1947 #include <string.h>
1948 #include <errno.h>
1949 #include <asn1_err.h>
1950
1951 #define BACK if (e) return e; p -= l; len -= l; ret += l
1952
1953 int
1954 encode_KerberosTime(unsigned char *p, size_t len, const KerberosTime * data,
1955                     size_t * size)
1956 {
1957     size_t ret = 0;
1958     size_t l;
1959     int i, e;
1960
1961     i = 0;
1962     e = encode_generalized_time(p, len, data, &l);
1963     BACK;
1964     *size = ret;
1965     return 0;
1966 }
1967
1968 #define FORW if(e) goto fail; p += l; len -= l; ret += l
1969
1970 int
1971 decode_KerberosTime(const unsigned char *p, size_t len, KerberosTime * data,
1972                     size_t * size)
1973 {
1974     size_t ret = 0, reallen;
1975     size_t l;
1976     int e;
1977
1978     memset(data, 0, sizeof(*data));
1979     reallen = 0;
1980     e = decode_generalized_time(p, len, data, &l);
1981     FORW;
1982     if (size)
1983         *size = ret;
1984     return 0;
1985   fail:
1986     free_KerberosTime(data);
1987     return e;
1988 }
1989
1990 void
1991 free_KerberosTime(KerberosTime * data)
1992 {
1993 }
1994
1995 size_t
1996 length_KerberosTime(const KerberosTime * data)
1997 {
1998     size_t ret = 0;
1999     ret += length_generalized_time(data);
2000     return ret;
2001 }
2002
2003 int
2004 copy_KerberosTime(const KerberosTime * from, KerberosTime * to)
2005 {
2006     *(to) = *(from);
2007     return 0;
2008 }
2009
2010 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2011 /* Do not edit */
2012
2013 #include <stdio.h>
2014 #include <stdlib.h>
2015 #include <time.h>
2016 #include <string.h>
2017 #include <errno.h>
2018 #include <asn1_err.h>
2019
2020 #define BACK if (e) return e; p -= l; len -= l; ret += l
2021
2022 int
2023 encode_TransitedEncoding(unsigned char *p, size_t len,
2024                          const TransitedEncoding * data, size_t * size)
2025 {
2026     size_t ret = 0;
2027     size_t l;
2028     int i, e;
2029
2030     i = 0;
2031     {
2032         int oldret = ret;
2033         ret = 0;
2034         e = encode_octet_string(p, len, &(data)->contents, &l);
2035         BACK;
2036         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
2037         BACK;
2038         ret += oldret;
2039     }
2040     {
2041         int oldret = ret;
2042         ret = 0;
2043         e = encode_integer(p, len, &(data)->tr_type, &l);
2044         BACK;
2045         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
2046         BACK;
2047         ret += oldret;
2048     }
2049     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
2050     BACK;
2051     *size = ret;
2052     return 0;
2053 }
2054
2055 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2056
2057 int
2058 decode_TransitedEncoding(const unsigned char *p, size_t len,
2059                          TransitedEncoding * data, size_t * size)
2060 {
2061     size_t ret = 0, reallen;
2062     size_t l;
2063     int e;
2064
2065     memset(data, 0, sizeof(*data));
2066     reallen = 0;
2067     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
2068                                  &l);
2069     FORW;
2070     {
2071         int dce_fix;
2072         if ((dce_fix = fix_dce(reallen, &len)) < 0)
2073             return ASN1_BAD_FORMAT;
2074         {
2075             size_t newlen, oldlen;
2076
2077             e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
2078             if (e)
2079                 return e;
2080             else {
2081                 p += l;
2082                 len -= l;
2083                 ret += l;
2084                 e = der_get_length(p, len, &newlen, &l);
2085                 FORW;
2086                 {
2087                     int dce_fix;
2088                     oldlen = len;
2089                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
2090                         return ASN1_BAD_FORMAT;
2091                     e = decode_integer(p, len, &(data)->tr_type, &l);
2092                     FORW;
2093                     if (dce_fix) {
2094                         e = der_match_tag_and_length(p, len, (Der_class) 0,
2095                                                      (Der_type) 0, 0,
2096                                                      &reallen, &l);
2097                         FORW;
2098                     } else
2099                         len = oldlen - newlen;
2100                 }
2101             }
2102         }
2103         {
2104             size_t newlen, oldlen;
2105
2106             e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
2107             if (e)
2108                 return e;
2109             else {
2110                 p += l;
2111                 len -= l;
2112                 ret += l;
2113                 e = der_get_length(p, len, &newlen, &l);
2114                 FORW;
2115                 {
2116                     int dce_fix;
2117                     oldlen = len;
2118                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
2119                         return ASN1_BAD_FORMAT;
2120                     e = decode_octet_string(p, len, &(data)->contents, &l);
2121                     FORW;
2122                     if (dce_fix) {
2123                         e = der_match_tag_and_length(p, len, (Der_class) 0,
2124                                                      (Der_type) 0, 0,
2125                                                      &reallen, &l);
2126                         FORW;
2127                     } else
2128                         len = oldlen - newlen;
2129                 }
2130             }
2131         }
2132         if (dce_fix) {
2133             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
2134                                          0, &reallen, &l);
2135             FORW;
2136         }
2137     }
2138     if (size)
2139         *size = ret;
2140     return 0;
2141   fail:
2142     free_TransitedEncoding(data);
2143     return e;
2144 }
2145
2146 void
2147 free_TransitedEncoding(TransitedEncoding * data)
2148 {
2149     free_octet_string(&(data)->contents);
2150 }
2151
2152 size_t
2153 length_TransitedEncoding(const TransitedEncoding * data)
2154 {
2155     size_t ret = 0;
2156     {
2157         int oldret = ret;
2158         ret = 0;
2159         ret += length_integer(&(data)->tr_type);
2160         ret += 1 + length_len(ret) + oldret;
2161     }
2162     {
2163         int oldret = ret;
2164         ret = 0;
2165         ret += length_octet_string(&(data)->contents);
2166         ret += 1 + length_len(ret) + oldret;
2167     }
2168     ret += 1 + length_len(ret);
2169     return ret;
2170 }
2171
2172 int
2173 copy_TransitedEncoding(const TransitedEncoding * from, TransitedEncoding * to)
2174 {
2175     *(&(to)->tr_type) = *(&(from)->tr_type);
2176     if (copy_octet_string(&(from)->contents, &(to)->contents))
2177         return ENOMEM;
2178     return 0;
2179 }
2180
2181 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2182 /* Do not edit */
2183
2184 #include <stdio.h>
2185 #include <stdlib.h>
2186 #include <time.h>
2187 #include <string.h>
2188 #include <errno.h>
2189 #include <asn1_err.h>
2190
2191 #define BACK if (e) return e; p -= l; len -= l; ret += l
2192
2193 int
2194 encode_EncryptionKey(unsigned char *p, size_t len, const EncryptionKey * data,
2195                      size_t * size)
2196 {
2197     size_t ret = 0;
2198     size_t l;
2199     int i, e;
2200
2201     i = 0;
2202     {
2203         int oldret = ret;
2204         ret = 0;
2205         e = encode_octet_string(p, len, &(data)->keyvalue, &l);
2206         BACK;
2207         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 1, &l);
2208         BACK;
2209         ret += oldret;
2210     }
2211     {
2212         int oldret = ret;
2213         ret = 0;
2214         e = encode_integer(p, len, &(data)->keytype, &l);
2215         BACK;
2216         e = der_put_length_and_tag(p, len, ret, Der_CONTEXT, CONS, 0, &l);
2217         BACK;
2218         ret += oldret;
2219     }
2220     e = der_put_length_and_tag(p, len, ret, UNIV, CONS, UT_Sequence, &l);
2221     BACK;
2222     *size = ret;
2223     return 0;
2224 }
2225
2226 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2227
2228 int
2229 decode_EncryptionKey(const unsigned char *p, size_t len, EncryptionKey * data,
2230                      size_t * size)
2231 {
2232     size_t ret = 0, reallen;
2233     size_t l;
2234     int e;
2235
2236     memset(data, 0, sizeof(*data));
2237     reallen = 0;
2238     e = der_match_tag_and_length(p, len, UNIV, CONS, UT_Sequence, &reallen,
2239                                  &l);
2240     FORW;
2241     {
2242         int dce_fix;
2243         if ((dce_fix = fix_dce(reallen, &len)) < 0)
2244             return ASN1_BAD_FORMAT;
2245         {
2246             size_t newlen, oldlen;
2247
2248             e = der_match_tag(p, len, Der_CONTEXT, CONS, 0, &l);
2249             if (e)
2250                 return e;
2251             else {
2252                 p += l;
2253                 len -= l;
2254                 ret += l;
2255                 e = der_get_length(p, len, &newlen, &l);
2256                 FORW;
2257                 {
2258                     int dce_fix;
2259                     oldlen = len;
2260                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
2261                         return ASN1_BAD_FORMAT;
2262                     e = decode_integer(p, len, &(data)->keytype, &l);
2263                     FORW;
2264                     if (dce_fix) {
2265                         e = der_match_tag_and_length(p, len, (Der_class) 0,
2266                                                      (Der_type) 0, 0,
2267                                                      &reallen, &l);
2268                         FORW;
2269                     } else
2270                         len = oldlen - newlen;
2271                 }
2272             }
2273         }
2274         {
2275             size_t newlen, oldlen;
2276
2277             e = der_match_tag(p, len, Der_CONTEXT, CONS, 1, &l);
2278             if (e)
2279                 return e;
2280             else {
2281                 p += l;
2282                 len -= l;
2283                 ret += l;
2284                 e = der_get_length(p, len, &newlen, &l);
2285                 FORW;
2286                 {
2287                     int dce_fix;
2288                     oldlen = len;
2289                     if ((dce_fix = fix_dce(newlen, &len)) < 0)
2290                         return ASN1_BAD_FORMAT;
2291                     e = decode_octet_string(p, len, &(data)->keyvalue, &l);
2292                     FORW;
2293                     if (dce_fix) {
2294                         e = der_match_tag_and_length(p, len, (Der_class) 0,
2295                                                      (Der_type) 0, 0,
2296                                                      &reallen, &l);
2297                         FORW;
2298                     } else
2299                         len = oldlen - newlen;
2300                 }
2301             }
2302         }
2303         if (dce_fix) {
2304             e = der_match_tag_and_length(p, len, (Der_class) 0, (Der_type) 0,
2305                                          0, &reallen, &l);
2306             FORW;
2307         }
2308     }
2309     if (size)
2310         *size = ret;
2311     return 0;
2312   fail:
2313     free_EncryptionKey(data);
2314     return e;
2315 }
2316
2317 void
2318 free_EncryptionKey(EncryptionKey * data)
2319 {
2320     free_octet_string(&(data)->keyvalue);
2321 }
2322
2323 size_t
2324 length_EncryptionKey(const EncryptionKey * data)
2325 {
2326     size_t ret = 0;
2327     {
2328         int oldret = ret;
2329         ret = 0;
2330         ret += length_integer(&(data)->keytype);
2331         ret += 1 + length_len(ret) + oldret;
2332     }
2333     {
2334         int oldret = ret;
2335         ret = 0;
2336         ret += length_octet_string(&(data)->keyvalue);
2337         ret += 1 + length_len(ret) + oldret;
2338     }
2339     ret += 1 + length_len(ret);
2340     return ret;
2341 }
2342
2343 int
2344 copy_EncryptionKey(const EncryptionKey * from, EncryptionKey * to)
2345 {
2346     *(&(to)->keytype) = *(&(from)->keytype);
2347     if (copy_octet_string(&(from)->keyvalue, &(to)->keyvalue))
2348         return ENOMEM;
2349     return 0;
2350 }
2351
2352 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2353 /* Do not edit */
2354
2355 #include <stdio.h>
2356 #include <stdlib.h>
2357 #include <time.h>
2358 #include <string.h>
2359 #include <errno.h>
2360 #include <asn1_err.h>
2361
2362 #define BACK if (e) return e; p -= l; len -= l; ret += l
2363
2364 int
2365 encode_TicketFlags(unsigned char *p, size_t len, const TicketFlags * data,
2366                    size_t * size)
2367 {
2368     size_t ret = 0;
2369     size_t l;
2370     int i, e;
2371
2372     i = 0;
2373     {
2374         unsigned char c = 0;
2375         *p-- = c;
2376         len--;
2377         ret++;
2378         c = 0;
2379         *p-- = c;
2380         len--;
2381         ret++;
2382         c = 0;
2383         if (data->anonymous)
2384             c |= 1 << 1;
2385         if (data->ok_as_delegate)
2386             c |= 1 << 2;
2387         if (data->transited_policy_checked)
2388             c |= 1 << 3;
2389         if (data->hw_authent)
2390             c |= 1 << 4;
2391         if (data->pre_authent)
2392             c |= 1 << 5;
2393         if (data->initial)
2394             c |= 1 << 6;
2395         if (data->renewable)
2396             c |= 1 << 7;
2397         *p-- = c;
2398         len--;
2399         ret++;
2400         c = 0;
2401         if (data->invalid)
2402             c |= 1 << 0;
2403         if (data->postdated)
2404             c |= 1 << 1;
2405         if (data->may_postdate)
2406             c |= 1 << 2;
2407         if (data->proxy)
2408             c |= 1 << 3;
2409         if (data->proxiable)
2410             c |= 1 << 4;
2411         if (data->forwarded)
2412             c |= 1 << 5;
2413         if (data->forwardable)
2414             c |= 1 << 6;
2415         if (data->reserved)
2416             c |= 1 << 7;
2417         *p-- = c;
2418         *p-- = 0;
2419         len -= 2;
2420         ret += 2;
2421     }
2422
2423     e = der_put_length_and_tag(p, len, ret, UNIV, PRIM, UT_BitString, &l);
2424     BACK;
2425     *size = ret;
2426     return 0;
2427 }
2428
2429 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2430
2431 int
2432 decode_TicketFlags(const unsigned char *p, size_t len, TicketFlags * data,
2433                    size_t * size)
2434 {
2435     size_t ret = 0, reallen;
2436     size_t l;
2437     int e;
2438
2439     memset(data, 0, sizeof(*data));
2440     reallen = 0;
2441     e = der_match_tag_and_length(p, len, UNIV, PRIM, UT_BitString, &reallen,
2442                                  &l);
2443     FORW;
2444     if (len < reallen)
2445         return ASN1_OVERRUN;
2446     p++;
2447     len--;
2448     reallen--;
2449     ret++;
2450     data->reserved = (*p >> 7) & 1;
2451     data->forwardable = (*p >> 6) & 1;
2452     data->forwarded = (*p >> 5) & 1;
2453     data->proxiable = (*p >> 4) & 1;
2454     data->proxy = (*p >> 3) & 1;
2455     data->may_postdate = (*p >> 2) & 1;
2456     data->postdated = (*p >> 1) & 1;
2457     data->invalid = (*p >> 0) & 1;
2458     p++;
2459     len--;
2460     reallen--;
2461     ret++;
2462     data->renewable = (*p >> 7) & 1;
2463     data->initial = (*p >> 6) & 1;
2464     data->pre_authent = (*p >> 5) & 1;
2465     data->hw_authent = (*p >> 4) & 1;
2466     data->transited_policy_checked = (*p >> 3) & 1;
2467     data->ok_as_delegate = (*p >> 2) & 1;
2468     data->anonymous = (*p >> 1) & 1;
2469     p += reallen;
2470     len -= reallen;
2471     ret += reallen;
2472     if (size)
2473         *size = ret;
2474     return 0;
2475   fail:
2476     free_TicketFlags(data);
2477     return e;
2478 }
2479
2480 void
2481 free_TicketFlags(TicketFlags * data)
2482 {
2483 }
2484
2485 size_t
2486 length_TicketFlags(const TicketFlags * data)
2487 {
2488     size_t ret = 0;
2489     ret += 7;
2490     return ret;
2491 }
2492
2493 int
2494 copy_TicketFlags(const TicketFlags * from, TicketFlags * to)
2495 {
2496     *(to) = *(from);
2497     return 0;
2498 }
2499
2500 unsigned
2501 TicketFlags2int(TicketFlags f)
2502 {
2503     unsigned r = 0;
2504     if (f.reserved)
2505         r |= (1U << 0);
2506     if (f.forwardable)
2507         r |= (1U << 1);
2508     if (f.forwarded)
2509         r |= (1U << 2);
2510     if (f.proxiable)
2511         r |= (1U << 3);
2512     if (f.proxy)
2513         r |= (1U << 4);
2514     if (f.may_postdate)
2515         r |= (1U << 5);
2516     if (f.postdated)
2517         r |= (1U << 6);
2518     if (f.invalid)
2519         r |= (1U << 7);
2520     if (f.renewable)
2521         r |= (1U << 8);
2522     if (f.initial)
2523         r |= (1U << 9);
2524     if (f.pre_authent)
2525         r |= (1U << 10);
2526     if (f.hw_authent)
2527         r |= (1U << 11);
2528     if (f.transited_policy_checked)
2529         r |= (1U << 12);
2530     if (f.ok_as_delegate)
2531         r |= (1U << 13);
2532     if (f.anonymous)
2533         r |= (1U << 14);
2534     return r;
2535 }
2536
2537 TicketFlags
2538 int2TicketFlags(unsigned n)
2539 {
2540     TicketFlags flags;
2541
2542     flags.reserved = (n >> 0) & 1;
2543     flags.forwardable = (n >> 1) & 1;
2544     flags.forwarded = (n >> 2) & 1;
2545     flags.proxiable = (n >> 3) & 1;
2546     flags.proxy = (n >> 4) & 1;
2547     flags.may_postdate = (n >> 5) & 1;
2548     flags.postdated = (n >> 6) & 1;
2549     flags.invalid = (n >> 7) & 1;
2550     flags.renewable = (n >> 8) & 1;
2551     flags.initial = (n >> 9) & 1;
2552     flags.pre_authent = (n >> 10) & 1;
2553     flags.hw_authent = (n >> 11) & 1;
2554     flags.transited_policy_checked = (n >> 12) & 1;
2555     flags.ok_as_delegate = (n >> 13) & 1;
2556     flags.anonymous = (n >> 14) & 1;
2557     return flags;
2558 }
2559
2560
2561 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2562 /* Do not edit */
2563
2564 #include <stdio.h>
2565 #include <stdlib.h>
2566 #include <time.h>
2567 #include <string.h>
2568 #include <errno.h>
2569 #include <asn1_err.h>
2570
2571 #define BACK if (e) return e; p -= l; len -= l; ret += l
2572
2573 int
2574 encode_Realm(unsigned char *p, size_t len, const Realm * data, size_t * size)
2575 {
2576     size_t ret = 0;
2577     size_t l;
2578     int i, e;
2579
2580     i = 0;
2581     e = encode_general_string(p, len, data, &l);
2582     BACK;
2583     *size = ret;
2584     return 0;
2585 }
2586
2587 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2588
2589 int
2590 decode_Realm(const unsigned char *p, size_t len, Realm * data, size_t * size)
2591 {
2592     size_t ret = 0, reallen;
2593     size_t l;
2594     int e;
2595
2596     memset(data, 0, sizeof(*data));
2597     reallen = 0;
2598     e = decode_general_string(p, len, data, &l);
2599     FORW;
2600     if (size)
2601         *size = ret;
2602     return 0;
2603   fail:
2604     free_Realm(data);
2605     return e;
2606 }
2607
2608 void
2609 free_Realm(Realm * data)
2610 {
2611     free_general_string(data);
2612 }
2613
2614 size_t
2615 length_Realm(const Realm * data)
2616 {
2617     size_t ret = 0;
2618     ret += length_general_string(data);
2619     return ret;
2620 }
2621
2622 int
2623 copy_Realm(const Realm * from, Realm * to)
2624 {
2625     if (copy_general_string(from, to))
2626         return ENOMEM;
2627     return 0;
2628 }
2629
2630 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2631 /* Do not edit */
2632
2633 #include <stdio.h>
2634 #include <stdlib.h>
2635 #include <time.h>
2636 #include <string.h>
2637 #include <errno.h>
2638 #include <asn1_err.h>
2639
2640 #define BACK if (e) return e; p -= l; len -= l; ret += l
2641
2642 int
2643 encode_ENCTYPE(unsigned char *p, size_t len, const ENCTYPE * data,
2644                size_t * size)
2645 {
2646     size_t ret = 0;
2647     size_t l;
2648     int i, e;
2649
2650     i = 0;
2651     e = encode_integer(p, len, (const int *)data, &l);
2652     BACK;
2653     *size = ret;
2654     return 0;
2655 }
2656
2657 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2658
2659 int
2660 decode_ENCTYPE(const unsigned char *p, size_t len, ENCTYPE * data,
2661                size_t * size)
2662 {
2663     size_t ret = 0, reallen;
2664     size_t l;
2665     int e;
2666
2667     memset(data, 0, sizeof(*data));
2668     reallen = 0;
2669     e = decode_integer(p, len, (int *)data, &l);
2670     FORW;
2671     if (size)
2672         *size = ret;
2673     return 0;
2674   fail:
2675     free_ENCTYPE(data);
2676     return e;
2677 }
2678
2679 void
2680 free_ENCTYPE(ENCTYPE * data)
2681 {
2682 }
2683
2684 size_t
2685 length_ENCTYPE(const ENCTYPE * data)
2686 {
2687     size_t ret = 0;
2688     ret += length_integer((const int *)data);
2689     return ret;
2690 }
2691
2692 int
2693 copy_ENCTYPE(const ENCTYPE * from, ENCTYPE * to)
2694 {
2695     *(to) = *(from);
2696     return 0;
2697 }
2698
2699 /* Generated from /home/lha/src/cvs/heimdal/lib/asn1/k5.asn1 */
2700 /* Do not edit */
2701
2702 #include <stdio.h>
2703 #include <stdlib.h>
2704 #include <time.h>
2705 #include <string.h>
2706 #include <errno.h>
2707 #include <asn1_err.h>
2708
2709 #define BACK if (e) return e; p -= l; len -= l; ret += l
2710
2711 int
2712 encode_NAME_TYPE(unsigned char *p, size_t len, const NAME_TYPE * data,
2713                  size_t * size)
2714 {
2715     size_t ret = 0;
2716     size_t l;
2717     int i, e;
2718
2719     i = 0;
2720     e = encode_integer(p, len, (const int *)data, &l);
2721     BACK;
2722     *size = ret;
2723     return 0;
2724 }
2725
2726 #define FORW if(e) goto fail; p += l; len -= l; ret += l
2727
2728 int
2729 decode_NAME_TYPE(const unsigned char *p, size_t len, NAME_TYPE * data,
2730                  size_t * size)
2731 {
2732     size_t ret = 0, reallen;
2733     size_t l;
2734     int e;
2735
2736     memset(data, 0, sizeof(*data));
2737     reallen = 0;
2738     e = decode_integer(p, len, (int *)data, &l);
2739     FORW;
2740     if (size)
2741         *size = ret;
2742     return 0;
2743   fail:
2744     free_NAME_TYPE(data);
2745     return e;
2746 }
2747
2748 void
2749 free_NAME_TYPE(NAME_TYPE * data)
2750 {
2751 }
2752
2753 size_t
2754 length_NAME_TYPE(const NAME_TYPE * data)
2755 {
2756     size_t ret = 0;
2757     ret += length_integer((const int *)data);
2758     return ret;
2759 }
2760
2761 int
2762 copy_NAME_TYPE(const NAME_TYPE * from, NAME_TYPE * to)
2763 {
2764     *(to) = *(from);
2765     return 0;
2766 }