LCOV - code coverage report
Current view: top level - bin/default/third_party/heimdal/lib/asn1 - asn1_hdb_asn1.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 189 4669 4.0 %
Date: 2024-04-21 15:09:00 Functions: 20 158 12.7 %

          Line data    Source code
       1             : /* Generated from /builds/eaglegai/samba/third_party/heimdal/lib/hdb/hdb.asn1 */
       2             : /* Do not edit */
       3             : 
       4             : #if defined(_WIN32) && !defined(ASN1_LIB)
       5             : # error "ASN1_LIB must be defined"
       6             : #endif
       7             : #include <stdio.h>
       8             : #include <stdlib.h>
       9             : #include <time.h>
      10             : #include <string.h>
      11             : #include <errno.h>
      12             : #include <limits.h>
      13             : #include <krb5-types.h>
      14             : #include "hdb_asn1.h"
      15             : #include "hdb_asn1-priv.h"
      16             : #include <asn1_err.h>
      17             : #include <der.h>
      18             : #include <asn1-template.h>
      19             : 
      20             : #include <parse_units.h>
      21             : 
      22             : int ASN1CALL
      23           0 : encode_Salt(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const Salt *data, size_t *size)
      24             : {
      25           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
      26           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
      27           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
      28             : 
      29             : /* opaque */
      30           0 : if((data)->opaque) {
      31           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
      32           0 : ret = 0;
      33           0 : e = der_put_octet_string(p, len, (data)->opaque, &l);
      34           0 : if (e) return e;
      35           0 : p -= l; len -= l; ret += l;
      36             : 
      37           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
      38           0 : if (e) return e;
      39           0 : p -= l; len -= l; ret += l;
      40             : 
      41           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
      42           0 : if (e) return e;
      43           0 : p -= l; len -= l; ret += l;
      44             : 
      45           0 : ret += Top_tag_oldret;
      46             : }
      47             : /* salt */
      48             : {
      49           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
      50           0 : ret = 0;
      51           0 : e = der_put_octet_string(p, len, &(data)->salt, &l);
      52           0 : if (e) return e;
      53           0 : p -= l; len -= l; ret += l;
      54             : 
      55           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
      56           0 : if (e) return e;
      57           0 : p -= l; len -= l; ret += l;
      58             : 
      59           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
      60           0 : if (e) return e;
      61           0 : p -= l; len -= l; ret += l;
      62             : 
      63           0 : ret += Top_tag_oldret;
      64             : }
      65             : /* type */
      66             : {
      67           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
      68           0 : ret = 0;
      69           0 : e = der_put_unsigned(p, len, &(data)->type, &l);
      70           0 : if (e) return e;
      71           0 : p -= l; len -= l; ret += l;
      72             : 
      73           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
      74           0 : if (e) return e;
      75           0 : p -= l; len -= l; ret += l;
      76             : 
      77           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
      78           0 : if (e) return e;
      79           0 : p -= l; len -= l; ret += l;
      80             : 
      81           0 : ret += Top_tag_oldret;
      82             : }
      83           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
      84           0 : if (e) return e;
      85           0 : p -= l; len -= l; ret += l;
      86             : 
      87           0 : *size = ret;
      88           0 : return 0;
      89             : }
      90             : 
      91             : int ASN1CALL
      92           0 : decode_Salt(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, Salt *data, size_t *size)
      93             : {
      94           0 : size_t ret = 0;
      95           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
      96           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
      97             : 
      98           0 : memset(data, 0, sizeof(*data));
      99             : {
     100           0 : size_t Top_datalen;
     101           0 : Der_type Top_type;
     102           0 : size_t Top_oldlen;
     103           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
     104           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
     105           0 : if (e) goto fail;
     106           0 : p += l; len -= l; ret += l;
     107           0 : Top_oldlen = len;
     108           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     109           0 : len = Top_datalen;
     110             : {
     111           0 : size_t type_datalen;
     112           0 : Der_type type_type;
     113           0 : size_t type_oldlen;
     114           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &type_type, 0, &type_datalen, &l);
     115           0 : if (e == 0 && type_type != CONS) { e = ASN1_BAD_ID; }
     116           0 : if (e) goto fail;
     117           0 : p += l; len -= l; ret += l;
     118           0 : type_oldlen = len;
     119           0 : if (type_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     120           0 : len = type_datalen;
     121             : {
     122           0 : size_t type_Tag_datalen;
     123           0 : Der_type type_Tag_type;
     124           0 : size_t type_Tag_oldlen;
     125           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &type_Tag_type, UT_Integer, &type_Tag_datalen, &l);
     126           0 : if (e == 0 && type_Tag_type != PRIM) { e = ASN1_BAD_ID; }
     127           0 : if (e) goto fail;
     128           0 : p += l; len -= l; ret += l;
     129           0 : type_Tag_oldlen = len;
     130           0 : if (type_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     131           0 : len = type_Tag_datalen;
     132           0 : e = der_get_unsigned(p, len, &(data)->type, &l);
     133           0 : if(e) goto fail;
     134           0 : p += l; len -= l; ret += l;
     135           0 : len = type_Tag_oldlen - type_Tag_datalen;
     136             : }
     137           0 : len = type_oldlen - type_datalen;
     138             : }
     139             : {
     140           0 : size_t salt_datalen;
     141           0 : Der_type salt_type;
     142           0 : size_t salt_oldlen;
     143           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &salt_type, 1, &salt_datalen, &l);
     144           0 : if (e == 0 && salt_type != CONS) { e = ASN1_BAD_ID; }
     145           0 : if (e) goto fail;
     146           0 : p += l; len -= l; ret += l;
     147           0 : salt_oldlen = len;
     148           0 : if (salt_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     149           0 : len = salt_datalen;
     150             : {
     151           0 : size_t salt_Tag_datalen;
     152           0 : Der_type salt_Tag_type;
     153           0 : size_t salt_Tag_oldlen;
     154           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &salt_Tag_type, UT_OctetString, &salt_Tag_datalen, &l);
     155           0 : if (e == 0 && salt_Tag_type != PRIM) { e = ASN1_BAD_ID; }
     156           0 : if (e) goto fail;
     157           0 : p += l; len -= l; ret += l;
     158           0 : salt_Tag_oldlen = len;
     159           0 : if (salt_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     160           0 : len = salt_Tag_datalen;
     161           0 : e = der_get_octet_string(p, len, &(data)->salt, &l);
     162           0 : if(e) goto fail;
     163           0 : p += l; len -= l; ret += l;
     164           0 : len = salt_Tag_oldlen - salt_Tag_datalen;
     165             : }
     166           0 : len = salt_oldlen - salt_datalen;
     167             : }
     168             : {
     169           0 : size_t opaque_datalen;
     170           0 : Der_type opaque_type;
     171           0 : size_t opaque_oldlen;
     172           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &opaque_type, 2, &opaque_datalen, &l);
     173           0 : if (e == 0 && opaque_type != CONS) { e = ASN1_BAD_ID; }
     174           0 : if(e) {
     175           0 : (data)->opaque = NULL;
     176             : } else {
     177           0 : (data)->opaque = calloc(1, sizeof(*(data)->opaque));
     178           0 : if ((data)->opaque == NULL) { e = ENOMEM; goto fail; }
     179           0 : p += l; len -= l; ret += l;
     180           0 : opaque_oldlen = len;
     181           0 : if (opaque_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     182           0 : len = opaque_datalen;
     183             : {
     184           0 : size_t opaque_Tag_datalen;
     185           0 : Der_type opaque_Tag_type;
     186           0 : size_t opaque_Tag_oldlen;
     187           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &opaque_Tag_type, UT_OctetString, &opaque_Tag_datalen, &l);
     188           0 : if (e == 0 && opaque_Tag_type != PRIM) { e = ASN1_BAD_ID; }
     189           0 : if (e) goto fail;
     190           0 : p += l; len -= l; ret += l;
     191           0 : opaque_Tag_oldlen = len;
     192           0 : if (opaque_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     193           0 : len = opaque_Tag_datalen;
     194           0 : e = der_get_octet_string(p, len, (data)->opaque, &l);
     195           0 : if(e) goto fail;
     196           0 : p += l; len -= l; ret += l;
     197           0 : len = opaque_Tag_oldlen - opaque_Tag_datalen;
     198             : }
     199           0 : len = opaque_oldlen - opaque_datalen;
     200             : }
     201             : }
     202           0 : len = Top_oldlen - Top_datalen;
     203             : }
     204           0 : if(size) *size = ret;
     205           0 : return 0;
     206           0 : fail:
     207           0 : free_Salt(data);
     208           0 : return e;
     209             : }
     210             : 
     211             : void ASN1CALL
     212      403678 : free_Salt(Salt *data)
     213             : {
     214      403678 : *&(data)->type = 0;
     215      403678 : der_free_octet_string(&(data)->salt);
     216      403678 : if((data)->opaque) {
     217           0 : der_free_octet_string((data)->opaque);
     218           0 : free((data)->opaque);
     219           0 : (data)->opaque = NULL;
     220             : }
     221      403678 : }
     222             : 
     223             : size_t ASN1CALL
     224           0 : length_Salt(const Salt *data)
     225             : {
     226           0 : size_t ret = 0;
     227             : {
     228           0 : size_t Top_tag_oldret = ret;
     229           0 : ret = 0;
     230           0 : ret += der_length_unsigned(&(data)->type);
     231           0 : ret += 1 + der_length_len (ret);
     232           0 : ret += 1 + der_length_len (ret);
     233           0 : ret += Top_tag_oldret;
     234             : }
     235             : {
     236           0 : size_t Top_tag_oldret = ret;
     237           0 : ret = 0;
     238           0 : ret += der_length_octet_string(&(data)->salt);
     239           0 : ret += 1 + der_length_len (ret);
     240           0 : ret += 1 + der_length_len (ret);
     241           0 : ret += Top_tag_oldret;
     242             : }
     243           0 : if((data)->opaque){
     244           0 : size_t Top_tag_oldret = ret;
     245           0 : ret = 0;
     246           0 : ret += der_length_octet_string((data)->opaque);
     247           0 : ret += 1 + der_length_len (ret);
     248           0 : ret += 1 + der_length_len (ret);
     249           0 : ret += Top_tag_oldret;
     250             : }
     251           0 : ret += 1 + der_length_len (ret);
     252           0 : return ret;
     253             : }
     254             : 
     255             : int ASN1CALL
     256        8352 : copy_Salt(const Salt *from, Salt *to)
     257             : {
     258        8352 : memset(to, 0, sizeof(*to));
     259        8352 : *(&(to)->type) = *(&(from)->type);
     260        8352 : if(der_copy_octet_string(&(from)->salt, &(to)->salt)) goto fail;
     261        8352 : if((from)->opaque) {
     262           0 : (to)->opaque = calloc(1, sizeof(*(to)->opaque));
     263           0 : if((to)->opaque == NULL) goto fail;
     264           0 : if(der_copy_octet_string((from)->opaque, (to)->opaque)) goto fail;
     265             : }else
     266        8352 : (to)->opaque = NULL;
     267        8289 : return 0;
     268           0 : fail:
     269           0 : free_Salt(to);
     270           0 : return ENOMEM;
     271             : }
     272             : 
     273             : char * ASN1CALL
     274           0 : print_Salt(const Salt *data, int flags)
     275           0 : { errno = EINVAL; return 0; }
     276             : 
     277             : int ASN1CALL
     278           0 : encode_Key(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const Key *data, size_t *size)
     279             : {
     280           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
     281           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     282           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
     283             : 
     284             : /* salt */
     285           0 : if((data)->salt) {
     286           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
     287           0 : ret = 0;
     288           0 : e = encode_Salt(p, len, (data)->salt, &l);
     289           0 : if (e) return e;
     290           0 : p -= l; len -= l; ret += l;
     291             : 
     292           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
     293           0 : if (e) return e;
     294           0 : p -= l; len -= l; ret += l;
     295             : 
     296           0 : ret += Top_tag_oldret;
     297             : }
     298             : /* key */
     299             : {
     300           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
     301           0 : ret = 0;
     302           0 : e = encode_EncryptionKey(p, len, &(data)->key, &l);
     303           0 : if (e) return e;
     304           0 : p -= l; len -= l; ret += l;
     305             : 
     306           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
     307           0 : if (e) return e;
     308           0 : p -= l; len -= l; ret += l;
     309             : 
     310           0 : ret += Top_tag_oldret;
     311             : }
     312             : /* mkvno */
     313           0 : if((data)->mkvno) {
     314           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
     315           0 : ret = 0;
     316           0 : e = der_put_unsigned(p, len, (data)->mkvno, &l);
     317           0 : if (e) return e;
     318           0 : p -= l; len -= l; ret += l;
     319             : 
     320           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
     321           0 : if (e) return e;
     322           0 : p -= l; len -= l; ret += l;
     323             : 
     324           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
     325           0 : if (e) return e;
     326           0 : p -= l; len -= l; ret += l;
     327             : 
     328           0 : ret += Top_tag_oldret;
     329             : }
     330           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
     331           0 : if (e) return e;
     332           0 : p -= l; len -= l; ret += l;
     333             : 
     334           0 : *size = ret;
     335           0 : return 0;
     336             : }
     337             : 
     338             : int ASN1CALL
     339           0 : decode_Key(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, Key *data, size_t *size)
     340             : {
     341           0 : size_t ret = 0;
     342           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     343           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
     344             : 
     345           0 : memset(data, 0, sizeof(*data));
     346             : {
     347           0 : size_t Top_datalen;
     348           0 : Der_type Top_type;
     349           0 : size_t Top_oldlen;
     350           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
     351           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
     352           0 : if (e) goto fail;
     353           0 : p += l; len -= l; ret += l;
     354           0 : Top_oldlen = len;
     355           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     356           0 : len = Top_datalen;
     357             : {
     358           0 : size_t mkvno_datalen;
     359           0 : Der_type mkvno_type;
     360           0 : size_t mkvno_oldlen;
     361           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &mkvno_type, 0, &mkvno_datalen, &l);
     362           0 : if (e == 0 && mkvno_type != CONS) { e = ASN1_BAD_ID; }
     363           0 : if(e) {
     364           0 : (data)->mkvno = NULL;
     365             : } else {
     366           0 : (data)->mkvno = calloc(1, sizeof(*(data)->mkvno));
     367           0 : if ((data)->mkvno == NULL) { e = ENOMEM; goto fail; }
     368           0 : p += l; len -= l; ret += l;
     369           0 : mkvno_oldlen = len;
     370           0 : if (mkvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     371           0 : len = mkvno_datalen;
     372             : {
     373           0 : size_t mkvno_Tag_datalen;
     374           0 : Der_type mkvno_Tag_type;
     375           0 : size_t mkvno_Tag_oldlen;
     376           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &mkvno_Tag_type, UT_Integer, &mkvno_Tag_datalen, &l);
     377           0 : if (e == 0 && mkvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
     378           0 : if (e) goto fail;
     379           0 : p += l; len -= l; ret += l;
     380           0 : mkvno_Tag_oldlen = len;
     381           0 : if (mkvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     382           0 : len = mkvno_Tag_datalen;
     383           0 : e = der_get_unsigned(p, len, (data)->mkvno, &l);
     384           0 : if(e) goto fail;
     385           0 : p += l; len -= l; ret += l;
     386           0 : len = mkvno_Tag_oldlen - mkvno_Tag_datalen;
     387             : }
     388           0 : len = mkvno_oldlen - mkvno_datalen;
     389             : }
     390             : }
     391             : {
     392           0 : size_t key_datalen;
     393           0 : Der_type key_type;
     394           0 : size_t key_oldlen;
     395           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &key_type, 1, &key_datalen, &l);
     396           0 : if (e == 0 && key_type != CONS) { e = ASN1_BAD_ID; }
     397           0 : if (e) goto fail;
     398           0 : p += l; len -= l; ret += l;
     399           0 : key_oldlen = len;
     400           0 : if (key_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     401           0 : len = key_datalen;
     402           0 : e = decode_EncryptionKey(p, len, &(data)->key, &l);
     403           0 : if(e) goto fail;
     404           0 : p += l; len -= l; ret += l;
     405           0 : len = key_oldlen - key_datalen;
     406             : }
     407             : {
     408           0 : size_t salt_datalen;
     409           0 : Der_type salt_type;
     410           0 : size_t salt_oldlen;
     411           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &salt_type, 2, &salt_datalen, &l);
     412           0 : if (e == 0 && salt_type != CONS) { e = ASN1_BAD_ID; }
     413           0 : if(e) {
     414           0 : (data)->salt = NULL;
     415             : } else {
     416           0 : (data)->salt = calloc(1, sizeof(*(data)->salt));
     417           0 : if ((data)->salt == NULL) { e = ENOMEM; goto fail; }
     418           0 : p += l; len -= l; ret += l;
     419           0 : salt_oldlen = len;
     420           0 : if (salt_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     421           0 : len = salt_datalen;
     422           0 : e = decode_Salt(p, len, (data)->salt, &l);
     423           0 : if(e) goto fail;
     424           0 : p += l; len -= l; ret += l;
     425           0 : len = salt_oldlen - salt_datalen;
     426             : }
     427             : }
     428           0 : len = Top_oldlen - Top_datalen;
     429             : }
     430           0 : if(size) *size = ret;
     431           0 : return 0;
     432           0 : fail:
     433           0 : free_Key(data);
     434           0 : return e;
     435             : }
     436             : 
     437             : void ASN1CALL
     438      546898 : free_Key(Key *data)
     439             : {
     440      546898 : if((data)->mkvno) {
     441           0 : *(data)->mkvno = 0;
     442           0 : free((data)->mkvno);
     443           0 : (data)->mkvno = NULL;
     444             : }
     445      546898 : free_EncryptionKey(&(data)->key);
     446      546898 : if((data)->salt) {
     447      403678 : free_Salt((data)->salt);
     448      403678 : free((data)->salt);
     449      403678 : (data)->salt = NULL;
     450             : }
     451      546898 : }
     452             : 
     453             : size_t ASN1CALL
     454           0 : length_Key(const Key *data)
     455             : {
     456           0 : size_t ret = 0;
     457           0 : if((data)->mkvno){
     458           0 : size_t Top_tag_oldret = ret;
     459           0 : ret = 0;
     460           0 : ret += der_length_unsigned((data)->mkvno);
     461           0 : ret += 1 + der_length_len (ret);
     462           0 : ret += 1 + der_length_len (ret);
     463           0 : ret += Top_tag_oldret;
     464             : }
     465             : {
     466           0 : size_t Top_tag_oldret = ret;
     467           0 : ret = 0;
     468           0 : ret += length_EncryptionKey(&(data)->key);
     469           0 : ret += 1 + der_length_len (ret);
     470           0 : ret += Top_tag_oldret;
     471             : }
     472           0 : if((data)->salt){
     473           0 : size_t Top_tag_oldret = ret;
     474           0 : ret = 0;
     475           0 : ret += length_Salt((data)->salt);
     476           0 : ret += 1 + der_length_len (ret);
     477           0 : ret += Top_tag_oldret;
     478             : }
     479           0 : ret += 1 + der_length_len (ret);
     480           0 : return ret;
     481             : }
     482             : 
     483             : int ASN1CALL
     484       11040 : copy_Key(const Key *from, Key *to)
     485             : {
     486       11040 : memset(to, 0, sizeof(*to));
     487       11040 : if((from)->mkvno) {
     488           0 : (to)->mkvno = calloc(1, sizeof(*(to)->mkvno));
     489           0 : if((to)->mkvno == NULL) goto fail;
     490           0 : *((to)->mkvno) = *((from)->mkvno);
     491             : }else
     492       10914 : (to)->mkvno = NULL;
     493       11040 : if(copy_EncryptionKey(&(from)->key, &(to)->key)) goto fail;
     494       11040 : if((from)->salt) {
     495        8352 : (to)->salt = calloc(1, sizeof(*(to)->salt));
     496        8352 : if((to)->salt == NULL) goto fail;
     497        8352 : if(copy_Salt((from)->salt, (to)->salt)) goto fail;
     498             : }else
     499        2688 : (to)->salt = NULL;
     500       10914 : return 0;
     501           0 : fail:
     502           0 : free_Key(to);
     503           0 : return ENOMEM;
     504             : }
     505             : 
     506             : char * ASN1CALL
     507           0 : print_Key(const Key *data, int flags)
     508           0 : { errno = EINVAL; return 0; }
     509             : 
     510             : int ASN1CALL
     511           0 : encode_Event(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const Event *data, size_t *size)
     512             : {
     513           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
     514           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     515           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
     516             : 
     517             : /* principal */
     518           0 : if((data)->principal) {
     519           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
     520           0 : ret = 0;
     521           0 : e = encode_Principal(p, len, (data)->principal, &l);
     522           0 : if (e) return e;
     523           0 : p -= l; len -= l; ret += l;
     524             : 
     525           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
     526           0 : if (e) return e;
     527           0 : p -= l; len -= l; ret += l;
     528             : 
     529           0 : ret += Top_tag_oldret;
     530             : }
     531             : /* time */
     532             : {
     533           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
     534           0 : ret = 0;
     535           0 : e = encode_KerberosTime(p, len, &(data)->time, &l);
     536           0 : if (e) return e;
     537           0 : p -= l; len -= l; ret += l;
     538             : 
     539           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
     540           0 : if (e) return e;
     541           0 : p -= l; len -= l; ret += l;
     542             : 
     543           0 : ret += Top_tag_oldret;
     544             : }
     545           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
     546           0 : if (e) return e;
     547           0 : p -= l; len -= l; ret += l;
     548             : 
     549           0 : *size = ret;
     550           0 : return 0;
     551             : }
     552             : 
     553             : int ASN1CALL
     554           0 : decode_Event(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, Event *data, size_t *size)
     555             : {
     556           0 : size_t ret = 0;
     557           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     558           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
     559             : 
     560           0 : memset(data, 0, sizeof(*data));
     561             : {
     562           0 : size_t Top_datalen;
     563           0 : Der_type Top_type;
     564           0 : size_t Top_oldlen;
     565           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
     566           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
     567           0 : if (e) goto fail;
     568           0 : p += l; len -= l; ret += l;
     569           0 : Top_oldlen = len;
     570           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     571           0 : len = Top_datalen;
     572             : {
     573           0 : size_t time_datalen;
     574           0 : Der_type time_type;
     575           0 : size_t time_oldlen;
     576           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &time_type, 0, &time_datalen, &l);
     577           0 : if (e == 0 && time_type != CONS) { e = ASN1_BAD_ID; }
     578           0 : if (e) goto fail;
     579           0 : p += l; len -= l; ret += l;
     580           0 : time_oldlen = len;
     581           0 : if (time_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     582           0 : len = time_datalen;
     583           0 : e = decode_KerberosTime(p, len, &(data)->time, &l);
     584           0 : if(e) goto fail;
     585           0 : p += l; len -= l; ret += l;
     586           0 : len = time_oldlen - time_datalen;
     587             : }
     588             : {
     589           0 : size_t principal_datalen;
     590           0 : Der_type principal_type;
     591           0 : size_t principal_oldlen;
     592           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &principal_type, 1, &principal_datalen, &l);
     593           0 : if (e == 0 && principal_type != CONS) { e = ASN1_BAD_ID; }
     594           0 : if(e) {
     595           0 : (data)->principal = NULL;
     596             : } else {
     597           0 : (data)->principal = calloc(1, sizeof(*(data)->principal));
     598           0 : if ((data)->principal == NULL) { e = ENOMEM; goto fail; }
     599           0 : p += l; len -= l; ret += l;
     600           0 : principal_oldlen = len;
     601           0 : if (principal_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     602           0 : len = principal_datalen;
     603           0 : e = decode_Principal(p, len, (data)->principal, &l);
     604           0 : if(e) goto fail;
     605           0 : p += l; len -= l; ret += l;
     606           0 : len = principal_oldlen - principal_datalen;
     607             : }
     608             : }
     609           0 : len = Top_oldlen - Top_datalen;
     610             : }
     611           0 : if(size) *size = ret;
     612           0 : return 0;
     613           0 : fail:
     614           0 : free_Event(data);
     615           0 : return e;
     616             : }
     617             : 
     618             : void ASN1CALL
     619      313571 : free_Event(Event *data)
     620             : {
     621      313571 : free_KerberosTime(&(data)->time);
     622      313571 : if((data)->principal) {
     623        2089 : free_Principal((data)->principal);
     624        2089 : free((data)->principal);
     625        2089 : (data)->principal = NULL;
     626             : }
     627      313571 : }
     628             : 
     629             : size_t ASN1CALL
     630           0 : length_Event(const Event *data)
     631             : {
     632           0 : size_t ret = 0;
     633             : {
     634           0 : size_t Top_tag_oldret = ret;
     635           0 : ret = 0;
     636           0 : ret += length_KerberosTime(&(data)->time);
     637           0 : ret += 1 + der_length_len (ret);
     638           0 : ret += Top_tag_oldret;
     639             : }
     640           0 : if((data)->principal){
     641           0 : size_t Top_tag_oldret = ret;
     642           0 : ret = 0;
     643           0 : ret += length_Principal((data)->principal);
     644           0 : ret += 1 + der_length_len (ret);
     645           0 : ret += Top_tag_oldret;
     646             : }
     647           0 : ret += 1 + der_length_len (ret);
     648           0 : return ret;
     649             : }
     650             : 
     651             : int ASN1CALL
     652           0 : copy_Event(const Event *from, Event *to)
     653             : {
     654           0 : memset(to, 0, sizeof(*to));
     655           0 : if(copy_KerberosTime(&(from)->time, &(to)->time)) goto fail;
     656           0 : if((from)->principal) {
     657           0 : (to)->principal = calloc(1, sizeof(*(to)->principal));
     658           0 : if((to)->principal == NULL) goto fail;
     659           0 : if(copy_Principal((from)->principal, (to)->principal)) goto fail;
     660             : }else
     661           0 : (to)->principal = NULL;
     662           0 : return 0;
     663           0 : fail:
     664           0 : free_Event(to);
     665           0 : return ENOMEM;
     666             : }
     667             : 
     668             : char * ASN1CALL
     669           0 : print_Event(const Event *data, int flags)
     670           0 : { errno = EINVAL; return 0; }
     671             : 
     672             : int ASN1CALL
     673           0 : encode_HDBFlags(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDBFlags *data, size_t *size)
     674             : {
     675           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
     676           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     677           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
     678             : 
     679             : {
     680           0 : unsigned char c = 0;
     681           0 : int rest = 0;
     682           0 : int bit_set = 0;
     683           0 : if((data)->do_not_store) {
     684           0 : c |= 1<<0;
     685             : }
     686           0 : if((data)->force_canonicalize) {
     687           0 : c |= 1<<1;
     688             : }
     689           0 : if((data)->auth_data_reqd) {
     690           0 : c |= 1<<7;
     691             : }
     692           0 : if (c != 0 || bit_set) {
     693           0 : if (len < 1) return ASN1_OVERFLOW;
     694           0 : *p-- = c; len--; ret++;
     695           0 : if (!bit_set) {
     696           0 : rest = 0;
     697           0 : while(c) { 
     698           0 : if (c & 1) break;
     699           0 : c = c >> 1;
     700           0 : rest++;
     701             : }
     702           0 : bit_set = 1;
     703             : }
     704             : }
     705           0 : c = 0;
     706           0 : if((data)->no_auth_data_reqd) {
     707           0 : c |= 1<<0;
     708             : }
     709           0 : if((data)->synthetic) {
     710           0 : c |= 1<<1;
     711             : }
     712           0 : if((data)->virtual) {
     713           0 : c |= 1<<2;
     714             : }
     715           0 : if((data)->virtual_keys) {
     716           0 : c |= 1<<3;
     717             : }
     718           0 : if((data)->materialize) {
     719           0 : c |= 1<<4;
     720             : }
     721           0 : if((data)->require_pwchange) {
     722           0 : c |= 1<<5;
     723             : }
     724           0 : if((data)->locked_out) {
     725           0 : c |= 1<<6;
     726             : }
     727           0 : if((data)->allow_digest) {
     728           0 : c |= 1<<7;
     729             : }
     730           0 : if (c != 0 || bit_set) {
     731           0 : if (len < 1) return ASN1_OVERFLOW;
     732           0 : *p-- = c; len--; ret++;
     733           0 : if (!bit_set) {
     734           0 : rest = 0;
     735           0 : while(c) { 
     736           0 : if (c & 1) break;
     737           0 : c = c >> 1;
     738           0 : rest++;
     739             : }
     740           0 : bit_set = 1;
     741             : }
     742             : }
     743           0 : c = 0;
     744           0 : if((data)->allow_kerberos4) {
     745           0 : c |= 1<<0;
     746             : }
     747           0 : if((data)->trusted_for_delegation) {
     748           0 : c |= 1<<1;
     749             : }
     750           0 : if((data)->immutable) {
     751           0 : c |= 1<<2;
     752             : }
     753           0 : if((data)->user_to_user) {
     754           0 : c |= 1<<3;
     755             : }
     756           0 : if((data)->ok_as_delegate) {
     757           0 : c |= 1<<4;
     758             : }
     759           0 : if((data)->require_hwauth) {
     760           0 : c |= 1<<5;
     761             : }
     762           0 : if((data)->change_pw) {
     763           0 : c |= 1<<6;
     764             : }
     765           0 : if((data)->require_preauth) {
     766           0 : c |= 1<<7;
     767             : }
     768           0 : if (c != 0 || bit_set) {
     769           0 : if (len < 1) return ASN1_OVERFLOW;
     770           0 : *p-- = c; len--; ret++;
     771           0 : if (!bit_set) {
     772           0 : rest = 0;
     773           0 : while(c) { 
     774           0 : if (c & 1) break;
     775           0 : c = c >> 1;
     776           0 : rest++;
     777             : }
     778           0 : bit_set = 1;
     779             : }
     780             : }
     781           0 : c = 0;
     782           0 : if((data)->invalid) {
     783           0 : c |= 1<<0;
     784             : }
     785           0 : if((data)->client) {
     786           0 : c |= 1<<1;
     787             : }
     788           0 : if((data)->server) {
     789           0 : c |= 1<<2;
     790             : }
     791           0 : if((data)->postdate) {
     792           0 : c |= 1<<3;
     793             : }
     794           0 : if((data)->renewable) {
     795           0 : c |= 1<<4;
     796             : }
     797           0 : if((data)->proxiable) {
     798           0 : c |= 1<<5;
     799             : }
     800           0 : if((data)->forwardable) {
     801           0 : c |= 1<<6;
     802             : }
     803           0 : if((data)->initial) {
     804           0 : c |= 1<<7;
     805             : }
     806           0 : if (c != 0 || bit_set) {
     807           0 : if (len < 1) return ASN1_OVERFLOW;
     808           0 : *p-- = c; len--; ret++;
     809           0 : if (!bit_set) {
     810           0 : rest = 0;
     811           0 : if(c) { 
     812           0 : while(c) { 
     813           0 : if (c & 1) break;
     814           0 : c = c >> 1;
     815           0 : rest++;
     816             : }
     817             : }
     818             : }
     819             : }
     820           0 : if (len < 1) return ASN1_OVERFLOW;
     821           0 : *p-- = rest;
     822           0 : len -= 1;
     823           0 : ret += 1;
     824             : }
     825             : 
     826           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_BitString, &l);
     827           0 : if (e) return e;
     828           0 : p -= l; len -= l; ret += l;
     829             : 
     830           0 : *size = ret;
     831           0 : return 0;
     832             : }
     833             : 
     834             : int ASN1CALL
     835           0 : decode_HDBFlags(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDBFlags *data, size_t *size)
     836             : {
     837           0 : size_t ret = 0;
     838           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
     839           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
     840             : 
     841           0 : memset(data, 0, sizeof(*data));
     842             : {
     843           0 : size_t Top_datalen;
     844           0 : Der_type Top_type;
     845           0 : size_t Top_oldlen;
     846           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_BitString, &Top_datalen, &l);
     847           0 : if (e == 0 && Top_type != PRIM) { e = ASN1_BAD_ID; }
     848           0 : if (e) goto fail;
     849           0 : p += l; len -= l; ret += l;
     850           0 : Top_oldlen = len;
     851           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
     852           0 : len = Top_datalen;
     853           0 : if (len < 1) return ASN1_OVERRUN;
     854           0 : p++; len--; ret++;
     855           0 : do {
     856           0 : if (len < 1) break;
     857           0 : (data)->initial = (*p >> 7) & 1;
     858           0 : (data)->forwardable = (*p >> 6) & 1;
     859           0 : (data)->proxiable = (*p >> 5) & 1;
     860           0 : (data)->renewable = (*p >> 4) & 1;
     861           0 : (data)->postdate = (*p >> 3) & 1;
     862           0 : (data)->server = (*p >> 2) & 1;
     863           0 : (data)->client = (*p >> 1) & 1;
     864           0 : (data)->invalid = (*p >> 0) & 1;
     865           0 : p++; len--; ret++;
     866           0 : if (len < 1) break;
     867           0 : (data)->require_preauth = (*p >> 7) & 1;
     868           0 : (data)->change_pw = (*p >> 6) & 1;
     869           0 : (data)->require_hwauth = (*p >> 5) & 1;
     870           0 : (data)->ok_as_delegate = (*p >> 4) & 1;
     871           0 : (data)->user_to_user = (*p >> 3) & 1;
     872           0 : (data)->immutable = (*p >> 2) & 1;
     873           0 : (data)->trusted_for_delegation = (*p >> 1) & 1;
     874           0 : (data)->allow_kerberos4 = (*p >> 0) & 1;
     875           0 : p++; len--; ret++;
     876           0 : if (len < 1) break;
     877           0 : (data)->allow_digest = (*p >> 7) & 1;
     878           0 : (data)->locked_out = (*p >> 6) & 1;
     879           0 : (data)->require_pwchange = (*p >> 5) & 1;
     880           0 : (data)->materialize = (*p >> 4) & 1;
     881           0 : (data)->virtual_keys = (*p >> 3) & 1;
     882           0 : (data)->virtual = (*p >> 2) & 1;
     883           0 : (data)->synthetic = (*p >> 1) & 1;
     884           0 : (data)->no_auth_data_reqd = (*p >> 0) & 1;
     885           0 : p++; len--; ret++;
     886           0 : if (len < 1) break;
     887           0 : (data)->auth_data_reqd = (*p >> 7) & 1;
     888           0 : (data)->force_canonicalize = (*p >> 1) & 1;
     889           0 : (data)->do_not_store = (*p >> 0) & 1;
     890             : } while(0);
     891           0 : p += len; ret += len;
     892           0 : len = Top_oldlen - Top_datalen;
     893             : }
     894           0 : if(size) *size = ret;
     895           0 : return 0;
     896           0 : fail:
     897           0 : free_HDBFlags(data);
     898           0 : return e;
     899             : }
     900             : 
     901             : void ASN1CALL
     902      313571 : free_HDBFlags(HDBFlags *data)
     903             : {
     904      313571 : }
     905             : 
     906             : size_t ASN1CALL
     907           0 : length_HDBFlags(const HDBFlags *data)
     908             : {
     909           0 : size_t ret = 0;
     910           0 : do {
     911           0 : if((data)->do_not_store) { ret += 4; break; }
     912           0 : if((data)->force_canonicalize) { ret += 4; break; }
     913           0 : if((data)->auth_data_reqd) { ret += 4; break; }
     914           0 : if((data)->no_auth_data_reqd) { ret += 3; break; }
     915           0 : if((data)->synthetic) { ret += 3; break; }
     916           0 : if((data)->virtual) { ret += 3; break; }
     917           0 : if((data)->virtual_keys) { ret += 3; break; }
     918           0 : if((data)->materialize) { ret += 3; break; }
     919           0 : if((data)->require_pwchange) { ret += 3; break; }
     920           0 : if((data)->locked_out) { ret += 3; break; }
     921           0 : if((data)->allow_digest) { ret += 3; break; }
     922           0 : if((data)->allow_kerberos4) { ret += 2; break; }
     923           0 : if((data)->trusted_for_delegation) { ret += 2; break; }
     924           0 : if((data)->immutable) { ret += 2; break; }
     925           0 : if((data)->user_to_user) { ret += 2; break; }
     926           0 : if((data)->ok_as_delegate) { ret += 2; break; }
     927           0 : if((data)->require_hwauth) { ret += 2; break; }
     928           0 : if((data)->change_pw) { ret += 2; break; }
     929           0 : if((data)->require_preauth) { ret += 2; break; }
     930           0 : if((data)->invalid) { ret += 1; break; }
     931           0 : if((data)->client) { ret += 1; break; }
     932           0 : if((data)->server) { ret += 1; break; }
     933           0 : if((data)->postdate) { ret += 1; break; }
     934           0 : if((data)->renewable) { ret += 1; break; }
     935           0 : if((data)->proxiable) { ret += 1; break; }
     936           0 : if((data)->forwardable) { ret += 1; break; }
     937           0 : if((data)->initial) { ret += 1; break; }
     938             : } while(0);
     939           0 : ret += 1;
     940           0 : ret += 1 + der_length_len (ret);
     941           0 : return ret;
     942             : }
     943             : 
     944             : int ASN1CALL
     945           0 : copy_HDBFlags(const HDBFlags *from, HDBFlags *to)
     946             : {
     947           0 : memset(to, 0, sizeof(*to));
     948           0 : *(to) = *(from);
     949           0 : return 0;
     950             : }
     951             : 
     952             : char * ASN1CALL
     953           0 : print_HDBFlags(const HDBFlags *data, int flags)
     954           0 : { errno = EINVAL; return 0; }
     955             : 
     956           0 : uint64_t HDBFlags2int(HDBFlags f)
     957             : {
     958           0 : uint64_t r = 0;
     959           0 : if(f.initial) r |= (1ULL << 0);
     960           0 : if(f.forwardable) r |= (1ULL << 1);
     961           0 : if(f.proxiable) r |= (1ULL << 2);
     962           0 : if(f.renewable) r |= (1ULL << 3);
     963           0 : if(f.postdate) r |= (1ULL << 4);
     964           0 : if(f.server) r |= (1ULL << 5);
     965           0 : if(f.client) r |= (1ULL << 6);
     966           0 : if(f.invalid) r |= (1ULL << 7);
     967           0 : if(f.require_preauth) r |= (1ULL << 8);
     968           0 : if(f.change_pw) r |= (1ULL << 9);
     969           0 : if(f.require_hwauth) r |= (1ULL << 10);
     970           0 : if(f.ok_as_delegate) r |= (1ULL << 11);
     971           0 : if(f.user_to_user) r |= (1ULL << 12);
     972           0 : if(f.immutable) r |= (1ULL << 13);
     973           0 : if(f.trusted_for_delegation) r |= (1ULL << 14);
     974           0 : if(f.allow_kerberos4) r |= (1ULL << 15);
     975           0 : if(f.allow_digest) r |= (1ULL << 16);
     976           0 : if(f.locked_out) r |= (1ULL << 17);
     977           0 : if(f.require_pwchange) r |= (1ULL << 18);
     978           0 : if(f.materialize) r |= (1ULL << 19);
     979           0 : if(f.virtual_keys) r |= (1ULL << 20);
     980           0 : if(f.virtual) r |= (1ULL << 21);
     981           0 : if(f.synthetic) r |= (1ULL << 22);
     982           0 : if(f.no_auth_data_reqd) r |= (1ULL << 23);
     983           0 : if(f.auth_data_reqd) r |= (1ULL << 24);
     984           0 : if(f.force_canonicalize) r |= (1ULL << 30);
     985           0 : if(f.do_not_store) r |= (1ULL << 31);
     986           0 : return r;
     987             : }
     988             : 
     989           0 : HDBFlags int2HDBFlags(uint64_t n)
     990             : {
     991           0 :         HDBFlags flags;
     992             : 
     993           0 :         memset(&flags, 0, sizeof(flags));
     994             : 
     995           0 :         flags.initial = (n >> 0) & 1;
     996           0 :         flags.forwardable = (n >> 1) & 1;
     997           0 :         flags.proxiable = (n >> 2) & 1;
     998           0 :         flags.renewable = (n >> 3) & 1;
     999           0 :         flags.postdate = (n >> 4) & 1;
    1000           0 :         flags.server = (n >> 5) & 1;
    1001           0 :         flags.client = (n >> 6) & 1;
    1002           0 :         flags.invalid = (n >> 7) & 1;
    1003           0 :         flags.require_preauth = (n >> 8) & 1;
    1004           0 :         flags.change_pw = (n >> 9) & 1;
    1005           0 :         flags.require_hwauth = (n >> 10) & 1;
    1006           0 :         flags.ok_as_delegate = (n >> 11) & 1;
    1007           0 :         flags.user_to_user = (n >> 12) & 1;
    1008           0 :         flags.immutable = (n >> 13) & 1;
    1009           0 :         flags.trusted_for_delegation = (n >> 14) & 1;
    1010           0 :         flags.allow_kerberos4 = (n >> 15) & 1;
    1011           0 :         flags.allow_digest = (n >> 16) & 1;
    1012           0 :         flags.locked_out = (n >> 17) & 1;
    1013           0 :         flags.require_pwchange = (n >> 18) & 1;
    1014           0 :         flags.materialize = (n >> 19) & 1;
    1015           0 :         flags.virtual_keys = (n >> 20) & 1;
    1016           0 :         flags.virtual = (n >> 21) & 1;
    1017           0 :         flags.synthetic = (n >> 22) & 1;
    1018           0 :         flags.no_auth_data_reqd = (n >> 23) & 1;
    1019           0 :         flags.auth_data_reqd = (n >> 24) & 1;
    1020           0 :         flags.force_canonicalize = (n >> 30) & 1;
    1021           0 :         flags.do_not_store = (n >> 31) & 1;
    1022           0 :         return flags;
    1023             : }
    1024             : 
    1025             : static struct units HDBFlags_units[] = {
    1026             :         {"do-not-store",      1ULL << 31},
    1027             :         {"force-canonicalize",        1ULL << 30},
    1028             :         {"auth-data-reqd",    1ULL << 24},
    1029             :         {"no-auth-data-reqd", 1ULL << 23},
    1030             :         {"synthetic", 1ULL << 22},
    1031             :         {"virtual",   1ULL << 21},
    1032             :         {"virtual-keys",      1ULL << 20},
    1033             :         {"materialize",       1ULL << 19},
    1034             :         {"require-pwchange",  1ULL << 18},
    1035             :         {"locked-out",        1ULL << 17},
    1036             :         {"allow-digest",      1ULL << 16},
    1037             :         {"allow-kerberos4",   1ULL << 15},
    1038             :         {"trusted-for-delegation",    1ULL << 14},
    1039             :         {"immutable", 1ULL << 13},
    1040             :         {"user-to-user",      1ULL << 12},
    1041             :         {"ok-as-delegate",    1ULL << 11},
    1042             :         {"require-hwauth",    1ULL << 10},
    1043             :         {"change-pw", 1ULL << 9},
    1044             :         {"require-preauth",   1ULL << 8},
    1045             :         {"invalid",   1ULL << 7},
    1046             :         {"client",    1ULL << 6},
    1047             :         {"server",    1ULL << 5},
    1048             :         {"postdate",  1ULL << 4},
    1049             :         {"renewable", 1ULL << 3},
    1050             :         {"proxiable", 1ULL << 2},
    1051             :         {"forwardable",       1ULL << 1},
    1052             :         {"initial",   1ULL << 0},
    1053             :         {NULL,  0}
    1054             : };
    1055             : 
    1056           0 : const struct units * asn1_HDBFlags_units(void){
    1057           0 : return HDBFlags_units;
    1058             : }
    1059             : 
    1060             : int ASN1CALL
    1061           0 : encode_GENERATION(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const GENERATION *data, size_t *size)
    1062             : {
    1063           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    1064           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1065           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    1066             : 
    1067             : /* gen */
    1068             : {
    1069           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1070           0 : ret = 0;
    1071           0 : e = der_put_unsigned(p, len, &(data)->gen, &l);
    1072           0 : if (e) return e;
    1073           0 : p -= l; len -= l; ret += l;
    1074             : 
    1075           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    1076           0 : if (e) return e;
    1077           0 : p -= l; len -= l; ret += l;
    1078             : 
    1079           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    1080           0 : if (e) return e;
    1081           0 : p -= l; len -= l; ret += l;
    1082             : 
    1083           0 : ret += Top_tag_oldret;
    1084             : }
    1085             : /* usec */
    1086             : {
    1087           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1088           0 : ret = 0;
    1089           0 : e = der_put_unsigned(p, len, &(data)->usec, &l);
    1090           0 : if (e) return e;
    1091           0 : p -= l; len -= l; ret += l;
    1092             : 
    1093           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    1094           0 : if (e) return e;
    1095           0 : p -= l; len -= l; ret += l;
    1096             : 
    1097           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    1098           0 : if (e) return e;
    1099           0 : p -= l; len -= l; ret += l;
    1100             : 
    1101           0 : ret += Top_tag_oldret;
    1102             : }
    1103             : /* time */
    1104             : {
    1105           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1106           0 : ret = 0;
    1107           0 : e = encode_KerberosTime(p, len, &(data)->time, &l);
    1108           0 : if (e) return e;
    1109           0 : p -= l; len -= l; ret += l;
    1110             : 
    1111           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    1112           0 : if (e) return e;
    1113           0 : p -= l; len -= l; ret += l;
    1114             : 
    1115           0 : ret += Top_tag_oldret;
    1116             : }
    1117           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1118           0 : if (e) return e;
    1119           0 : p -= l; len -= l; ret += l;
    1120             : 
    1121           0 : *size = ret;
    1122           0 : return 0;
    1123             : }
    1124             : 
    1125             : int ASN1CALL
    1126           0 : decode_GENERATION(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, GENERATION *data, size_t *size)
    1127             : {
    1128           0 : size_t ret = 0;
    1129           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1130           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    1131             : 
    1132           0 : memset(data, 0, sizeof(*data));
    1133             : {
    1134           0 : size_t Top_datalen;
    1135           0 : Der_type Top_type;
    1136           0 : size_t Top_oldlen;
    1137           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    1138           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    1139           0 : if (e) goto fail;
    1140           0 : p += l; len -= l; ret += l;
    1141           0 : Top_oldlen = len;
    1142           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1143           0 : len = Top_datalen;
    1144             : {
    1145           0 : size_t time_datalen;
    1146           0 : Der_type time_type;
    1147           0 : size_t time_oldlen;
    1148           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &time_type, 0, &time_datalen, &l);
    1149           0 : if (e == 0 && time_type != CONS) { e = ASN1_BAD_ID; }
    1150           0 : if (e) goto fail;
    1151           0 : p += l; len -= l; ret += l;
    1152           0 : time_oldlen = len;
    1153           0 : if (time_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1154           0 : len = time_datalen;
    1155           0 : e = decode_KerberosTime(p, len, &(data)->time, &l);
    1156           0 : if(e) goto fail;
    1157           0 : p += l; len -= l; ret += l;
    1158           0 : len = time_oldlen - time_datalen;
    1159             : }
    1160             : {
    1161           0 : size_t usec_datalen;
    1162           0 : Der_type usec_type;
    1163           0 : size_t usec_oldlen;
    1164           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &usec_type, 1, &usec_datalen, &l);
    1165           0 : if (e == 0 && usec_type != CONS) { e = ASN1_BAD_ID; }
    1166           0 : if (e) goto fail;
    1167           0 : p += l; len -= l; ret += l;
    1168           0 : usec_oldlen = len;
    1169           0 : if (usec_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1170           0 : len = usec_datalen;
    1171             : {
    1172           0 : size_t usec_Tag_datalen;
    1173           0 : Der_type usec_Tag_type;
    1174           0 : size_t usec_Tag_oldlen;
    1175           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &usec_Tag_type, UT_Integer, &usec_Tag_datalen, &l);
    1176           0 : if (e == 0 && usec_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1177           0 : if (e) goto fail;
    1178           0 : p += l; len -= l; ret += l;
    1179           0 : usec_Tag_oldlen = len;
    1180           0 : if (usec_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1181           0 : len = usec_Tag_datalen;
    1182           0 : e = der_get_unsigned(p, len, &(data)->usec, &l);
    1183           0 : if(e) goto fail;
    1184           0 : p += l; len -= l; ret += l;
    1185           0 : len = usec_Tag_oldlen - usec_Tag_datalen;
    1186             : }
    1187           0 : len = usec_oldlen - usec_datalen;
    1188             : }
    1189             : {
    1190           0 : size_t gen_datalen;
    1191           0 : Der_type gen_type;
    1192           0 : size_t gen_oldlen;
    1193           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &gen_type, 2, &gen_datalen, &l);
    1194           0 : if (e == 0 && gen_type != CONS) { e = ASN1_BAD_ID; }
    1195           0 : if (e) goto fail;
    1196           0 : p += l; len -= l; ret += l;
    1197           0 : gen_oldlen = len;
    1198           0 : if (gen_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1199           0 : len = gen_datalen;
    1200             : {
    1201           0 : size_t gen_Tag_datalen;
    1202           0 : Der_type gen_Tag_type;
    1203           0 : size_t gen_Tag_oldlen;
    1204           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &gen_Tag_type, UT_Integer, &gen_Tag_datalen, &l);
    1205           0 : if (e == 0 && gen_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1206           0 : if (e) goto fail;
    1207           0 : p += l; len -= l; ret += l;
    1208           0 : gen_Tag_oldlen = len;
    1209           0 : if (gen_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1210           0 : len = gen_Tag_datalen;
    1211           0 : e = der_get_unsigned(p, len, &(data)->gen, &l);
    1212           0 : if(e) goto fail;
    1213           0 : p += l; len -= l; ret += l;
    1214           0 : len = gen_Tag_oldlen - gen_Tag_datalen;
    1215             : }
    1216           0 : len = gen_oldlen - gen_datalen;
    1217             : }
    1218           0 : len = Top_oldlen - Top_datalen;
    1219             : }
    1220           0 : if(size) *size = ret;
    1221           0 : return 0;
    1222           0 : fail:
    1223           0 : free_GENERATION(data);
    1224           0 : return e;
    1225             : }
    1226             : 
    1227             : void ASN1CALL
    1228           0 : free_GENERATION(GENERATION *data)
    1229             : {
    1230           0 : free_KerberosTime(&(data)->time);
    1231           0 : *&(data)->usec = 0;
    1232           0 : *&(data)->gen = 0;
    1233           0 : }
    1234             : 
    1235             : size_t ASN1CALL
    1236           0 : length_GENERATION(const GENERATION *data)
    1237             : {
    1238           0 : size_t ret = 0;
    1239             : {
    1240           0 : size_t Top_tag_oldret = ret;
    1241           0 : ret = 0;
    1242           0 : ret += length_KerberosTime(&(data)->time);
    1243           0 : ret += 1 + der_length_len (ret);
    1244           0 : ret += Top_tag_oldret;
    1245             : }
    1246             : {
    1247           0 : size_t Top_tag_oldret = ret;
    1248           0 : ret = 0;
    1249           0 : ret += der_length_unsigned(&(data)->usec);
    1250           0 : ret += 1 + der_length_len (ret);
    1251           0 : ret += 1 + der_length_len (ret);
    1252           0 : ret += Top_tag_oldret;
    1253             : }
    1254             : {
    1255           0 : size_t Top_tag_oldret = ret;
    1256           0 : ret = 0;
    1257           0 : ret += der_length_unsigned(&(data)->gen);
    1258           0 : ret += 1 + der_length_len (ret);
    1259           0 : ret += 1 + der_length_len (ret);
    1260           0 : ret += Top_tag_oldret;
    1261             : }
    1262           0 : ret += 1 + der_length_len (ret);
    1263           0 : return ret;
    1264             : }
    1265             : 
    1266             : int ASN1CALL
    1267           0 : copy_GENERATION(const GENERATION *from, GENERATION *to)
    1268             : {
    1269           0 : memset(to, 0, sizeof(*to));
    1270           0 : if(copy_KerberosTime(&(from)->time, &(to)->time)) goto fail;
    1271           0 : *(&(to)->usec) = *(&(from)->usec);
    1272           0 : *(&(to)->gen) = *(&(from)->gen);
    1273           0 : return 0;
    1274           0 : fail:
    1275           0 : free_GENERATION(to);
    1276           0 : return ENOMEM;
    1277             : }
    1278             : 
    1279             : char * ASN1CALL
    1280           0 : print_GENERATION(const GENERATION *data, int flags)
    1281           0 : { errno = EINVAL; return 0; }
    1282             : 
    1283             : int ASN1CALL
    1284           0 : encode_HDB_Ext_PKINIT_acl(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_PKINIT_acl *data, size_t *size)
    1285             : {
    1286           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    1287           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1288           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    1289             : 
    1290           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    1291           0 : size_t Top_tag_for_oldret = ret;
    1292           0 : ret = 0;
    1293             : /* anchor */
    1294           0 : if((&(data)->val[i])->anchor) {
    1295           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1296           0 : ret = 0;
    1297           0 : e = der_put_utf8string(p, len, (&(data)->val[i])->anchor, &l);
    1298           0 : if (e) return e;
    1299           0 : p -= l; len -= l; ret += l;
    1300             : 
    1301           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_UTF8String, &l);
    1302           0 : if (e) return e;
    1303           0 : p -= l; len -= l; ret += l;
    1304             : 
    1305           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    1306           0 : if (e) return e;
    1307           0 : p -= l; len -= l; ret += l;
    1308             : 
    1309           0 : ret += Top_tag_S_Of_tag_oldret;
    1310             : }
    1311             : /* issuer */
    1312           0 : if((&(data)->val[i])->issuer) {
    1313           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1314           0 : ret = 0;
    1315           0 : e = der_put_utf8string(p, len, (&(data)->val[i])->issuer, &l);
    1316           0 : if (e) return e;
    1317           0 : p -= l; len -= l; ret += l;
    1318             : 
    1319           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_UTF8String, &l);
    1320           0 : if (e) return e;
    1321           0 : p -= l; len -= l; ret += l;
    1322             : 
    1323           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    1324           0 : if (e) return e;
    1325           0 : p -= l; len -= l; ret += l;
    1326             : 
    1327           0 : ret += Top_tag_S_Of_tag_oldret;
    1328             : }
    1329             : /* subject */
    1330             : {
    1331           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1332           0 : ret = 0;
    1333           0 : e = der_put_utf8string(p, len, &(&(data)->val[i])->subject, &l);
    1334           0 : if (e) return e;
    1335           0 : p -= l; len -= l; ret += l;
    1336             : 
    1337           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_UTF8String, &l);
    1338           0 : if (e) return e;
    1339           0 : p -= l; len -= l; ret += l;
    1340             : 
    1341           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    1342           0 : if (e) return e;
    1343           0 : p -= l; len -= l; ret += l;
    1344             : 
    1345           0 : ret += Top_tag_S_Of_tag_oldret;
    1346             : }
    1347           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1348           0 : if (e) return e;
    1349           0 : p -= l; len -= l; ret += l;
    1350             : 
    1351           0 : ret += Top_tag_for_oldret;
    1352             : }
    1353           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1354           0 : if (e) return e;
    1355           0 : p -= l; len -= l; ret += l;
    1356             : 
    1357           0 : *size = ret;
    1358           0 : return 0;
    1359             : }
    1360             : 
    1361             : int ASN1CALL
    1362           0 : decode_HDB_Ext_PKINIT_acl(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_PKINIT_acl *data, size_t *size)
    1363             : {
    1364           0 : size_t ret = 0;
    1365           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1366           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    1367             : 
    1368           0 : memset(data, 0, sizeof(*data));
    1369             : {
    1370           0 : size_t Top_datalen;
    1371           0 : Der_type Top_type;
    1372           0 : size_t Top_oldlen;
    1373           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    1374           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    1375           0 : if (e) goto fail;
    1376           0 : p += l; len -= l; ret += l;
    1377           0 : Top_oldlen = len;
    1378           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1379           0 : len = Top_datalen;
    1380             : {
    1381           0 : size_t Top_Tag_origlen = len;
    1382           0 : size_t Top_Tag_oldret = ret;
    1383           0 : size_t Top_Tag_olen = 0;
    1384           0 : void *Top_Tag_tmp;
    1385           0 : ret = 0;
    1386           0 : (data)->len = 0;
    1387           0 : (data)->val = NULL;
    1388           0 : while(ret < Top_Tag_origlen) {
    1389           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    1390           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    1391           0 : Top_Tag_olen = Top_Tag_nlen;
    1392           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    1393           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    1394           0 : (data)->val = Top_Tag_tmp;
    1395             : {
    1396           0 : size_t Top_Tag_s_of_datalen;
    1397           0 : Der_type Top_Tag_s_of_type;
    1398           0 : size_t Top_Tag_s_of_oldlen;
    1399           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_Tag_s_of_type, UT_Sequence, &Top_Tag_s_of_datalen, &l);
    1400           0 : if (e == 0 && Top_Tag_s_of_type != CONS) { e = ASN1_BAD_ID; }
    1401           0 : if (e) goto fail;
    1402           0 : p += l; len -= l; ret += l;
    1403           0 : Top_Tag_s_of_oldlen = len;
    1404           0 : if (Top_Tag_s_of_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1405           0 : len = Top_Tag_s_of_datalen;
    1406             : {
    1407           0 : size_t subject_datalen;
    1408           0 : Der_type subject_type;
    1409           0 : size_t subject_oldlen;
    1410           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &subject_type, 0, &subject_datalen, &l);
    1411           0 : if (e == 0 && subject_type != CONS) { e = ASN1_BAD_ID; }
    1412           0 : if (e) goto fail;
    1413           0 : p += l; len -= l; ret += l;
    1414           0 : subject_oldlen = len;
    1415           0 : if (subject_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1416           0 : len = subject_datalen;
    1417             : {
    1418           0 : size_t subject_Tag_datalen;
    1419           0 : Der_type subject_Tag_type;
    1420           0 : size_t subject_Tag_oldlen;
    1421           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &subject_Tag_type, UT_UTF8String, &subject_Tag_datalen, &l);
    1422           0 : if (e == 0 && subject_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1423           0 : if (e) goto fail;
    1424           0 : p += l; len -= l; ret += l;
    1425           0 : subject_Tag_oldlen = len;
    1426           0 : if (subject_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1427           0 : len = subject_Tag_datalen;
    1428           0 : e = der_get_utf8string(p, len, &(&(data)->val[(data)->len])->subject, &l);
    1429           0 : if(e) goto fail;
    1430           0 : p += l; len -= l; ret += l;
    1431           0 : len = subject_Tag_oldlen - subject_Tag_datalen;
    1432             : }
    1433           0 : len = subject_oldlen - subject_datalen;
    1434             : }
    1435             : {
    1436           0 : size_t issuer_datalen;
    1437           0 : Der_type issuer_type;
    1438           0 : size_t issuer_oldlen;
    1439           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &issuer_type, 1, &issuer_datalen, &l);
    1440           0 : if (e == 0 && issuer_type != CONS) { e = ASN1_BAD_ID; }
    1441           0 : if(e) {
    1442           0 : (&(data)->val[(data)->len])->issuer = NULL;
    1443             : } else {
    1444           0 : (&(data)->val[(data)->len])->issuer = calloc(1, sizeof(*(&(data)->val[(data)->len])->issuer));
    1445           0 : if ((&(data)->val[(data)->len])->issuer == NULL) { e = ENOMEM; goto fail; }
    1446           0 : p += l; len -= l; ret += l;
    1447           0 : issuer_oldlen = len;
    1448           0 : if (issuer_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1449           0 : len = issuer_datalen;
    1450             : {
    1451           0 : size_t issuer_Tag_datalen;
    1452           0 : Der_type issuer_Tag_type;
    1453           0 : size_t issuer_Tag_oldlen;
    1454           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &issuer_Tag_type, UT_UTF8String, &issuer_Tag_datalen, &l);
    1455           0 : if (e == 0 && issuer_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1456           0 : if (e) goto fail;
    1457           0 : p += l; len -= l; ret += l;
    1458           0 : issuer_Tag_oldlen = len;
    1459           0 : if (issuer_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1460           0 : len = issuer_Tag_datalen;
    1461           0 : e = der_get_utf8string(p, len, (&(data)->val[(data)->len])->issuer, &l);
    1462           0 : if(e) goto fail;
    1463           0 : p += l; len -= l; ret += l;
    1464           0 : len = issuer_Tag_oldlen - issuer_Tag_datalen;
    1465             : }
    1466           0 : len = issuer_oldlen - issuer_datalen;
    1467             : }
    1468             : }
    1469             : {
    1470           0 : size_t anchor_datalen;
    1471           0 : Der_type anchor_type;
    1472           0 : size_t anchor_oldlen;
    1473           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &anchor_type, 2, &anchor_datalen, &l);
    1474           0 : if (e == 0 && anchor_type != CONS) { e = ASN1_BAD_ID; }
    1475           0 : if(e) {
    1476           0 : (&(data)->val[(data)->len])->anchor = NULL;
    1477             : } else {
    1478           0 : (&(data)->val[(data)->len])->anchor = calloc(1, sizeof(*(&(data)->val[(data)->len])->anchor));
    1479           0 : if ((&(data)->val[(data)->len])->anchor == NULL) { e = ENOMEM; goto fail; }
    1480           0 : p += l; len -= l; ret += l;
    1481           0 : anchor_oldlen = len;
    1482           0 : if (anchor_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1483           0 : len = anchor_datalen;
    1484             : {
    1485           0 : size_t anchor_Tag_datalen;
    1486           0 : Der_type anchor_Tag_type;
    1487           0 : size_t anchor_Tag_oldlen;
    1488           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &anchor_Tag_type, UT_UTF8String, &anchor_Tag_datalen, &l);
    1489           0 : if (e == 0 && anchor_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1490           0 : if (e) goto fail;
    1491           0 : p += l; len -= l; ret += l;
    1492           0 : anchor_Tag_oldlen = len;
    1493           0 : if (anchor_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1494           0 : len = anchor_Tag_datalen;
    1495           0 : e = der_get_utf8string(p, len, (&(data)->val[(data)->len])->anchor, &l);
    1496           0 : if(e) goto fail;
    1497           0 : p += l; len -= l; ret += l;
    1498           0 : len = anchor_Tag_oldlen - anchor_Tag_datalen;
    1499             : }
    1500           0 : len = anchor_oldlen - anchor_datalen;
    1501             : }
    1502             : }
    1503           0 : len = Top_Tag_s_of_oldlen - Top_Tag_s_of_datalen;
    1504             : }
    1505           0 : (data)->len++;
    1506           0 : len = Top_Tag_origlen - ret;
    1507             : }
    1508           0 : ret += Top_Tag_oldret;
    1509             : }
    1510           0 : len = Top_oldlen - Top_datalen;
    1511             : }
    1512           0 : if(size) *size = ret;
    1513           0 : return 0;
    1514           0 : fail:
    1515           0 : free_HDB_Ext_PKINIT_acl(data);
    1516           0 : return e;
    1517             : }
    1518             : 
    1519             : void ASN1CALL
    1520           0 : free_HDB_Ext_PKINIT_acl(HDB_Ext_PKINIT_acl *data)
    1521             : {
    1522           0 : if ((data)->val)
    1523           0 : while((data)->len){
    1524           0 : der_free_utf8string(&(&(data)->val[(data)->len-1])->subject);
    1525           0 : if((&(data)->val[(data)->len-1])->issuer) {
    1526           0 : der_free_utf8string((&(data)->val[(data)->len-1])->issuer);
    1527           0 : free((&(data)->val[(data)->len-1])->issuer);
    1528           0 : (&(data)->val[(data)->len-1])->issuer = NULL;
    1529             : }
    1530           0 : if((&(data)->val[(data)->len-1])->anchor) {
    1531           0 : der_free_utf8string((&(data)->val[(data)->len-1])->anchor);
    1532           0 : free((&(data)->val[(data)->len-1])->anchor);
    1533           0 : (&(data)->val[(data)->len-1])->anchor = NULL;
    1534             : }
    1535           0 : (data)->len--;
    1536           0 : } else (data)->len = 0;
    1537           0 : free((data)->val);
    1538           0 : (data)->val = NULL;
    1539           0 : }
    1540             : 
    1541             : size_t ASN1CALL
    1542           0 : length_HDB_Ext_PKINIT_acl(const HDB_Ext_PKINIT_acl *data)
    1543             : {
    1544           0 : size_t ret = 0;
    1545             : {
    1546           0 : size_t Top_tag_oldret = ret;
    1547           0 : unsigned int n_Top_tag;
    1548           0 : ret = 0;
    1549           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    1550           0 : size_t Top_tag_for_oldret = ret;
    1551           0 : ret = 0;
    1552             : {
    1553           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    1554           0 : ret = 0;
    1555           0 : ret += der_length_utf8string(&(&(data)->val[n_Top_tag - 1])->subject);
    1556           0 : ret += 1 + der_length_len (ret);
    1557           0 : ret += 1 + der_length_len (ret);
    1558           0 : ret += Top_tag_S_Of_tag_oldret;
    1559             : }
    1560           0 : if((&(data)->val[n_Top_tag - 1])->issuer){
    1561           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    1562           0 : ret = 0;
    1563           0 : ret += der_length_utf8string((&(data)->val[n_Top_tag - 1])->issuer);
    1564           0 : ret += 1 + der_length_len (ret);
    1565           0 : ret += 1 + der_length_len (ret);
    1566           0 : ret += Top_tag_S_Of_tag_oldret;
    1567             : }
    1568           0 : if((&(data)->val[n_Top_tag - 1])->anchor){
    1569           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    1570           0 : ret = 0;
    1571           0 : ret += der_length_utf8string((&(data)->val[n_Top_tag - 1])->anchor);
    1572           0 : ret += 1 + der_length_len (ret);
    1573           0 : ret += 1 + der_length_len (ret);
    1574           0 : ret += Top_tag_S_Of_tag_oldret;
    1575             : }
    1576           0 : ret += 1 + der_length_len (ret);
    1577           0 : ret += Top_tag_for_oldret;
    1578             : }
    1579           0 : ret += Top_tag_oldret;
    1580             : }
    1581           0 : ret += 1 + der_length_len (ret);
    1582           0 : return ret;
    1583             : }
    1584             : 
    1585             : int ASN1CALL
    1586           0 : copy_HDB_Ext_PKINIT_acl(const HDB_Ext_PKINIT_acl *from, HDB_Ext_PKINIT_acl *to)
    1587             : {
    1588           0 : memset(to, 0, sizeof(*to));
    1589           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    1590           0 : goto fail;
    1591           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    1592           0 : if(der_copy_utf8string(&(&(from)->val[(to)->len])->subject, &(&(to)->val[(to)->len])->subject)) goto fail;
    1593           0 : if((&(from)->val[(to)->len])->issuer) {
    1594           0 : (&(to)->val[(to)->len])->issuer = calloc(1, sizeof(*(&(to)->val[(to)->len])->issuer));
    1595           0 : if((&(to)->val[(to)->len])->issuer == NULL) goto fail;
    1596           0 : if(der_copy_utf8string((&(from)->val[(to)->len])->issuer, (&(to)->val[(to)->len])->issuer)) goto fail;
    1597             : }else
    1598           0 : (&(to)->val[(to)->len])->issuer = NULL;
    1599           0 : if((&(from)->val[(to)->len])->anchor) {
    1600           0 : (&(to)->val[(to)->len])->anchor = calloc(1, sizeof(*(&(to)->val[(to)->len])->anchor));
    1601           0 : if((&(to)->val[(to)->len])->anchor == NULL) goto fail;
    1602           0 : if(der_copy_utf8string((&(from)->val[(to)->len])->anchor, (&(to)->val[(to)->len])->anchor)) goto fail;
    1603             : }else
    1604           0 : (&(to)->val[(to)->len])->anchor = NULL;
    1605             : }
    1606           0 : return 0;
    1607           0 : fail:
    1608           0 : free_HDB_Ext_PKINIT_acl(to);
    1609           0 : return ENOMEM;
    1610             : }
    1611             : 
    1612             : char * ASN1CALL
    1613           0 : print_HDB_Ext_PKINIT_acl(const HDB_Ext_PKINIT_acl *data, int flags)
    1614           0 : { errno = EINVAL; return 0; }
    1615             : 
    1616             : int ASN1CALL
    1617           0 : encode_HDB_Ext_PKINIT_hash(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_PKINIT_hash *data, size_t *size)
    1618             : {
    1619           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    1620           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1621           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    1622             : 
    1623           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    1624           0 : size_t Top_tag_for_oldret = ret;
    1625           0 : ret = 0;
    1626             : /* digest */
    1627             : {
    1628           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1629           0 : ret = 0;
    1630           0 : e = der_put_octet_string(p, len, &(&(data)->val[i])->digest, &l);
    1631           0 : if (e) return e;
    1632           0 : p -= l; len -= l; ret += l;
    1633             : 
    1634           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
    1635           0 : if (e) return e;
    1636           0 : p -= l; len -= l; ret += l;
    1637             : 
    1638           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    1639           0 : if (e) return e;
    1640           0 : p -= l; len -= l; ret += l;
    1641             : 
    1642           0 : ret += Top_tag_S_Of_tag_oldret;
    1643             : }
    1644             : /* digest-type */
    1645             : {
    1646           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1647           0 : ret = 0;
    1648           0 : e = der_put_oid(p, len, &(&(data)->val[i])->digest_type, &l);
    1649           0 : if (e) return e;
    1650           0 : p -= l; len -= l; ret += l;
    1651             : 
    1652           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OID, &l);
    1653           0 : if (e) return e;
    1654           0 : p -= l; len -= l; ret += l;
    1655             : 
    1656           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    1657           0 : if (e) return e;
    1658           0 : p -= l; len -= l; ret += l;
    1659             : 
    1660           0 : ret += Top_tag_S_Of_tag_oldret;
    1661             : }
    1662           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1663           0 : if (e) return e;
    1664           0 : p -= l; len -= l; ret += l;
    1665             : 
    1666           0 : ret += Top_tag_for_oldret;
    1667             : }
    1668           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1669           0 : if (e) return e;
    1670           0 : p -= l; len -= l; ret += l;
    1671             : 
    1672           0 : *size = ret;
    1673           0 : return 0;
    1674             : }
    1675             : 
    1676             : int ASN1CALL
    1677           0 : decode_HDB_Ext_PKINIT_hash(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_PKINIT_hash *data, size_t *size)
    1678             : {
    1679           0 : size_t ret = 0;
    1680           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1681           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    1682             : 
    1683           0 : memset(data, 0, sizeof(*data));
    1684             : {
    1685           0 : size_t Top_datalen;
    1686           0 : Der_type Top_type;
    1687           0 : size_t Top_oldlen;
    1688           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    1689           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    1690           0 : if (e) goto fail;
    1691           0 : p += l; len -= l; ret += l;
    1692           0 : Top_oldlen = len;
    1693           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1694           0 : len = Top_datalen;
    1695             : {
    1696           0 : size_t Top_Tag_origlen = len;
    1697           0 : size_t Top_Tag_oldret = ret;
    1698           0 : size_t Top_Tag_olen = 0;
    1699           0 : void *Top_Tag_tmp;
    1700           0 : ret = 0;
    1701           0 : (data)->len = 0;
    1702           0 : (data)->val = NULL;
    1703           0 : while(ret < Top_Tag_origlen) {
    1704           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    1705           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    1706           0 : Top_Tag_olen = Top_Tag_nlen;
    1707           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    1708           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    1709           0 : (data)->val = Top_Tag_tmp;
    1710             : {
    1711           0 : size_t Top_Tag_s_of_datalen;
    1712           0 : Der_type Top_Tag_s_of_type;
    1713           0 : size_t Top_Tag_s_of_oldlen;
    1714           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_Tag_s_of_type, UT_Sequence, &Top_Tag_s_of_datalen, &l);
    1715           0 : if (e == 0 && Top_Tag_s_of_type != CONS) { e = ASN1_BAD_ID; }
    1716           0 : if (e) goto fail;
    1717           0 : p += l; len -= l; ret += l;
    1718           0 : Top_Tag_s_of_oldlen = len;
    1719           0 : if (Top_Tag_s_of_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1720           0 : len = Top_Tag_s_of_datalen;
    1721             : {
    1722           0 : size_t digest_type_datalen;
    1723           0 : Der_type digest_type_type;
    1724           0 : size_t digest_type_oldlen;
    1725           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &digest_type_type, 0, &digest_type_datalen, &l);
    1726           0 : if (e == 0 && digest_type_type != CONS) { e = ASN1_BAD_ID; }
    1727           0 : if (e) goto fail;
    1728           0 : p += l; len -= l; ret += l;
    1729           0 : digest_type_oldlen = len;
    1730           0 : if (digest_type_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1731           0 : len = digest_type_datalen;
    1732             : {
    1733           0 : size_t digest_type_Tag_datalen;
    1734           0 : Der_type digest_type_Tag_type;
    1735           0 : size_t digest_type_Tag_oldlen;
    1736           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &digest_type_Tag_type, UT_OID, &digest_type_Tag_datalen, &l);
    1737           0 : if (e == 0 && digest_type_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1738           0 : if (e) goto fail;
    1739           0 : p += l; len -= l; ret += l;
    1740           0 : digest_type_Tag_oldlen = len;
    1741           0 : if (digest_type_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1742           0 : len = digest_type_Tag_datalen;
    1743           0 : e = der_get_oid(p, len, &(&(data)->val[(data)->len])->digest_type, &l);
    1744           0 : if(e) goto fail;
    1745           0 : p += l; len -= l; ret += l;
    1746           0 : len = digest_type_Tag_oldlen - digest_type_Tag_datalen;
    1747             : }
    1748           0 : len = digest_type_oldlen - digest_type_datalen;
    1749             : }
    1750             : {
    1751           0 : size_t digest_datalen;
    1752           0 : Der_type digest_type;
    1753           0 : size_t digest_oldlen;
    1754           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &digest_type, 1, &digest_datalen, &l);
    1755           0 : if (e == 0 && digest_type != CONS) { e = ASN1_BAD_ID; }
    1756           0 : if (e) goto fail;
    1757           0 : p += l; len -= l; ret += l;
    1758           0 : digest_oldlen = len;
    1759           0 : if (digest_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1760           0 : len = digest_datalen;
    1761             : {
    1762           0 : size_t digest_Tag_datalen;
    1763           0 : Der_type digest_Tag_type;
    1764           0 : size_t digest_Tag_oldlen;
    1765           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &digest_Tag_type, UT_OctetString, &digest_Tag_datalen, &l);
    1766           0 : if (e == 0 && digest_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1767           0 : if (e) goto fail;
    1768           0 : p += l; len -= l; ret += l;
    1769           0 : digest_Tag_oldlen = len;
    1770           0 : if (digest_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1771           0 : len = digest_Tag_datalen;
    1772           0 : e = der_get_octet_string(p, len, &(&(data)->val[(data)->len])->digest, &l);
    1773           0 : if(e) goto fail;
    1774           0 : p += l; len -= l; ret += l;
    1775           0 : len = digest_Tag_oldlen - digest_Tag_datalen;
    1776             : }
    1777           0 : len = digest_oldlen - digest_datalen;
    1778             : }
    1779           0 : len = Top_Tag_s_of_oldlen - Top_Tag_s_of_datalen;
    1780             : }
    1781           0 : (data)->len++;
    1782           0 : len = Top_Tag_origlen - ret;
    1783             : }
    1784           0 : ret += Top_Tag_oldret;
    1785             : }
    1786           0 : len = Top_oldlen - Top_datalen;
    1787             : }
    1788           0 : if(size) *size = ret;
    1789           0 : return 0;
    1790           0 : fail:
    1791           0 : free_HDB_Ext_PKINIT_hash(data);
    1792           0 : return e;
    1793             : }
    1794             : 
    1795             : void ASN1CALL
    1796           0 : free_HDB_Ext_PKINIT_hash(HDB_Ext_PKINIT_hash *data)
    1797             : {
    1798           0 : if ((data)->val)
    1799           0 : while((data)->len){
    1800           0 : der_free_oid(&(&(data)->val[(data)->len-1])->digest_type);
    1801           0 : der_free_octet_string(&(&(data)->val[(data)->len-1])->digest);
    1802           0 : (data)->len--;
    1803           0 : } else (data)->len = 0;
    1804           0 : free((data)->val);
    1805           0 : (data)->val = NULL;
    1806           0 : }
    1807             : 
    1808             : size_t ASN1CALL
    1809           0 : length_HDB_Ext_PKINIT_hash(const HDB_Ext_PKINIT_hash *data)
    1810             : {
    1811           0 : size_t ret = 0;
    1812             : {
    1813           0 : size_t Top_tag_oldret = ret;
    1814           0 : unsigned int n_Top_tag;
    1815           0 : ret = 0;
    1816           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    1817           0 : size_t Top_tag_for_oldret = ret;
    1818           0 : ret = 0;
    1819             : {
    1820           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    1821           0 : ret = 0;
    1822           0 : ret += der_length_oid(&(&(data)->val[n_Top_tag - 1])->digest_type);
    1823           0 : ret += 1 + der_length_len (ret);
    1824           0 : ret += 1 + der_length_len (ret);
    1825           0 : ret += Top_tag_S_Of_tag_oldret;
    1826             : }
    1827             : {
    1828           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    1829           0 : ret = 0;
    1830           0 : ret += der_length_octet_string(&(&(data)->val[n_Top_tag - 1])->digest);
    1831           0 : ret += 1 + der_length_len (ret);
    1832           0 : ret += 1 + der_length_len (ret);
    1833           0 : ret += Top_tag_S_Of_tag_oldret;
    1834             : }
    1835           0 : ret += 1 + der_length_len (ret);
    1836           0 : ret += Top_tag_for_oldret;
    1837             : }
    1838           0 : ret += Top_tag_oldret;
    1839             : }
    1840           0 : ret += 1 + der_length_len (ret);
    1841           0 : return ret;
    1842             : }
    1843             : 
    1844             : int ASN1CALL
    1845           0 : copy_HDB_Ext_PKINIT_hash(const HDB_Ext_PKINIT_hash *from, HDB_Ext_PKINIT_hash *to)
    1846             : {
    1847           0 : memset(to, 0, sizeof(*to));
    1848           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    1849           0 : goto fail;
    1850           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    1851           0 : if(der_copy_oid(&(&(from)->val[(to)->len])->digest_type, &(&(to)->val[(to)->len])->digest_type)) goto fail;
    1852           0 : if(der_copy_octet_string(&(&(from)->val[(to)->len])->digest, &(&(to)->val[(to)->len])->digest)) goto fail;
    1853             : }
    1854           0 : return 0;
    1855           0 : fail:
    1856           0 : free_HDB_Ext_PKINIT_hash(to);
    1857           0 : return ENOMEM;
    1858             : }
    1859             : 
    1860             : char * ASN1CALL
    1861           0 : print_HDB_Ext_PKINIT_hash(const HDB_Ext_PKINIT_hash *data, int flags)
    1862           0 : { errno = EINVAL; return 0; }
    1863             : 
    1864             : int ASN1CALL
    1865           0 : encode_HDB_Ext_PKINIT_cert(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_PKINIT_cert *data, size_t *size)
    1866             : {
    1867           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    1868           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1869           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    1870             : 
    1871           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    1872           0 : size_t Top_tag_for_oldret = ret;
    1873           0 : ret = 0;
    1874             : /* cert */
    1875             : {
    1876           0 : size_t Top_tag_S_Of_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    1877           0 : ret = 0;
    1878           0 : e = der_put_octet_string(p, len, &(&(data)->val[i])->cert, &l);
    1879           0 : if (e) return e;
    1880           0 : p -= l; len -= l; ret += l;
    1881             : 
    1882           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
    1883           0 : if (e) return e;
    1884           0 : p -= l; len -= l; ret += l;
    1885             : 
    1886           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    1887           0 : if (e) return e;
    1888           0 : p -= l; len -= l; ret += l;
    1889             : 
    1890           0 : ret += Top_tag_S_Of_tag_oldret;
    1891             : }
    1892           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1893           0 : if (e) return e;
    1894           0 : p -= l; len -= l; ret += l;
    1895             : 
    1896           0 : ret += Top_tag_for_oldret;
    1897             : }
    1898           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1899           0 : if (e) return e;
    1900           0 : p -= l; len -= l; ret += l;
    1901             : 
    1902           0 : *size = ret;
    1903           0 : return 0;
    1904             : }
    1905             : 
    1906             : int ASN1CALL
    1907           0 : decode_HDB_Ext_PKINIT_cert(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_PKINIT_cert *data, size_t *size)
    1908             : {
    1909           0 : size_t ret = 0;
    1910           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    1911           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    1912             : 
    1913           0 : memset(data, 0, sizeof(*data));
    1914             : {
    1915           0 : size_t Top_datalen;
    1916           0 : Der_type Top_type;
    1917           0 : size_t Top_oldlen;
    1918           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    1919           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    1920           0 : if (e) goto fail;
    1921           0 : p += l; len -= l; ret += l;
    1922           0 : Top_oldlen = len;
    1923           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1924           0 : len = Top_datalen;
    1925             : {
    1926           0 : size_t Top_Tag_origlen = len;
    1927           0 : size_t Top_Tag_oldret = ret;
    1928           0 : size_t Top_Tag_olen = 0;
    1929           0 : void *Top_Tag_tmp;
    1930           0 : ret = 0;
    1931           0 : (data)->len = 0;
    1932           0 : (data)->val = NULL;
    1933           0 : while(ret < Top_Tag_origlen) {
    1934           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    1935           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    1936           0 : Top_Tag_olen = Top_Tag_nlen;
    1937           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    1938           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    1939           0 : (data)->val = Top_Tag_tmp;
    1940             : {
    1941           0 : size_t Top_Tag_s_of_datalen;
    1942           0 : Der_type Top_Tag_s_of_type;
    1943           0 : size_t Top_Tag_s_of_oldlen;
    1944           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_Tag_s_of_type, UT_Sequence, &Top_Tag_s_of_datalen, &l);
    1945           0 : if (e == 0 && Top_Tag_s_of_type != CONS) { e = ASN1_BAD_ID; }
    1946           0 : if (e) goto fail;
    1947           0 : p += l; len -= l; ret += l;
    1948           0 : Top_Tag_s_of_oldlen = len;
    1949           0 : if (Top_Tag_s_of_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1950           0 : len = Top_Tag_s_of_datalen;
    1951             : {
    1952           0 : size_t cert_datalen;
    1953           0 : Der_type cert_type;
    1954           0 : size_t cert_oldlen;
    1955           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &cert_type, 0, &cert_datalen, &l);
    1956           0 : if (e == 0 && cert_type != CONS) { e = ASN1_BAD_ID; }
    1957           0 : if (e) goto fail;
    1958           0 : p += l; len -= l; ret += l;
    1959           0 : cert_oldlen = len;
    1960           0 : if (cert_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1961           0 : len = cert_datalen;
    1962             : {
    1963           0 : size_t cert_Tag_datalen;
    1964           0 : Der_type cert_Tag_type;
    1965           0 : size_t cert_Tag_oldlen;
    1966           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &cert_Tag_type, UT_OctetString, &cert_Tag_datalen, &l);
    1967           0 : if (e == 0 && cert_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    1968           0 : if (e) goto fail;
    1969           0 : p += l; len -= l; ret += l;
    1970           0 : cert_Tag_oldlen = len;
    1971           0 : if (cert_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    1972           0 : len = cert_Tag_datalen;
    1973           0 : e = der_get_octet_string(p, len, &(&(data)->val[(data)->len])->cert, &l);
    1974           0 : if(e) goto fail;
    1975           0 : p += l; len -= l; ret += l;
    1976           0 : len = cert_Tag_oldlen - cert_Tag_datalen;
    1977             : }
    1978           0 : len = cert_oldlen - cert_datalen;
    1979             : }
    1980           0 : len = Top_Tag_s_of_oldlen - Top_Tag_s_of_datalen;
    1981             : }
    1982           0 : (data)->len++;
    1983           0 : len = Top_Tag_origlen - ret;
    1984             : }
    1985           0 : ret += Top_Tag_oldret;
    1986             : }
    1987           0 : len = Top_oldlen - Top_datalen;
    1988             : }
    1989           0 : if(size) *size = ret;
    1990           0 : return 0;
    1991           0 : fail:
    1992           0 : free_HDB_Ext_PKINIT_cert(data);
    1993           0 : return e;
    1994             : }
    1995             : 
    1996             : void ASN1CALL
    1997           0 : free_HDB_Ext_PKINIT_cert(HDB_Ext_PKINIT_cert *data)
    1998             : {
    1999           0 : if ((data)->val)
    2000           0 : while((data)->len){
    2001           0 : der_free_octet_string(&(&(data)->val[(data)->len-1])->cert);
    2002           0 : (data)->len--;
    2003           0 : } else (data)->len = 0;
    2004           0 : free((data)->val);
    2005           0 : (data)->val = NULL;
    2006           0 : }
    2007             : 
    2008             : size_t ASN1CALL
    2009           0 : length_HDB_Ext_PKINIT_cert(const HDB_Ext_PKINIT_cert *data)
    2010             : {
    2011           0 : size_t ret = 0;
    2012             : {
    2013           0 : size_t Top_tag_oldret = ret;
    2014           0 : unsigned int n_Top_tag;
    2015           0 : ret = 0;
    2016           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    2017           0 : size_t Top_tag_for_oldret = ret;
    2018           0 : ret = 0;
    2019             : {
    2020           0 : size_t Top_tag_S_Of_tag_oldret = ret;
    2021           0 : ret = 0;
    2022           0 : ret += der_length_octet_string(&(&(data)->val[n_Top_tag - 1])->cert);
    2023           0 : ret += 1 + der_length_len (ret);
    2024           0 : ret += 1 + der_length_len (ret);
    2025           0 : ret += Top_tag_S_Of_tag_oldret;
    2026             : }
    2027           0 : ret += 1 + der_length_len (ret);
    2028           0 : ret += Top_tag_for_oldret;
    2029             : }
    2030           0 : ret += Top_tag_oldret;
    2031             : }
    2032           0 : ret += 1 + der_length_len (ret);
    2033           0 : return ret;
    2034             : }
    2035             : 
    2036             : int ASN1CALL
    2037           0 : copy_HDB_Ext_PKINIT_cert(const HDB_Ext_PKINIT_cert *from, HDB_Ext_PKINIT_cert *to)
    2038             : {
    2039           0 : memset(to, 0, sizeof(*to));
    2040           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    2041           0 : goto fail;
    2042           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    2043           0 : if(der_copy_octet_string(&(&(from)->val[(to)->len])->cert, &(&(to)->val[(to)->len])->cert)) goto fail;
    2044             : }
    2045           0 : return 0;
    2046           0 : fail:
    2047           0 : free_HDB_Ext_PKINIT_cert(to);
    2048           0 : return ENOMEM;
    2049             : }
    2050             : 
    2051             : char * ASN1CALL
    2052           0 : print_HDB_Ext_PKINIT_cert(const HDB_Ext_PKINIT_cert *data, int flags)
    2053           0 : { errno = EINVAL; return 0; }
    2054             : 
    2055             : int ASN1CALL
    2056           0 : encode_HDB_Ext_Constrained_delegation_acl(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_Constrained_delegation_acl *data, size_t *size)
    2057             : {
    2058           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2059           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2060           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2061             : 
    2062           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    2063           0 : size_t Top_tag_for_oldret = ret;
    2064           0 : ret = 0;
    2065           0 : e = encode_Principal(p, len, &(data)->val[i], &l);
    2066           0 : if (e) return e;
    2067           0 : p -= l; len -= l; ret += l;
    2068             : 
    2069           0 : ret += Top_tag_for_oldret;
    2070             : }
    2071           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2072           0 : if (e) return e;
    2073           0 : p -= l; len -= l; ret += l;
    2074             : 
    2075           0 : *size = ret;
    2076           0 : return 0;
    2077             : }
    2078             : 
    2079             : int ASN1CALL
    2080           0 : decode_HDB_Ext_Constrained_delegation_acl(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_Constrained_delegation_acl *data, size_t *size)
    2081             : {
    2082           0 : size_t ret = 0;
    2083           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2084           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2085             : 
    2086           0 : memset(data, 0, sizeof(*data));
    2087             : {
    2088           0 : size_t Top_datalen;
    2089           0 : Der_type Top_type;
    2090           0 : size_t Top_oldlen;
    2091           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    2092           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    2093           0 : if (e) goto fail;
    2094           0 : p += l; len -= l; ret += l;
    2095           0 : Top_oldlen = len;
    2096           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2097           0 : len = Top_datalen;
    2098             : {
    2099           0 : size_t Top_Tag_origlen = len;
    2100           0 : size_t Top_Tag_oldret = ret;
    2101           0 : size_t Top_Tag_olen = 0;
    2102           0 : void *Top_Tag_tmp;
    2103           0 : ret = 0;
    2104           0 : (data)->len = 0;
    2105           0 : (data)->val = NULL;
    2106           0 : while(ret < Top_Tag_origlen) {
    2107           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    2108           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    2109           0 : Top_Tag_olen = Top_Tag_nlen;
    2110           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    2111           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    2112           0 : (data)->val = Top_Tag_tmp;
    2113           0 : e = decode_Principal(p, len, &(data)->val[(data)->len], &l);
    2114           0 : if(e) goto fail;
    2115           0 : p += l; len -= l; ret += l;
    2116           0 : (data)->len++;
    2117           0 : len = Top_Tag_origlen - ret;
    2118             : }
    2119           0 : ret += Top_Tag_oldret;
    2120             : }
    2121           0 : len = Top_oldlen - Top_datalen;
    2122             : }
    2123           0 : if(size) *size = ret;
    2124           0 : return 0;
    2125           0 : fail:
    2126           0 : free_HDB_Ext_Constrained_delegation_acl(data);
    2127           0 : return e;
    2128             : }
    2129             : 
    2130             : void ASN1CALL
    2131           0 : free_HDB_Ext_Constrained_delegation_acl(HDB_Ext_Constrained_delegation_acl *data)
    2132             : {
    2133           0 : if ((data)->val)
    2134           0 : while((data)->len){
    2135           0 : free_Principal(&(data)->val[(data)->len-1]);
    2136           0 : (data)->len--;
    2137           0 : } else (data)->len = 0;
    2138           0 : free((data)->val);
    2139           0 : (data)->val = NULL;
    2140           0 : }
    2141             : 
    2142             : size_t ASN1CALL
    2143           0 : length_HDB_Ext_Constrained_delegation_acl(const HDB_Ext_Constrained_delegation_acl *data)
    2144             : {
    2145           0 : size_t ret = 0;
    2146             : {
    2147           0 : size_t Top_tag_oldret = ret;
    2148           0 : unsigned int n_Top_tag;
    2149           0 : ret = 0;
    2150           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    2151           0 : size_t Top_tag_for_oldret = ret;
    2152           0 : ret = 0;
    2153           0 : ret += length_Principal(&(data)->val[n_Top_tag - 1]);
    2154           0 : ret += Top_tag_for_oldret;
    2155             : }
    2156           0 : ret += Top_tag_oldret;
    2157             : }
    2158           0 : ret += 1 + der_length_len (ret);
    2159           0 : return ret;
    2160             : }
    2161             : 
    2162             : int ASN1CALL
    2163           0 : copy_HDB_Ext_Constrained_delegation_acl(const HDB_Ext_Constrained_delegation_acl *from, HDB_Ext_Constrained_delegation_acl *to)
    2164             : {
    2165           0 : memset(to, 0, sizeof(*to));
    2166           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    2167           0 : goto fail;
    2168           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    2169           0 : if(copy_Principal(&(from)->val[(to)->len], &(to)->val[(to)->len])) goto fail;
    2170             : }
    2171           0 : return 0;
    2172           0 : fail:
    2173           0 : free_HDB_Ext_Constrained_delegation_acl(to);
    2174           0 : return ENOMEM;
    2175             : }
    2176             : 
    2177             : char * ASN1CALL
    2178           0 : print_HDB_Ext_Constrained_delegation_acl(const HDB_Ext_Constrained_delegation_acl *data, int flags)
    2179           0 : { errno = EINVAL; return 0; }
    2180             : 
    2181             : int ASN1CALL
    2182           0 : encode_HDB_Ext_Lan_Manager_OWF(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_Lan_Manager_OWF *data, size_t *size)
    2183             : {
    2184           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2185           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2186           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2187             : 
    2188           0 : e = der_put_octet_string(p, len, data, &l);
    2189           0 : if (e) return e;
    2190           0 : p -= l; len -= l; ret += l;
    2191             : 
    2192           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
    2193           0 : if (e) return e;
    2194           0 : p -= l; len -= l; ret += l;
    2195             : 
    2196           0 : *size = ret;
    2197           0 : return 0;
    2198             : }
    2199             : 
    2200             : int ASN1CALL
    2201           0 : decode_HDB_Ext_Lan_Manager_OWF(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_Lan_Manager_OWF *data, size_t *size)
    2202             : {
    2203           0 : size_t ret = 0;
    2204           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2205           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2206             : 
    2207           0 : memset(data, 0, sizeof(*data));
    2208             : {
    2209           0 : size_t Top_datalen;
    2210           0 : Der_type Top_type;
    2211           0 : size_t Top_oldlen;
    2212           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_OctetString, &Top_datalen, &l);
    2213           0 : if (e == 0 && Top_type != PRIM) { e = ASN1_BAD_ID; }
    2214           0 : if (e) goto fail;
    2215           0 : p += l; len -= l; ret += l;
    2216           0 : Top_oldlen = len;
    2217           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2218           0 : len = Top_datalen;
    2219           0 : e = der_get_octet_string(p, len, data, &l);
    2220           0 : if(e) goto fail;
    2221           0 : p += l; len -= l; ret += l;
    2222           0 : len = Top_oldlen - Top_datalen;
    2223             : }
    2224           0 : if(size) *size = ret;
    2225           0 : return 0;
    2226           0 : fail:
    2227           0 : free_HDB_Ext_Lan_Manager_OWF(data);
    2228           0 : return e;
    2229             : }
    2230             : 
    2231             : void ASN1CALL
    2232           0 : free_HDB_Ext_Lan_Manager_OWF(HDB_Ext_Lan_Manager_OWF *data)
    2233             : {
    2234           0 : der_free_octet_string(data);
    2235           0 : }
    2236             : 
    2237             : size_t ASN1CALL
    2238           0 : length_HDB_Ext_Lan_Manager_OWF(const HDB_Ext_Lan_Manager_OWF *data)
    2239             : {
    2240           0 : size_t ret = 0;
    2241           0 : ret += der_length_octet_string(data);
    2242           0 : ret += 1 + der_length_len (ret);
    2243           0 : return ret;
    2244             : }
    2245             : 
    2246             : int ASN1CALL
    2247           0 : copy_HDB_Ext_Lan_Manager_OWF(const HDB_Ext_Lan_Manager_OWF *from, HDB_Ext_Lan_Manager_OWF *to)
    2248             : {
    2249           0 : memset(to, 0, sizeof(*to));
    2250           0 : if(der_copy_octet_string(from, to)) goto fail;
    2251           0 : return 0;
    2252           0 : fail:
    2253           0 : free_HDB_Ext_Lan_Manager_OWF(to);
    2254           0 : return ENOMEM;
    2255             : }
    2256             : 
    2257             : char * ASN1CALL
    2258           0 : print_HDB_Ext_Lan_Manager_OWF(const HDB_Ext_Lan_Manager_OWF *data, int flags)
    2259           0 : { errno = EINVAL; return 0; }
    2260             : 
    2261             : int ASN1CALL
    2262           0 : encode_HDB_Ext_Password(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_Password *data, size_t *size)
    2263             : {
    2264           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2265           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2266           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2267             : 
    2268             : /* password */
    2269             : {
    2270           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2271           0 : ret = 0;
    2272           0 : e = der_put_octet_string(p, len, &(data)->password, &l);
    2273           0 : if (e) return e;
    2274           0 : p -= l; len -= l; ret += l;
    2275             : 
    2276           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
    2277           0 : if (e) return e;
    2278           0 : p -= l; len -= l; ret += l;
    2279             : 
    2280           0 : ret += Top_tag_oldret;
    2281             : }
    2282             : /* mkvno */
    2283           0 : if((data)->mkvno) {
    2284           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2285           0 : ret = 0;
    2286           0 : e = der_put_unsigned(p, len, (data)->mkvno, &l);
    2287           0 : if (e) return e;
    2288           0 : p -= l; len -= l; ret += l;
    2289             : 
    2290           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    2291           0 : if (e) return e;
    2292           0 : p -= l; len -= l; ret += l;
    2293             : 
    2294           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    2295           0 : if (e) return e;
    2296           0 : p -= l; len -= l; ret += l;
    2297             : 
    2298           0 : ret += Top_tag_oldret;
    2299             : }
    2300           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2301           0 : if (e) return e;
    2302           0 : p -= l; len -= l; ret += l;
    2303             : 
    2304           0 : *size = ret;
    2305           0 : return 0;
    2306             : }
    2307             : 
    2308             : int ASN1CALL
    2309           0 : decode_HDB_Ext_Password(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_Password *data, size_t *size)
    2310             : {
    2311           0 : size_t ret = 0;
    2312           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2313           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2314             : 
    2315           0 : memset(data, 0, sizeof(*data));
    2316             : {
    2317           0 : size_t Top_datalen;
    2318           0 : Der_type Top_type;
    2319           0 : size_t Top_oldlen;
    2320           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    2321           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    2322           0 : if (e) goto fail;
    2323           0 : p += l; len -= l; ret += l;
    2324           0 : Top_oldlen = len;
    2325           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2326           0 : len = Top_datalen;
    2327             : {
    2328           0 : size_t mkvno_datalen;
    2329           0 : Der_type mkvno_type;
    2330           0 : size_t mkvno_oldlen;
    2331           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &mkvno_type, 0, &mkvno_datalen, &l);
    2332           0 : if (e == 0 && mkvno_type != CONS) { e = ASN1_BAD_ID; }
    2333           0 : if(e) {
    2334           0 : (data)->mkvno = NULL;
    2335             : } else {
    2336           0 : (data)->mkvno = calloc(1, sizeof(*(data)->mkvno));
    2337           0 : if ((data)->mkvno == NULL) { e = ENOMEM; goto fail; }
    2338           0 : p += l; len -= l; ret += l;
    2339           0 : mkvno_oldlen = len;
    2340           0 : if (mkvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2341           0 : len = mkvno_datalen;
    2342             : {
    2343           0 : size_t mkvno_Tag_datalen;
    2344           0 : Der_type mkvno_Tag_type;
    2345           0 : size_t mkvno_Tag_oldlen;
    2346           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &mkvno_Tag_type, UT_Integer, &mkvno_Tag_datalen, &l);
    2347           0 : if (e == 0 && mkvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    2348           0 : if (e) goto fail;
    2349           0 : p += l; len -= l; ret += l;
    2350           0 : mkvno_Tag_oldlen = len;
    2351           0 : if (mkvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2352           0 : len = mkvno_Tag_datalen;
    2353           0 : e = der_get_unsigned(p, len, (data)->mkvno, &l);
    2354           0 : if(e) goto fail;
    2355           0 : p += l; len -= l; ret += l;
    2356           0 : len = mkvno_Tag_oldlen - mkvno_Tag_datalen;
    2357             : }
    2358           0 : len = mkvno_oldlen - mkvno_datalen;
    2359             : }
    2360             : }
    2361             : {
    2362           0 : size_t password_datalen;
    2363           0 : Der_type password_type;
    2364           0 : size_t password_oldlen;
    2365           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &password_type, UT_OctetString, &password_datalen, &l);
    2366           0 : if (e == 0 && password_type != PRIM) { e = ASN1_BAD_ID; }
    2367           0 : if (e) goto fail;
    2368           0 : p += l; len -= l; ret += l;
    2369           0 : password_oldlen = len;
    2370           0 : if (password_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2371           0 : len = password_datalen;
    2372           0 : e = der_get_octet_string(p, len, &(data)->password, &l);
    2373           0 : if(e) goto fail;
    2374           0 : p += l; len -= l; ret += l;
    2375           0 : len = password_oldlen - password_datalen;
    2376             : }
    2377           0 : len = Top_oldlen - Top_datalen;
    2378             : }
    2379           0 : if(size) *size = ret;
    2380           0 : return 0;
    2381           0 : fail:
    2382           0 : free_HDB_Ext_Password(data);
    2383           0 : return e;
    2384             : }
    2385             : 
    2386             : void ASN1CALL
    2387           0 : free_HDB_Ext_Password(HDB_Ext_Password *data)
    2388             : {
    2389           0 : if((data)->mkvno) {
    2390           0 : *(data)->mkvno = 0;
    2391           0 : free((data)->mkvno);
    2392           0 : (data)->mkvno = NULL;
    2393             : }
    2394           0 : der_free_octet_string(&(data)->password);
    2395           0 : }
    2396             : 
    2397             : size_t ASN1CALL
    2398           0 : length_HDB_Ext_Password(const HDB_Ext_Password *data)
    2399             : {
    2400           0 : size_t ret = 0;
    2401           0 : if((data)->mkvno){
    2402           0 : size_t Top_tag_oldret = ret;
    2403           0 : ret = 0;
    2404           0 : ret += der_length_unsigned((data)->mkvno);
    2405           0 : ret += 1 + der_length_len (ret);
    2406           0 : ret += 1 + der_length_len (ret);
    2407           0 : ret += Top_tag_oldret;
    2408             : }
    2409             : {
    2410           0 : size_t Top_tag_oldret = ret;
    2411           0 : ret = 0;
    2412           0 : ret += der_length_octet_string(&(data)->password);
    2413           0 : ret += 1 + der_length_len (ret);
    2414           0 : ret += Top_tag_oldret;
    2415             : }
    2416           0 : ret += 1 + der_length_len (ret);
    2417           0 : return ret;
    2418             : }
    2419             : 
    2420             : int ASN1CALL
    2421           0 : copy_HDB_Ext_Password(const HDB_Ext_Password *from, HDB_Ext_Password *to)
    2422             : {
    2423           0 : memset(to, 0, sizeof(*to));
    2424           0 : if((from)->mkvno) {
    2425           0 : (to)->mkvno = calloc(1, sizeof(*(to)->mkvno));
    2426           0 : if((to)->mkvno == NULL) goto fail;
    2427           0 : *((to)->mkvno) = *((from)->mkvno);
    2428             : }else
    2429           0 : (to)->mkvno = NULL;
    2430           0 : if(der_copy_octet_string(&(from)->password, &(to)->password)) goto fail;
    2431           0 : return 0;
    2432           0 : fail:
    2433           0 : free_HDB_Ext_Password(to);
    2434           0 : return ENOMEM;
    2435             : }
    2436             : 
    2437             : char * ASN1CALL
    2438           0 : print_HDB_Ext_Password(const HDB_Ext_Password *data, int flags)
    2439           0 : { errno = EINVAL; return 0; }
    2440             : 
    2441             : int ASN1CALL
    2442           0 : encode_HDB_Ext_Aliases(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_Aliases *data, size_t *size)
    2443             : {
    2444           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2445           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2446           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2447             : 
    2448             : /* aliases */
    2449             : {
    2450           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2451           0 : ret = 0;
    2452           0 : for(i = (int)(&(data)->aliases)->len - 1; i >= 0; --i) {
    2453           0 : size_t aliases_tag_tag_for_oldret = ret;
    2454           0 : ret = 0;
    2455           0 : e = encode_Principal(p, len, &(&(data)->aliases)->val[i], &l);
    2456           0 : if (e) return e;
    2457           0 : p -= l; len -= l; ret += l;
    2458             : 
    2459           0 : ret += aliases_tag_tag_for_oldret;
    2460             : }
    2461           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2462           0 : if (e) return e;
    2463           0 : p -= l; len -= l; ret += l;
    2464             : 
    2465           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    2466           0 : if (e) return e;
    2467           0 : p -= l; len -= l; ret += l;
    2468             : 
    2469           0 : ret += Top_tag_oldret;
    2470             : }
    2471             : /* case-insensitive */
    2472             : {
    2473           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2474           0 : ret = 0;
    2475           0 : e = der_put_boolean(p, len, &(data)->case_insensitive, &l);
    2476           0 : if (e) return e;
    2477           0 : p -= l; len -= l; ret += l;
    2478             : 
    2479           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Boolean, &l);
    2480           0 : if (e) return e;
    2481           0 : p -= l; len -= l; ret += l;
    2482             : 
    2483           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    2484           0 : if (e) return e;
    2485           0 : p -= l; len -= l; ret += l;
    2486             : 
    2487           0 : ret += Top_tag_oldret;
    2488             : }
    2489           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2490           0 : if (e) return e;
    2491           0 : p -= l; len -= l; ret += l;
    2492             : 
    2493           0 : *size = ret;
    2494           0 : return 0;
    2495             : }
    2496             : 
    2497             : int ASN1CALL
    2498           0 : decode_HDB_Ext_Aliases(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_Aliases *data, size_t *size)
    2499             : {
    2500           0 : size_t ret = 0;
    2501           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2502           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2503             : 
    2504           0 : memset(data, 0, sizeof(*data));
    2505             : {
    2506           0 : size_t Top_datalen;
    2507           0 : Der_type Top_type;
    2508           0 : size_t Top_oldlen;
    2509           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    2510           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    2511           0 : if (e) goto fail;
    2512           0 : p += l; len -= l; ret += l;
    2513           0 : Top_oldlen = len;
    2514           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2515           0 : len = Top_datalen;
    2516             : {
    2517           0 : size_t case_insensitive_datalen;
    2518           0 : Der_type case_insensitive_type;
    2519           0 : size_t case_insensitive_oldlen;
    2520           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &case_insensitive_type, 0, &case_insensitive_datalen, &l);
    2521           0 : if (e == 0 && case_insensitive_type != CONS) { e = ASN1_BAD_ID; }
    2522           0 : if (e) goto fail;
    2523           0 : p += l; len -= l; ret += l;
    2524           0 : case_insensitive_oldlen = len;
    2525           0 : if (case_insensitive_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2526           0 : len = case_insensitive_datalen;
    2527             : {
    2528           0 : size_t case_insensitive_Tag_datalen;
    2529           0 : Der_type case_insensitive_Tag_type;
    2530           0 : size_t case_insensitive_Tag_oldlen;
    2531           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &case_insensitive_Tag_type, UT_Boolean, &case_insensitive_Tag_datalen, &l);
    2532           0 : if (e == 0 && case_insensitive_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    2533           0 : if (e) goto fail;
    2534           0 : p += l; len -= l; ret += l;
    2535           0 : case_insensitive_Tag_oldlen = len;
    2536           0 : if (case_insensitive_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2537           0 : len = case_insensitive_Tag_datalen;
    2538           0 : e = der_get_boolean(p, len, &(data)->case_insensitive, &l);
    2539           0 : if(e) goto fail;
    2540           0 : p += l; len -= l; ret += l;
    2541           0 : len = case_insensitive_Tag_oldlen - case_insensitive_Tag_datalen;
    2542             : }
    2543           0 : len = case_insensitive_oldlen - case_insensitive_datalen;
    2544             : }
    2545             : {
    2546           0 : size_t aliases_datalen;
    2547           0 : Der_type aliases_type;
    2548           0 : size_t aliases_oldlen;
    2549           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &aliases_type, 1, &aliases_datalen, &l);
    2550           0 : if (e == 0 && aliases_type != CONS) { e = ASN1_BAD_ID; }
    2551           0 : if (e) goto fail;
    2552           0 : p += l; len -= l; ret += l;
    2553           0 : aliases_oldlen = len;
    2554           0 : if (aliases_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2555           0 : len = aliases_datalen;
    2556             : {
    2557           0 : size_t aliases_Tag_datalen;
    2558           0 : Der_type aliases_Tag_type;
    2559           0 : size_t aliases_Tag_oldlen;
    2560           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &aliases_Tag_type, UT_Sequence, &aliases_Tag_datalen, &l);
    2561           0 : if (e == 0 && aliases_Tag_type != CONS) { e = ASN1_BAD_ID; }
    2562           0 : if (e) goto fail;
    2563           0 : p += l; len -= l; ret += l;
    2564           0 : aliases_Tag_oldlen = len;
    2565           0 : if (aliases_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2566           0 : len = aliases_Tag_datalen;
    2567             : {
    2568           0 : size_t aliases_Tag_Tag_origlen = len;
    2569           0 : size_t aliases_Tag_Tag_oldret = ret;
    2570           0 : size_t aliases_Tag_Tag_olen = 0;
    2571           0 : void *aliases_Tag_Tag_tmp;
    2572           0 : ret = 0;
    2573           0 : (&(data)->aliases)->len = 0;
    2574           0 : (&(data)->aliases)->val = NULL;
    2575           0 : while(ret < aliases_Tag_Tag_origlen) {
    2576           0 : size_t aliases_Tag_Tag_nlen = aliases_Tag_Tag_olen + sizeof(*((&(data)->aliases)->val));
    2577           0 : if (aliases_Tag_Tag_olen > aliases_Tag_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    2578           0 : aliases_Tag_Tag_olen = aliases_Tag_Tag_nlen;
    2579           0 : aliases_Tag_Tag_tmp = realloc((&(data)->aliases)->val, aliases_Tag_Tag_olen);
    2580           0 : if (aliases_Tag_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    2581           0 : (&(data)->aliases)->val = aliases_Tag_Tag_tmp;
    2582           0 : e = decode_Principal(p, len, &(&(data)->aliases)->val[(&(data)->aliases)->len], &l);
    2583           0 : if(e) goto fail;
    2584           0 : p += l; len -= l; ret += l;
    2585           0 : (&(data)->aliases)->len++;
    2586           0 : len = aliases_Tag_Tag_origlen - ret;
    2587             : }
    2588           0 : ret += aliases_Tag_Tag_oldret;
    2589             : }
    2590           0 : len = aliases_Tag_oldlen - aliases_Tag_datalen;
    2591             : }
    2592           0 : len = aliases_oldlen - aliases_datalen;
    2593             : }
    2594           0 : len = Top_oldlen - Top_datalen;
    2595             : }
    2596           0 : if(size) *size = ret;
    2597           0 : return 0;
    2598           0 : fail:
    2599           0 : free_HDB_Ext_Aliases(data);
    2600           0 : return e;
    2601             : }
    2602             : 
    2603             : void ASN1CALL
    2604           0 : free_HDB_Ext_Aliases(HDB_Ext_Aliases *data)
    2605             : {
    2606           0 : *&(data)->case_insensitive = 0;
    2607           0 : if ((&(data)->aliases)->val)
    2608           0 : while((&(data)->aliases)->len){
    2609           0 : free_Principal(&(&(data)->aliases)->val[(&(data)->aliases)->len-1]);
    2610           0 : (&(data)->aliases)->len--;
    2611           0 : } else (&(data)->aliases)->len = 0;
    2612           0 : free((&(data)->aliases)->val);
    2613           0 : (&(data)->aliases)->val = NULL;
    2614           0 : }
    2615             : 
    2616             : size_t ASN1CALL
    2617           0 : length_HDB_Ext_Aliases(const HDB_Ext_Aliases *data)
    2618             : {
    2619           0 : size_t ret = 0;
    2620             : {
    2621           0 : size_t Top_tag_oldret = ret;
    2622           0 : ret = 0;
    2623           0 : ret += 1;
    2624           0 : ret += 1 + der_length_len (ret);
    2625           0 : ret += 1 + der_length_len (ret);
    2626           0 : ret += Top_tag_oldret;
    2627             : }
    2628             : {
    2629           0 : size_t Top_tag_oldret = ret;
    2630           0 : ret = 0;
    2631             : {
    2632           0 : size_t aliases_tag_tag_oldret = ret;
    2633           0 : unsigned int n_aliases_tag_tag;
    2634           0 : ret = 0;
    2635           0 : for(n_aliases_tag_tag = (&(data)->aliases)->len; n_aliases_tag_tag > 0; --n_aliases_tag_tag){
    2636           0 : size_t aliases_tag_tag_for_oldret = ret;
    2637           0 : ret = 0;
    2638           0 : ret += length_Principal(&(&(data)->aliases)->val[n_aliases_tag_tag - 1]);
    2639           0 : ret += aliases_tag_tag_for_oldret;
    2640             : }
    2641           0 : ret += aliases_tag_tag_oldret;
    2642             : }
    2643           0 : ret += 1 + der_length_len (ret);
    2644           0 : ret += 1 + der_length_len (ret);
    2645           0 : ret += Top_tag_oldret;
    2646             : }
    2647           0 : ret += 1 + der_length_len (ret);
    2648           0 : return ret;
    2649             : }
    2650             : 
    2651             : int ASN1CALL
    2652           0 : copy_HDB_Ext_Aliases(const HDB_Ext_Aliases *from, HDB_Ext_Aliases *to)
    2653             : {
    2654           0 : memset(to, 0, sizeof(*to));
    2655           0 : *(&(to)->case_insensitive) = *(&(from)->case_insensitive);
    2656           0 : if(((&(to)->aliases)->val = calloc(1, (&(from)->aliases)->len * sizeof(*(&(to)->aliases)->val))) == NULL && (&(from)->aliases)->len != 0)
    2657           0 : goto fail;
    2658           0 : for((&(to)->aliases)->len = 0; (&(to)->aliases)->len < (&(from)->aliases)->len; (&(to)->aliases)->len++){
    2659           0 : if(copy_Principal(&(&(from)->aliases)->val[(&(to)->aliases)->len], &(&(to)->aliases)->val[(&(to)->aliases)->len])) goto fail;
    2660             : }
    2661           0 : return 0;
    2662           0 : fail:
    2663           0 : free_HDB_Ext_Aliases(to);
    2664           0 : return ENOMEM;
    2665             : }
    2666             : 
    2667             : char * ASN1CALL
    2668           0 : print_HDB_Ext_Aliases(const HDB_Ext_Aliases *data, int flags)
    2669           0 : { errno = EINVAL; return 0; }
    2670             : 
    2671             : int ASN1CALL
    2672           0 : encode_Keys(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const Keys *data, size_t *size)
    2673             : {
    2674           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2675           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2676           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2677             : 
    2678           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    2679           0 : size_t Top_tag_for_oldret = ret;
    2680           0 : ret = 0;
    2681           0 : e = encode_Key(p, len, &(data)->val[i], &l);
    2682           0 : if (e) return e;
    2683           0 : p -= l; len -= l; ret += l;
    2684             : 
    2685           0 : ret += Top_tag_for_oldret;
    2686             : }
    2687           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2688           0 : if (e) return e;
    2689           0 : p -= l; len -= l; ret += l;
    2690             : 
    2691           0 : *size = ret;
    2692           0 : return 0;
    2693             : }
    2694             : 
    2695             : int ASN1CALL
    2696           0 : decode_Keys(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, Keys *data, size_t *size)
    2697             : {
    2698           0 : size_t ret = 0;
    2699           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2700           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2701             : 
    2702           0 : memset(data, 0, sizeof(*data));
    2703             : {
    2704           0 : size_t Top_datalen;
    2705           0 : Der_type Top_type;
    2706           0 : size_t Top_oldlen;
    2707           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    2708           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    2709           0 : if (e) goto fail;
    2710           0 : p += l; len -= l; ret += l;
    2711           0 : Top_oldlen = len;
    2712           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2713           0 : len = Top_datalen;
    2714             : {
    2715           0 : size_t Top_Tag_origlen = len;
    2716           0 : size_t Top_Tag_oldret = ret;
    2717           0 : size_t Top_Tag_olen = 0;
    2718           0 : void *Top_Tag_tmp;
    2719           0 : ret = 0;
    2720           0 : (data)->len = 0;
    2721           0 : (data)->val = NULL;
    2722           0 : while(ret < Top_Tag_origlen) {
    2723           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    2724           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    2725           0 : Top_Tag_olen = Top_Tag_nlen;
    2726           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    2727           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    2728           0 : (data)->val = Top_Tag_tmp;
    2729           0 : e = decode_Key(p, len, &(data)->val[(data)->len], &l);
    2730           0 : if(e) goto fail;
    2731           0 : p += l; len -= l; ret += l;
    2732           0 : (data)->len++;
    2733           0 : len = Top_Tag_origlen - ret;
    2734             : }
    2735           0 : ret += Top_Tag_oldret;
    2736             : }
    2737           0 : len = Top_oldlen - Top_datalen;
    2738             : }
    2739           0 : if(size) *size = ret;
    2740           0 : return 0;
    2741           0 : fail:
    2742           0 : free_Keys(data);
    2743           0 : return e;
    2744             : }
    2745             : 
    2746             : void ASN1CALL
    2747      324607 : free_Keys(Keys *data)
    2748             : {
    2749      324607 : if ((data)->val)
    2750      853590 : while((data)->len){
    2751      539948 : free_Key(&(data)->val[(data)->len-1]);
    2752      539948 : (data)->len--;
    2753       10965 : } else (data)->len = 0;
    2754      324607 : free((data)->val);
    2755      324607 : (data)->val = NULL;
    2756      324607 : }
    2757             : 
    2758             : size_t ASN1CALL
    2759           0 : length_Keys(const Keys *data)
    2760             : {
    2761           0 : size_t ret = 0;
    2762             : {
    2763           0 : size_t Top_tag_oldret = ret;
    2764           0 : unsigned int n_Top_tag;
    2765           0 : ret = 0;
    2766           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    2767           0 : size_t Top_tag_for_oldret = ret;
    2768           0 : ret = 0;
    2769           0 : ret += length_Key(&(data)->val[n_Top_tag - 1]);
    2770           0 : ret += Top_tag_for_oldret;
    2771             : }
    2772           0 : ret += Top_tag_oldret;
    2773             : }
    2774           0 : ret += 1 + der_length_len (ret);
    2775           0 : return ret;
    2776             : }
    2777             : 
    2778             : int ASN1CALL
    2779        4090 : copy_Keys(const Keys *from, Keys *to)
    2780             : {
    2781        4090 : memset(to, 0, sizeof(*to));
    2782        4090 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    2783           0 : goto fail;
    2784        8180 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    2785        4090 : if(copy_Key(&(from)->val[(to)->len], &(to)->val[(to)->len])) goto fail;
    2786             : }
    2787        4036 : return 0;
    2788           0 : fail:
    2789           0 : free_Keys(to);
    2790           0 : return ENOMEM;
    2791             : }
    2792             : 
    2793             : char * ASN1CALL
    2794           0 : print_Keys(const Keys *data, int flags)
    2795           0 : { errno = EINVAL; return 0; }
    2796             : 
    2797             : int ASN1CALL
    2798        6950 : add_Keys(Keys *data, const Key *element)
    2799             : {
    2800          72 : int ret;
    2801          72 : void *ptr;
    2802             : 
    2803        6950 : ptr = realloc(data->val, 
    2804        6950 :         (data->len + 1) * sizeof(data->val[0]));
    2805        6950 : if (ptr == NULL) return ENOMEM;
    2806        6950 : data->val = ptr;
    2807             : 
    2808        6950 : ret = copy_Key(element, &data->val[data->len]);
    2809        6950 : if (ret) return ret;
    2810        6950 : data->len++;
    2811        6950 : return 0;
    2812             : }
    2813             : 
    2814             : int ASN1CALL
    2815           0 : remove_Keys(Keys *data, unsigned int element)
    2816             : {
    2817           0 : void *ptr;
    2818             : 
    2819           0 : if (data->len == 0 || element >= data->len)
    2820           0 :         return ASN1_OVERRUN;
    2821           0 : free_Key(&data->val[element]);
    2822           0 : data->len--;
    2823           0 : if (element < data->len)
    2824           0 :         memmove(&data->val[element], &data->val[element + 1], 
    2825           0 :                 sizeof(data->val[0]) * (data->len - element));
    2826           0 : ptr = realloc(data->val, data->len * sizeof(data->val[0]));
    2827           0 : if (ptr != NULL || data->len == 0) data->val = ptr;
    2828           0 : return 0;
    2829             : }
    2830             : 
    2831             : int ASN1CALL
    2832           0 : encode_HDB_keyset(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_keyset *data, size_t *size)
    2833             : {
    2834           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    2835           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2836           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    2837             : 
    2838             : /* set-time */
    2839           0 : if((data)->set_time) {
    2840           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2841           0 : ret = 0;
    2842           0 : e = encode_KerberosTime(p, len, (data)->set_time, &l);
    2843           0 : if (e) return e;
    2844           0 : p -= l; len -= l; ret += l;
    2845             : 
    2846           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    2847           0 : if (e) return e;
    2848           0 : p -= l; len -= l; ret += l;
    2849             : 
    2850           0 : ret += Top_tag_oldret;
    2851             : }
    2852             : /* keys */
    2853             : {
    2854           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2855           0 : ret = 0;
    2856           0 : e = encode_Keys(p, len, &(data)->keys, &l);
    2857           0 : if (e) return e;
    2858           0 : p -= l; len -= l; ret += l;
    2859             : 
    2860           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    2861           0 : if (e) return e;
    2862           0 : p -= l; len -= l; ret += l;
    2863             : 
    2864           0 : ret += Top_tag_oldret;
    2865             : }
    2866             : /* kvno */
    2867             : {
    2868           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    2869           0 : ret = 0;
    2870           0 : e = der_put_unsigned(p, len, &(data)->kvno, &l);
    2871           0 : if (e) return e;
    2872           0 : p -= l; len -= l; ret += l;
    2873             : 
    2874           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    2875           0 : if (e) return e;
    2876           0 : p -= l; len -= l; ret += l;
    2877             : 
    2878           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    2879           0 : if (e) return e;
    2880           0 : p -= l; len -= l; ret += l;
    2881             : 
    2882           0 : ret += Top_tag_oldret;
    2883             : }
    2884           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    2885           0 : if (e) return e;
    2886           0 : p -= l; len -= l; ret += l;
    2887             : 
    2888           0 : *size = ret;
    2889           0 : return 0;
    2890             : }
    2891             : 
    2892             : int ASN1CALL
    2893           0 : decode_HDB_keyset(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_keyset *data, size_t *size)
    2894             : {
    2895           0 : size_t ret = 0;
    2896           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    2897           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    2898             : 
    2899           0 : memset(data, 0, sizeof(*data));
    2900             : {
    2901           0 : size_t Top_datalen;
    2902           0 : Der_type Top_type;
    2903           0 : size_t Top_oldlen;
    2904           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    2905           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    2906           0 : if (e) goto fail;
    2907           0 : p += l; len -= l; ret += l;
    2908           0 : Top_oldlen = len;
    2909           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2910           0 : len = Top_datalen;
    2911             : {
    2912           0 : size_t kvno_datalen;
    2913           0 : Der_type kvno_type;
    2914           0 : size_t kvno_oldlen;
    2915           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &kvno_type, 0, &kvno_datalen, &l);
    2916           0 : if (e == 0 && kvno_type != CONS) { e = ASN1_BAD_ID; }
    2917           0 : if (e) goto fail;
    2918           0 : p += l; len -= l; ret += l;
    2919           0 : kvno_oldlen = len;
    2920           0 : if (kvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2921           0 : len = kvno_datalen;
    2922             : {
    2923           0 : size_t kvno_Tag_datalen;
    2924           0 : Der_type kvno_Tag_type;
    2925           0 : size_t kvno_Tag_oldlen;
    2926           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &kvno_Tag_type, UT_Integer, &kvno_Tag_datalen, &l);
    2927           0 : if (e == 0 && kvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    2928           0 : if (e) goto fail;
    2929           0 : p += l; len -= l; ret += l;
    2930           0 : kvno_Tag_oldlen = len;
    2931           0 : if (kvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2932           0 : len = kvno_Tag_datalen;
    2933           0 : e = der_get_unsigned(p, len, &(data)->kvno, &l);
    2934           0 : if(e) goto fail;
    2935           0 : p += l; len -= l; ret += l;
    2936           0 : len = kvno_Tag_oldlen - kvno_Tag_datalen;
    2937             : }
    2938           0 : len = kvno_oldlen - kvno_datalen;
    2939             : }
    2940             : {
    2941           0 : size_t keys_datalen;
    2942           0 : Der_type keys_type;
    2943           0 : size_t keys_oldlen;
    2944           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &keys_type, 1, &keys_datalen, &l);
    2945           0 : if (e == 0 && keys_type != CONS) { e = ASN1_BAD_ID; }
    2946           0 : if (e) goto fail;
    2947           0 : p += l; len -= l; ret += l;
    2948           0 : keys_oldlen = len;
    2949           0 : if (keys_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2950           0 : len = keys_datalen;
    2951           0 : e = decode_Keys(p, len, &(data)->keys, &l);
    2952           0 : if(e) goto fail;
    2953           0 : p += l; len -= l; ret += l;
    2954           0 : len = keys_oldlen - keys_datalen;
    2955             : }
    2956             : {
    2957           0 : size_t set_time_datalen;
    2958           0 : Der_type set_time_type;
    2959           0 : size_t set_time_oldlen;
    2960           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &set_time_type, 2, &set_time_datalen, &l);
    2961           0 : if (e == 0 && set_time_type != CONS) { e = ASN1_BAD_ID; }
    2962           0 : if(e) {
    2963           0 : (data)->set_time = NULL;
    2964             : } else {
    2965           0 : (data)->set_time = calloc(1, sizeof(*(data)->set_time));
    2966           0 : if ((data)->set_time == NULL) { e = ENOMEM; goto fail; }
    2967           0 : p += l; len -= l; ret += l;
    2968           0 : set_time_oldlen = len;
    2969           0 : if (set_time_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    2970           0 : len = set_time_datalen;
    2971           0 : e = decode_KerberosTime(p, len, (data)->set_time, &l);
    2972           0 : if(e) goto fail;
    2973           0 : p += l; len -= l; ret += l;
    2974           0 : len = set_time_oldlen - set_time_datalen;
    2975             : }
    2976             : }
    2977           0 : len = Top_oldlen - Top_datalen;
    2978             : }
    2979           0 : if(size) *size = ret;
    2980           0 : return 0;
    2981           0 : fail:
    2982           0 : free_HDB_keyset(data);
    2983           0 : return e;
    2984             : }
    2985             : 
    2986             : void ASN1CALL
    2987       11036 : free_HDB_keyset(HDB_keyset *data)
    2988             : {
    2989       11036 : *&(data)->kvno = 0;
    2990       11036 : free_Keys(&(data)->keys);
    2991       11036 : if((data)->set_time) {
    2992           0 : free_KerberosTime((data)->set_time);
    2993           0 : free((data)->set_time);
    2994           0 : (data)->set_time = NULL;
    2995             : }
    2996       11036 : }
    2997             : 
    2998             : size_t ASN1CALL
    2999           0 : length_HDB_keyset(const HDB_keyset *data)
    3000             : {
    3001           0 : size_t ret = 0;
    3002             : {
    3003           0 : size_t Top_tag_oldret = ret;
    3004           0 : ret = 0;
    3005           0 : ret += der_length_unsigned(&(data)->kvno);
    3006           0 : ret += 1 + der_length_len (ret);
    3007           0 : ret += 1 + der_length_len (ret);
    3008           0 : ret += Top_tag_oldret;
    3009             : }
    3010             : {
    3011           0 : size_t Top_tag_oldret = ret;
    3012           0 : ret = 0;
    3013           0 : ret += length_Keys(&(data)->keys);
    3014           0 : ret += 1 + der_length_len (ret);
    3015           0 : ret += Top_tag_oldret;
    3016             : }
    3017           0 : if((data)->set_time){
    3018           0 : size_t Top_tag_oldret = ret;
    3019           0 : ret = 0;
    3020           0 : ret += length_KerberosTime((data)->set_time);
    3021           0 : ret += 1 + der_length_len (ret);
    3022           0 : ret += Top_tag_oldret;
    3023             : }
    3024           0 : ret += 1 + der_length_len (ret);
    3025           0 : return ret;
    3026             : }
    3027             : 
    3028             : int ASN1CALL
    3029        4090 : copy_HDB_keyset(const HDB_keyset *from, HDB_keyset *to)
    3030             : {
    3031        4090 : memset(to, 0, sizeof(*to));
    3032        4090 : *(&(to)->kvno) = *(&(from)->kvno);
    3033        4090 : if(copy_Keys(&(from)->keys, &(to)->keys)) goto fail;
    3034        4090 : if((from)->set_time) {
    3035           0 : (to)->set_time = calloc(1, sizeof(*(to)->set_time));
    3036           0 : if((to)->set_time == NULL) goto fail;
    3037           0 : if(copy_KerberosTime((from)->set_time, (to)->set_time)) goto fail;
    3038             : }else
    3039        4090 : (to)->set_time = NULL;
    3040        4036 : return 0;
    3041           0 : fail:
    3042           0 : free_HDB_keyset(to);
    3043           0 : return ENOMEM;
    3044             : }
    3045             : 
    3046             : char * ASN1CALL
    3047           0 : print_HDB_keyset(const HDB_keyset *data, int flags)
    3048           0 : { errno = EINVAL; return 0; }
    3049             : 
    3050             : int ASN1CALL
    3051           0 : encode_HDB_Ext_KeySet(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_KeySet *data, size_t *size)
    3052             : {
    3053           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    3054           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3055           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    3056             : 
    3057           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    3058           0 : size_t Top_tag_for_oldret = ret;
    3059           0 : ret = 0;
    3060           0 : e = encode_HDB_keyset(p, len, &(data)->val[i], &l);
    3061           0 : if (e) return e;
    3062           0 : p -= l; len -= l; ret += l;
    3063             : 
    3064           0 : ret += Top_tag_for_oldret;
    3065             : }
    3066           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    3067           0 : if (e) return e;
    3068           0 : p -= l; len -= l; ret += l;
    3069             : 
    3070           0 : *size = ret;
    3071           0 : return 0;
    3072             : }
    3073             : 
    3074             : int ASN1CALL
    3075           0 : decode_HDB_Ext_KeySet(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_KeySet *data, size_t *size)
    3076             : {
    3077           0 : size_t ret = 0;
    3078           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3079           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    3080             : 
    3081           0 : memset(data, 0, sizeof(*data));
    3082             : {
    3083           0 : size_t Top_datalen;
    3084           0 : Der_type Top_type;
    3085           0 : size_t Top_oldlen;
    3086           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    3087           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    3088           0 : if (e) goto fail;
    3089           0 : p += l; len -= l; ret += l;
    3090           0 : Top_oldlen = len;
    3091           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3092           0 : len = Top_datalen;
    3093             : {
    3094           0 : size_t Top_Tag_origlen = len;
    3095           0 : size_t Top_Tag_oldret = ret;
    3096           0 : size_t Top_Tag_olen = 0;
    3097           0 : void *Top_Tag_tmp;
    3098           0 : ret = 0;
    3099           0 : (data)->len = 0;
    3100           0 : (data)->val = NULL;
    3101           0 : while(ret < Top_Tag_origlen) {
    3102           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    3103           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    3104           0 : Top_Tag_olen = Top_Tag_nlen;
    3105           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    3106           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    3107           0 : (data)->val = Top_Tag_tmp;
    3108           0 : e = decode_HDB_keyset(p, len, &(data)->val[(data)->len], &l);
    3109           0 : if(e) goto fail;
    3110           0 : p += l; len -= l; ret += l;
    3111           0 : (data)->len++;
    3112           0 : len = Top_Tag_origlen - ret;
    3113             : }
    3114           0 : ret += Top_Tag_oldret;
    3115             : }
    3116           0 : len = Top_oldlen - Top_datalen;
    3117             : }
    3118           0 : if(size) *size = ret;
    3119           0 : return 0;
    3120           0 : fail:
    3121           0 : free_HDB_Ext_KeySet(data);
    3122           0 : return e;
    3123             : }
    3124             : 
    3125             : void ASN1CALL
    3126        3288 : free_HDB_Ext_KeySet(HDB_Ext_KeySet *data)
    3127             : {
    3128        3288 : if ((data)->val)
    3129        7374 : while((data)->len){
    3130        4086 : free_HDB_keyset(&(data)->val[(data)->len-1]);
    3131        4086 : (data)->len--;
    3132           0 : } else (data)->len = 0;
    3133        3288 : free((data)->val);
    3134        3288 : (data)->val = NULL;
    3135        3288 : }
    3136             : 
    3137             : size_t ASN1CALL
    3138           0 : length_HDB_Ext_KeySet(const HDB_Ext_KeySet *data)
    3139             : {
    3140           0 : size_t ret = 0;
    3141             : {
    3142           0 : size_t Top_tag_oldret = ret;
    3143           0 : unsigned int n_Top_tag;
    3144           0 : ret = 0;
    3145           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    3146           0 : size_t Top_tag_for_oldret = ret;
    3147           0 : ret = 0;
    3148           0 : ret += length_HDB_keyset(&(data)->val[n_Top_tag - 1]);
    3149           0 : ret += Top_tag_for_oldret;
    3150             : }
    3151           0 : ret += Top_tag_oldret;
    3152             : }
    3153           0 : ret += 1 + der_length_len (ret);
    3154           0 : return ret;
    3155             : }
    3156             : 
    3157             : int ASN1CALL
    3158        1645 : copy_HDB_Ext_KeySet(const HDB_Ext_KeySet *from, HDB_Ext_KeySet *to)
    3159             : {
    3160        1645 : memset(to, 0, sizeof(*to));
    3161        1645 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    3162           0 : goto fail;
    3163        3290 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    3164        1645 : if(copy_HDB_keyset(&(from)->val[(to)->len], &(to)->val[(to)->len])) goto fail;
    3165             : }
    3166        1627 : return 0;
    3167           0 : fail:
    3168           0 : free_HDB_Ext_KeySet(to);
    3169           0 : return ENOMEM;
    3170             : }
    3171             : 
    3172             : char * ASN1CALL
    3173           0 : print_HDB_Ext_KeySet(const HDB_Ext_KeySet *data, int flags)
    3174           0 : { errno = EINVAL; return 0; }
    3175             : 
    3176             : int ASN1CALL
    3177        2445 : add_HDB_Ext_KeySet(HDB_Ext_KeySet *data, const HDB_keyset *element)
    3178             : {
    3179          36 : int ret;
    3180          36 : void *ptr;
    3181             : 
    3182        2445 : ptr = realloc(data->val, 
    3183        2445 :         (data->len + 1) * sizeof(data->val[0]));
    3184        2445 : if (ptr == NULL) return ENOMEM;
    3185        2445 : data->val = ptr;
    3186             : 
    3187        2445 : ret = copy_HDB_keyset(element, &data->val[data->len]);
    3188        2445 : if (ret) return ret;
    3189        2445 : data->len++;
    3190        2445 : return 0;
    3191             : }
    3192             : 
    3193             : int ASN1CALL
    3194           0 : remove_HDB_Ext_KeySet(HDB_Ext_KeySet *data, unsigned int element)
    3195             : {
    3196           0 : void *ptr;
    3197             : 
    3198           0 : if (data->len == 0 || element >= data->len)
    3199           0 :         return ASN1_OVERRUN;
    3200           0 : free_HDB_keyset(&data->val[element]);
    3201           0 : data->len--;
    3202           0 : if (element < data->len)
    3203           0 :         memmove(&data->val[element], &data->val[element + 1], 
    3204           0 :                 sizeof(data->val[0]) * (data->len - element));
    3205           0 : ptr = realloc(data->val, data->len * sizeof(data->val[0]));
    3206           0 : if (ptr != NULL || data->len == 0) data->val = ptr;
    3207           0 : return 0;
    3208             : }
    3209             : 
    3210             : int ASN1CALL
    3211           0 : encode_KeyRotationFlags(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const KeyRotationFlags *data, size_t *size)
    3212             : {
    3213           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    3214           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3215           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    3216             : 
    3217             : {
    3218           0 : unsigned char c = 0;
    3219           0 : int rest = 0;
    3220           0 : int bit_set = 0;
    3221           0 : if((data)->parent) {
    3222           0 : c |= 1<<6;
    3223             : }
    3224           0 : if((data)->deleted) {
    3225           0 : c |= 1<<7;
    3226             : }
    3227           0 : if (c != 0 || bit_set) {
    3228           0 : if (len < 1) return ASN1_OVERFLOW;
    3229           0 : *p-- = c; len--; ret++;
    3230           0 : if (!bit_set) {
    3231           0 : rest = 0;
    3232           0 : if(c) { 
    3233           0 : while(c) { 
    3234           0 : if (c & 1) break;
    3235           0 : c = c >> 1;
    3236           0 : rest++;
    3237             : }
    3238             : }
    3239             : }
    3240             : }
    3241           0 : if (len < 1) return ASN1_OVERFLOW;
    3242           0 : *p-- = rest;
    3243           0 : len -= 1;
    3244           0 : ret += 1;
    3245             : }
    3246             : 
    3247           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_BitString, &l);
    3248           0 : if (e) return e;
    3249           0 : p -= l; len -= l; ret += l;
    3250             : 
    3251           0 : *size = ret;
    3252           0 : return 0;
    3253             : }
    3254             : 
    3255             : int ASN1CALL
    3256           0 : decode_KeyRotationFlags(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, KeyRotationFlags *data, size_t *size)
    3257             : {
    3258           0 : size_t ret = 0;
    3259           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3260           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    3261             : 
    3262           0 : memset(data, 0, sizeof(*data));
    3263             : {
    3264           0 : size_t Top_datalen;
    3265           0 : Der_type Top_type;
    3266           0 : size_t Top_oldlen;
    3267           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_BitString, &Top_datalen, &l);
    3268           0 : if (e == 0 && Top_type != PRIM) { e = ASN1_BAD_ID; }
    3269           0 : if (e) goto fail;
    3270           0 : p += l; len -= l; ret += l;
    3271           0 : Top_oldlen = len;
    3272           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3273           0 : len = Top_datalen;
    3274           0 : if (len < 1) return ASN1_OVERRUN;
    3275           0 : p++; len--; ret++;
    3276           0 : do {
    3277           0 : if (len < 1) break;
    3278           0 : (data)->deleted = (*p >> 7) & 1;
    3279           0 : (data)->parent = (*p >> 6) & 1;
    3280             : } while(0);
    3281           0 : p += len; ret += len;
    3282           0 : len = Top_oldlen - Top_datalen;
    3283             : }
    3284           0 : if(size) *size = ret;
    3285           0 : return 0;
    3286           0 : fail:
    3287           0 : free_KeyRotationFlags(data);
    3288           0 : return e;
    3289             : }
    3290             : 
    3291             : void ASN1CALL
    3292           0 : free_KeyRotationFlags(KeyRotationFlags *data)
    3293             : {
    3294           0 : }
    3295             : 
    3296             : size_t ASN1CALL
    3297           0 : length_KeyRotationFlags(const KeyRotationFlags *data)
    3298             : {
    3299           0 : size_t ret = 0;
    3300           0 : do {
    3301           0 : if((data)->parent) { ret += 1; break; }
    3302           0 : if((data)->deleted) { ret += 1; break; }
    3303             : } while(0);
    3304           0 : ret += 1;
    3305           0 : ret += 1 + der_length_len (ret);
    3306           0 : return ret;
    3307             : }
    3308             : 
    3309             : int ASN1CALL
    3310           0 : copy_KeyRotationFlags(const KeyRotationFlags *from, KeyRotationFlags *to)
    3311             : {
    3312           0 : memset(to, 0, sizeof(*to));
    3313           0 : *(to) = *(from);
    3314           0 : return 0;
    3315             : }
    3316             : 
    3317             : char * ASN1CALL
    3318           0 : print_KeyRotationFlags(const KeyRotationFlags *data, int flags)
    3319           0 : { errno = EINVAL; return 0; }
    3320             : 
    3321           0 : uint64_t KeyRotationFlags2int(KeyRotationFlags f)
    3322             : {
    3323           0 : uint64_t r = 0;
    3324           0 : if(f.deleted) r |= (1ULL << 0);
    3325           0 : if(f.parent) r |= (1ULL << 1);
    3326           0 : return r;
    3327             : }
    3328             : 
    3329           0 : KeyRotationFlags int2KeyRotationFlags(uint64_t n)
    3330             : {
    3331           0 :         KeyRotationFlags flags;
    3332             : 
    3333           0 :         memset(&flags, 0, sizeof(flags));
    3334             : 
    3335           0 :         flags.deleted = (n >> 0) & 1;
    3336           0 :         flags.parent = (n >> 1) & 1;
    3337           0 :         return flags;
    3338             : }
    3339             : 
    3340             : static struct units KeyRotationFlags_units[] = {
    3341             :         {"parent",    1ULL << 1},
    3342             :         {"deleted",   1ULL << 0},
    3343             :         {NULL,  0}
    3344             : };
    3345             : 
    3346           0 : const struct units * asn1_KeyRotationFlags_units(void){
    3347           0 : return KeyRotationFlags_units;
    3348             : }
    3349             : 
    3350             : int ASN1CALL
    3351           0 : encode_KeyRotation(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const KeyRotation *data, size_t *size)
    3352             : {
    3353           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    3354           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3355           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    3356             : 
    3357             : /* base-key-kvno */
    3358             : {
    3359           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3360           0 : ret = 0;
    3361           0 : e = der_put_unsigned(p, len, &(data)->base_key_kvno, &l);
    3362           0 : if (e) return e;
    3363           0 : p -= l; len -= l; ret += l;
    3364             : 
    3365           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3366           0 : if (e) return e;
    3367           0 : p -= l; len -= l; ret += l;
    3368             : 
    3369           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 4, &l);
    3370           0 : if (e) return e;
    3371           0 : p -= l; len -= l; ret += l;
    3372             : 
    3373           0 : ret += Top_tag_oldret;
    3374             : }
    3375             : /* base-kvno */
    3376             : {
    3377           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3378           0 : ret = 0;
    3379           0 : e = der_put_unsigned(p, len, &(data)->base_kvno, &l);
    3380           0 : if (e) return e;
    3381           0 : p -= l; len -= l; ret += l;
    3382             : 
    3383           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3384           0 : if (e) return e;
    3385           0 : p -= l; len -= l; ret += l;
    3386             : 
    3387           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 3, &l);
    3388           0 : if (e) return e;
    3389           0 : p -= l; len -= l; ret += l;
    3390             : 
    3391           0 : ret += Top_tag_oldret;
    3392             : }
    3393             : /* period */
    3394             : {
    3395           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3396           0 : ret = 0;
    3397           0 : e = der_put_unsigned(p, len, &(data)->period, &l);
    3398           0 : if (e) return e;
    3399           0 : p -= l; len -= l; ret += l;
    3400             : 
    3401           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3402           0 : if (e) return e;
    3403           0 : p -= l; len -= l; ret += l;
    3404             : 
    3405           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    3406           0 : if (e) return e;
    3407           0 : p -= l; len -= l; ret += l;
    3408             : 
    3409           0 : ret += Top_tag_oldret;
    3410             : }
    3411             : /* epoch */
    3412             : {
    3413           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3414           0 : ret = 0;
    3415           0 : e = encode_KerberosTime(p, len, &(data)->epoch, &l);
    3416           0 : if (e) return e;
    3417           0 : p -= l; len -= l; ret += l;
    3418             : 
    3419           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    3420           0 : if (e) return e;
    3421           0 : p -= l; len -= l; ret += l;
    3422             : 
    3423           0 : ret += Top_tag_oldret;
    3424             : }
    3425             : /* flags */
    3426             : {
    3427           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3428           0 : ret = 0;
    3429           0 : e = encode_KeyRotationFlags(p, len, &(data)->flags, &l);
    3430           0 : if (e) return e;
    3431           0 : p -= l; len -= l; ret += l;
    3432             : 
    3433           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    3434           0 : if (e) return e;
    3435           0 : p -= l; len -= l; ret += l;
    3436             : 
    3437           0 : ret += Top_tag_oldret;
    3438             : }
    3439           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    3440           0 : if (e) return e;
    3441           0 : p -= l; len -= l; ret += l;
    3442             : 
    3443           0 : *size = ret;
    3444           0 : return 0;
    3445             : }
    3446             : 
    3447             : int ASN1CALL
    3448           0 : decode_KeyRotation(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, KeyRotation *data, size_t *size)
    3449             : {
    3450           0 : size_t ret = 0;
    3451           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3452           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    3453             : 
    3454           0 : memset(data, 0, sizeof(*data));
    3455             : {
    3456           0 : size_t Top_datalen;
    3457           0 : Der_type Top_type;
    3458           0 : size_t Top_oldlen;
    3459           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    3460           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    3461           0 : if (e) goto fail;
    3462           0 : p += l; len -= l; ret += l;
    3463           0 : Top_oldlen = len;
    3464           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3465           0 : len = Top_datalen;
    3466             : {
    3467           0 : size_t flags_datalen;
    3468           0 : Der_type flags_type;
    3469           0 : size_t flags_oldlen;
    3470           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &flags_type, 0, &flags_datalen, &l);
    3471           0 : if (e == 0 && flags_type != CONS) { e = ASN1_BAD_ID; }
    3472           0 : if (e) goto fail;
    3473           0 : p += l; len -= l; ret += l;
    3474           0 : flags_oldlen = len;
    3475           0 : if (flags_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3476           0 : len = flags_datalen;
    3477           0 : e = decode_KeyRotationFlags(p, len, &(data)->flags, &l);
    3478           0 : if(e) goto fail;
    3479           0 : p += l; len -= l; ret += l;
    3480           0 : len = flags_oldlen - flags_datalen;
    3481             : }
    3482             : {
    3483           0 : size_t epoch_datalen;
    3484           0 : Der_type epoch_type;
    3485           0 : size_t epoch_oldlen;
    3486           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &epoch_type, 1, &epoch_datalen, &l);
    3487           0 : if (e == 0 && epoch_type != CONS) { e = ASN1_BAD_ID; }
    3488           0 : if (e) goto fail;
    3489           0 : p += l; len -= l; ret += l;
    3490           0 : epoch_oldlen = len;
    3491           0 : if (epoch_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3492           0 : len = epoch_datalen;
    3493           0 : e = decode_KerberosTime(p, len, &(data)->epoch, &l);
    3494           0 : if(e) goto fail;
    3495           0 : p += l; len -= l; ret += l;
    3496           0 : len = epoch_oldlen - epoch_datalen;
    3497             : }
    3498             : {
    3499           0 : size_t period_datalen;
    3500           0 : Der_type period_type;
    3501           0 : size_t period_oldlen;
    3502           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &period_type, 2, &period_datalen, &l);
    3503           0 : if (e == 0 && period_type != CONS) { e = ASN1_BAD_ID; }
    3504           0 : if (e) goto fail;
    3505           0 : p += l; len -= l; ret += l;
    3506           0 : period_oldlen = len;
    3507           0 : if (period_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3508           0 : len = period_datalen;
    3509             : {
    3510           0 : size_t period_Tag_datalen;
    3511           0 : Der_type period_Tag_type;
    3512           0 : size_t period_Tag_oldlen;
    3513           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &period_Tag_type, UT_Integer, &period_Tag_datalen, &l);
    3514           0 : if (e == 0 && period_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    3515           0 : if (e) goto fail;
    3516           0 : p += l; len -= l; ret += l;
    3517           0 : period_Tag_oldlen = len;
    3518           0 : if (period_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3519           0 : len = period_Tag_datalen;
    3520           0 : e = der_get_unsigned(p, len, &(data)->period, &l);
    3521           0 : if(e) goto fail;
    3522           0 : p += l; len -= l; ret += l;
    3523           0 : len = period_Tag_oldlen - period_Tag_datalen;
    3524             : }
    3525           0 : len = period_oldlen - period_datalen;
    3526             : }
    3527             : {
    3528           0 : size_t base_kvno_datalen;
    3529           0 : Der_type base_kvno_type;
    3530           0 : size_t base_kvno_oldlen;
    3531           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &base_kvno_type, 3, &base_kvno_datalen, &l);
    3532           0 : if (e == 0 && base_kvno_type != CONS) { e = ASN1_BAD_ID; }
    3533           0 : if (e) goto fail;
    3534           0 : p += l; len -= l; ret += l;
    3535           0 : base_kvno_oldlen = len;
    3536           0 : if (base_kvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3537           0 : len = base_kvno_datalen;
    3538             : {
    3539           0 : size_t base_kvno_Tag_datalen;
    3540           0 : Der_type base_kvno_Tag_type;
    3541           0 : size_t base_kvno_Tag_oldlen;
    3542           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &base_kvno_Tag_type, UT_Integer, &base_kvno_Tag_datalen, &l);
    3543           0 : if (e == 0 && base_kvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    3544           0 : if (e) goto fail;
    3545           0 : p += l; len -= l; ret += l;
    3546           0 : base_kvno_Tag_oldlen = len;
    3547           0 : if (base_kvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3548           0 : len = base_kvno_Tag_datalen;
    3549           0 : e = der_get_unsigned(p, len, &(data)->base_kvno, &l);
    3550           0 : if(e) goto fail;
    3551           0 : p += l; len -= l; ret += l;
    3552           0 : len = base_kvno_Tag_oldlen - base_kvno_Tag_datalen;
    3553             : }
    3554           0 : len = base_kvno_oldlen - base_kvno_datalen;
    3555             : }
    3556             : {
    3557           0 : size_t base_key_kvno_datalen;
    3558           0 : Der_type base_key_kvno_type;
    3559           0 : size_t base_key_kvno_oldlen;
    3560           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &base_key_kvno_type, 4, &base_key_kvno_datalen, &l);
    3561           0 : if (e == 0 && base_key_kvno_type != CONS) { e = ASN1_BAD_ID; }
    3562           0 : if (e) goto fail;
    3563           0 : p += l; len -= l; ret += l;
    3564           0 : base_key_kvno_oldlen = len;
    3565           0 : if (base_key_kvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3566           0 : len = base_key_kvno_datalen;
    3567             : {
    3568           0 : size_t base_key_kvno_Tag_datalen;
    3569           0 : Der_type base_key_kvno_Tag_type;
    3570           0 : size_t base_key_kvno_Tag_oldlen;
    3571           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &base_key_kvno_Tag_type, UT_Integer, &base_key_kvno_Tag_datalen, &l);
    3572           0 : if (e == 0 && base_key_kvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    3573           0 : if (e) goto fail;
    3574           0 : p += l; len -= l; ret += l;
    3575           0 : base_key_kvno_Tag_oldlen = len;
    3576           0 : if (base_key_kvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3577           0 : len = base_key_kvno_Tag_datalen;
    3578           0 : e = der_get_unsigned(p, len, &(data)->base_key_kvno, &l);
    3579           0 : if(e) goto fail;
    3580           0 : p += l; len -= l; ret += l;
    3581           0 : len = base_key_kvno_Tag_oldlen - base_key_kvno_Tag_datalen;
    3582             : }
    3583           0 : len = base_key_kvno_oldlen - base_key_kvno_datalen;
    3584             : }
    3585           0 : len = Top_oldlen - Top_datalen;
    3586             : }
    3587           0 : if(size) *size = ret;
    3588           0 : return 0;
    3589           0 : fail:
    3590           0 : free_KeyRotation(data);
    3591           0 : return e;
    3592             : }
    3593             : 
    3594             : void ASN1CALL
    3595           0 : free_KeyRotation(KeyRotation *data)
    3596             : {
    3597           0 : free_KeyRotationFlags(&(data)->flags);
    3598           0 : free_KerberosTime(&(data)->epoch);
    3599           0 : *&(data)->period = 0;
    3600           0 : *&(data)->base_kvno = 0;
    3601           0 : *&(data)->base_key_kvno = 0;
    3602           0 : }
    3603             : 
    3604             : size_t ASN1CALL
    3605           0 : length_KeyRotation(const KeyRotation *data)
    3606             : {
    3607           0 : size_t ret = 0;
    3608             : {
    3609           0 : size_t Top_tag_oldret = ret;
    3610           0 : ret = 0;
    3611           0 : ret += length_KeyRotationFlags(&(data)->flags);
    3612           0 : ret += 1 + der_length_len (ret);
    3613           0 : ret += Top_tag_oldret;
    3614             : }
    3615             : {
    3616           0 : size_t Top_tag_oldret = ret;
    3617           0 : ret = 0;
    3618           0 : ret += length_KerberosTime(&(data)->epoch);
    3619           0 : ret += 1 + der_length_len (ret);
    3620           0 : ret += Top_tag_oldret;
    3621             : }
    3622             : {
    3623           0 : size_t Top_tag_oldret = ret;
    3624           0 : ret = 0;
    3625           0 : ret += der_length_unsigned(&(data)->period);
    3626           0 : ret += 1 + der_length_len (ret);
    3627           0 : ret += 1 + der_length_len (ret);
    3628           0 : ret += Top_tag_oldret;
    3629             : }
    3630             : {
    3631           0 : size_t Top_tag_oldret = ret;
    3632           0 : ret = 0;
    3633           0 : ret += der_length_unsigned(&(data)->base_kvno);
    3634           0 : ret += 1 + der_length_len (ret);
    3635           0 : ret += 1 + der_length_len (ret);
    3636           0 : ret += Top_tag_oldret;
    3637             : }
    3638             : {
    3639           0 : size_t Top_tag_oldret = ret;
    3640           0 : ret = 0;
    3641           0 : ret += der_length_unsigned(&(data)->base_key_kvno);
    3642           0 : ret += 1 + der_length_len (ret);
    3643           0 : ret += 1 + der_length_len (ret);
    3644           0 : ret += Top_tag_oldret;
    3645             : }
    3646           0 : ret += 1 + der_length_len (ret);
    3647           0 : return ret;
    3648             : }
    3649             : 
    3650             : int ASN1CALL
    3651           0 : copy_KeyRotation(const KeyRotation *from, KeyRotation *to)
    3652             : {
    3653           0 : memset(to, 0, sizeof(*to));
    3654           0 : if(copy_KeyRotationFlags(&(from)->flags, &(to)->flags)) goto fail;
    3655           0 : if(copy_KerberosTime(&(from)->epoch, &(to)->epoch)) goto fail;
    3656           0 : *(&(to)->period) = *(&(from)->period);
    3657           0 : *(&(to)->base_kvno) = *(&(from)->base_kvno);
    3658           0 : *(&(to)->base_key_kvno) = *(&(from)->base_key_kvno);
    3659           0 : return 0;
    3660           0 : fail:
    3661           0 : free_KeyRotation(to);
    3662           0 : return ENOMEM;
    3663             : }
    3664             : 
    3665             : char * ASN1CALL
    3666           0 : print_KeyRotation(const KeyRotation *data, int flags)
    3667           0 : { errno = EINVAL; return 0; }
    3668             : 
    3669             : int ASN1CALL
    3670           0 : encode_HDB_Ext_KeyRotation(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_Ext_KeyRotation *data, size_t *size)
    3671             : {
    3672           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    3673           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3674           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    3675             : 
    3676           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    3677           0 : size_t Top_tag_for_oldret = ret;
    3678           0 : ret = 0;
    3679           0 : e = encode_KeyRotation(p, len, &(data)->val[i], &l);
    3680           0 : if (e) return e;
    3681           0 : p -= l; len -= l; ret += l;
    3682             : 
    3683           0 : ret += Top_tag_for_oldret;
    3684             : }
    3685           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    3686           0 : if (e) return e;
    3687           0 : p -= l; len -= l; ret += l;
    3688             : 
    3689           0 : *size = ret;
    3690           0 : return 0;
    3691             : }
    3692             : 
    3693             : int ASN1CALL
    3694           0 : decode_HDB_Ext_KeyRotation(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_Ext_KeyRotation *data, size_t *size)
    3695             : {
    3696           0 : size_t ret = 0;
    3697           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3698           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    3699             : 
    3700           0 : memset(data, 0, sizeof(*data));
    3701             : {
    3702           0 : size_t Top_datalen;
    3703           0 : Der_type Top_type;
    3704           0 : size_t Top_oldlen;
    3705           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    3706           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    3707           0 : if (e) goto fail;
    3708           0 : p += l; len -= l; ret += l;
    3709           0 : Top_oldlen = len;
    3710           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    3711           0 : len = Top_datalen;
    3712             : {
    3713           0 : size_t Top_Tag_origlen = len;
    3714           0 : size_t Top_Tag_oldret = ret;
    3715           0 : size_t Top_Tag_olen = 0;
    3716           0 : void *Top_Tag_tmp;
    3717           0 : ret = 0;
    3718           0 : (data)->len = 0;
    3719           0 : (data)->val = NULL;
    3720           0 : while(ret < Top_Tag_origlen) {
    3721           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    3722           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    3723           0 : Top_Tag_olen = Top_Tag_nlen;
    3724           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    3725           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    3726           0 : (data)->val = Top_Tag_tmp;
    3727           0 : e = decode_KeyRotation(p, len, &(data)->val[(data)->len], &l);
    3728           0 : if(e) goto fail;
    3729           0 : p += l; len -= l; ret += l;
    3730           0 : (data)->len++;
    3731           0 : len = Top_Tag_origlen - ret;
    3732             : }
    3733           0 : ret += Top_Tag_oldret;
    3734             : }
    3735           0 : if ((data)->len > 3) {
    3736           0 : e = ASN1_MAX_CONSTRAINT; goto fail;
    3737             : }
    3738           0 : if ((data)->len < 1) {
    3739           0 : e = ASN1_MIN_CONSTRAINT; goto fail;
    3740             : }
    3741           0 : len = Top_oldlen - Top_datalen;
    3742             : }
    3743           0 : if(size) *size = ret;
    3744           0 : return 0;
    3745           0 : fail:
    3746           0 : free_HDB_Ext_KeyRotation(data);
    3747           0 : return e;
    3748             : }
    3749             : 
    3750             : void ASN1CALL
    3751           0 : free_HDB_Ext_KeyRotation(HDB_Ext_KeyRotation *data)
    3752             : {
    3753           0 : if ((data)->val)
    3754           0 : while((data)->len){
    3755           0 : free_KeyRotation(&(data)->val[(data)->len-1]);
    3756           0 : (data)->len--;
    3757           0 : } else (data)->len = 0;
    3758           0 : free((data)->val);
    3759           0 : (data)->val = NULL;
    3760           0 : }
    3761             : 
    3762             : size_t ASN1CALL
    3763           0 : length_HDB_Ext_KeyRotation(const HDB_Ext_KeyRotation *data)
    3764             : {
    3765           0 : size_t ret = 0;
    3766             : {
    3767           0 : size_t Top_tag_oldret = ret;
    3768           0 : unsigned int n_Top_tag;
    3769           0 : ret = 0;
    3770           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    3771           0 : size_t Top_tag_for_oldret = ret;
    3772           0 : ret = 0;
    3773           0 : ret += length_KeyRotation(&(data)->val[n_Top_tag - 1]);
    3774           0 : ret += Top_tag_for_oldret;
    3775             : }
    3776           0 : ret += Top_tag_oldret;
    3777             : }
    3778           0 : ret += 1 + der_length_len (ret);
    3779           0 : return ret;
    3780             : }
    3781             : 
    3782             : int ASN1CALL
    3783           0 : copy_HDB_Ext_KeyRotation(const HDB_Ext_KeyRotation *from, HDB_Ext_KeyRotation *to)
    3784             : {
    3785           0 : memset(to, 0, sizeof(*to));
    3786           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    3787           0 : goto fail;
    3788           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    3789           0 : if(copy_KeyRotation(&(from)->val[(to)->len], &(to)->val[(to)->len])) goto fail;
    3790             : }
    3791           0 : return 0;
    3792           0 : fail:
    3793           0 : free_HDB_Ext_KeyRotation(to);
    3794           0 : return ENOMEM;
    3795             : }
    3796             : 
    3797             : char * ASN1CALL
    3798           0 : print_HDB_Ext_KeyRotation(const HDB_Ext_KeyRotation *data, int flags)
    3799           0 : { errno = EINVAL; return 0; }
    3800             : 
    3801             : int ASN1CALL
    3802           0 : add_HDB_Ext_KeyRotation(HDB_Ext_KeyRotation *data, const KeyRotation *element)
    3803             : {
    3804           0 : int ret;
    3805           0 : void *ptr;
    3806             : 
    3807           0 : ptr = realloc(data->val, 
    3808           0 :         (data->len + 1) * sizeof(data->val[0]));
    3809           0 : if (ptr == NULL) return ENOMEM;
    3810           0 : data->val = ptr;
    3811             : 
    3812           0 : ret = copy_KeyRotation(element, &data->val[data->len]);
    3813           0 : if (ret) return ret;
    3814           0 : data->len++;
    3815           0 : return 0;
    3816             : }
    3817             : 
    3818             : int ASN1CALL
    3819           0 : remove_HDB_Ext_KeyRotation(HDB_Ext_KeyRotation *data, unsigned int element)
    3820             : {
    3821           0 : void *ptr;
    3822             : 
    3823           0 : if (data->len == 0 || element >= data->len)
    3824           0 :         return ASN1_OVERRUN;
    3825           0 : free_KeyRotation(&data->val[element]);
    3826           0 : data->len--;
    3827           0 : if (element < data->len)
    3828           0 :         memmove(&data->val[element], &data->val[element + 1], 
    3829           0 :                 sizeof(data->val[0]) * (data->len - element));
    3830           0 : ptr = realloc(data->val, data->len * sizeof(data->val[0]));
    3831           0 : if (ptr != NULL || data->len == 0) data->val = ptr;
    3832           0 : return 0;
    3833             : }
    3834             : 
    3835             : int ASN1CALL
    3836           0 : encode_HDB_extension(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_extension *data, size_t *size)
    3837             : {
    3838           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    3839           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    3840           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    3841             : 
    3842             : /* data */
    3843             : {
    3844           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    3845           0 : ret = 0;
    3846             : 
    3847           0 : switch((&(data)->data)->element) {
    3848           0 : case choice_HDB_extension_data_krb5_config: {size_t data_tag_oldret = ret;
    3849           0 : ret = 0;
    3850           0 : e = der_put_octet_string(p, len, &((&(data)->data))->u.krb5_config, &l);
    3851           0 : if (e) return e;
    3852           0 : p -= l; len -= l; ret += l;
    3853             : 
    3854           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
    3855           0 : if (e) return e;
    3856           0 : p -= l; len -= l; ret += l;
    3857             : 
    3858           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 15, &l);
    3859           0 : if (e) return e;
    3860           0 : p -= l; len -= l; ret += l;
    3861             : 
    3862           0 : ret += data_tag_oldret;
    3863           0 : break;
    3864             : }
    3865           0 : case choice_HDB_extension_data_key_rotation: {size_t data_tag_oldret = ret;
    3866           0 : ret = 0;
    3867           0 : e = encode_HDB_Ext_KeyRotation(p, len, &((&(data)->data))->u.key_rotation, &l);
    3868           0 : if (e) return e;
    3869           0 : p -= l; len -= l; ret += l;
    3870             : 
    3871           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 14, &l);
    3872           0 : if (e) return e;
    3873           0 : p -= l; len -= l; ret += l;
    3874             : 
    3875           0 : ret += data_tag_oldret;
    3876           0 : break;
    3877             : }
    3878           0 : case choice_HDB_extension_data_principal_id: {size_t data_tag_oldret = ret;
    3879           0 : ret = 0;
    3880           0 : e = der_put_integer64(p, len, &((&(data)->data))->u.principal_id, &l);
    3881           0 : if (e) return e;
    3882           0 : p -= l; len -= l; ret += l;
    3883             : 
    3884           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3885           0 : if (e) return e;
    3886           0 : p -= l; len -= l; ret += l;
    3887             : 
    3888           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 13, &l);
    3889           0 : if (e) return e;
    3890           0 : p -= l; len -= l; ret += l;
    3891             : 
    3892           0 : ret += data_tag_oldret;
    3893           0 : break;
    3894             : }
    3895           0 : case choice_HDB_extension_data_policy: {size_t data_tag_oldret = ret;
    3896           0 : ret = 0;
    3897           0 : e = der_put_utf8string(p, len, &((&(data)->data))->u.policy, &l);
    3898           0 : if (e) return e;
    3899           0 : p -= l; len -= l; ret += l;
    3900             : 
    3901           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_UTF8String, &l);
    3902           0 : if (e) return e;
    3903           0 : p -= l; len -= l; ret += l;
    3904             : 
    3905           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 12, &l);
    3906           0 : if (e) return e;
    3907           0 : p -= l; len -= l; ret += l;
    3908             : 
    3909           0 : ret += data_tag_oldret;
    3910           0 : break;
    3911             : }
    3912           0 : case choice_HDB_extension_data_hist_kvno_diff_svc: {size_t data_tag_oldret = ret;
    3913           0 : ret = 0;
    3914           0 : e = der_put_unsigned(p, len, &((&(data)->data))->u.hist_kvno_diff_svc, &l);
    3915           0 : if (e) return e;
    3916           0 : p -= l; len -= l; ret += l;
    3917             : 
    3918           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3919           0 : if (e) return e;
    3920           0 : p -= l; len -= l; ret += l;
    3921             : 
    3922           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 11, &l);
    3923           0 : if (e) return e;
    3924           0 : p -= l; len -= l; ret += l;
    3925             : 
    3926           0 : ret += data_tag_oldret;
    3927           0 : break;
    3928             : }
    3929           0 : case choice_HDB_extension_data_hist_kvno_diff_clnt: {size_t data_tag_oldret = ret;
    3930           0 : ret = 0;
    3931           0 : e = der_put_unsigned(p, len, &((&(data)->data))->u.hist_kvno_diff_clnt, &l);
    3932           0 : if (e) return e;
    3933           0 : p -= l; len -= l; ret += l;
    3934             : 
    3935           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    3936           0 : if (e) return e;
    3937           0 : p -= l; len -= l; ret += l;
    3938             : 
    3939           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 10, &l);
    3940           0 : if (e) return e;
    3941           0 : p -= l; len -= l; ret += l;
    3942             : 
    3943           0 : ret += data_tag_oldret;
    3944           0 : break;
    3945             : }
    3946           0 : case choice_HDB_extension_data_hist_keys: {size_t data_tag_oldret = ret;
    3947           0 : ret = 0;
    3948           0 : e = encode_HDB_Ext_KeySet(p, len, &((&(data)->data))->u.hist_keys, &l);
    3949           0 : if (e) return e;
    3950           0 : p -= l; len -= l; ret += l;
    3951             : 
    3952           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 9, &l);
    3953           0 : if (e) return e;
    3954           0 : p -= l; len -= l; ret += l;
    3955             : 
    3956           0 : ret += data_tag_oldret;
    3957           0 : break;
    3958             : }
    3959           0 : case choice_HDB_extension_data_pkinit_cert: {size_t data_tag_oldret = ret;
    3960           0 : ret = 0;
    3961           0 : e = encode_HDB_Ext_PKINIT_cert(p, len, &((&(data)->data))->u.pkinit_cert, &l);
    3962           0 : if (e) return e;
    3963           0 : p -= l; len -= l; ret += l;
    3964             : 
    3965           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 8, &l);
    3966           0 : if (e) return e;
    3967           0 : p -= l; len -= l; ret += l;
    3968             : 
    3969           0 : ret += data_tag_oldret;
    3970           0 : break;
    3971             : }
    3972           0 : case choice_HDB_extension_data_last_pw_change: {size_t data_tag_oldret = ret;
    3973           0 : ret = 0;
    3974           0 : e = encode_KerberosTime(p, len, &((&(data)->data))->u.last_pw_change, &l);
    3975           0 : if (e) return e;
    3976           0 : p -= l; len -= l; ret += l;
    3977             : 
    3978           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 7, &l);
    3979           0 : if (e) return e;
    3980           0 : p -= l; len -= l; ret += l;
    3981             : 
    3982           0 : ret += data_tag_oldret;
    3983           0 : break;
    3984             : }
    3985           0 : case choice_HDB_extension_data_aliases: {size_t data_tag_oldret = ret;
    3986           0 : ret = 0;
    3987           0 : e = encode_HDB_Ext_Aliases(p, len, &((&(data)->data))->u.aliases, &l);
    3988           0 : if (e) return e;
    3989           0 : p -= l; len -= l; ret += l;
    3990             : 
    3991           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 6, &l);
    3992           0 : if (e) return e;
    3993           0 : p -= l; len -= l; ret += l;
    3994             : 
    3995           0 : ret += data_tag_oldret;
    3996           0 : break;
    3997             : }
    3998           0 : case choice_HDB_extension_data_password: {size_t data_tag_oldret = ret;
    3999           0 : ret = 0;
    4000           0 : e = encode_HDB_Ext_Password(p, len, &((&(data)->data))->u.password, &l);
    4001           0 : if (e) return e;
    4002           0 : p -= l; len -= l; ret += l;
    4003             : 
    4004           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 5, &l);
    4005           0 : if (e) return e;
    4006           0 : p -= l; len -= l; ret += l;
    4007             : 
    4008           0 : ret += data_tag_oldret;
    4009           0 : break;
    4010             : }
    4011           0 : case choice_HDB_extension_data_lm_owf: {size_t data_tag_oldret = ret;
    4012           0 : ret = 0;
    4013           0 : e = encode_HDB_Ext_Lan_Manager_OWF(p, len, &((&(data)->data))->u.lm_owf, &l);
    4014           0 : if (e) return e;
    4015           0 : p -= l; len -= l; ret += l;
    4016             : 
    4017           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 4, &l);
    4018           0 : if (e) return e;
    4019           0 : p -= l; len -= l; ret += l;
    4020             : 
    4021           0 : ret += data_tag_oldret;
    4022           0 : break;
    4023             : }
    4024           0 : case choice_HDB_extension_data_allowed_to_delegate_to: {size_t data_tag_oldret = ret;
    4025           0 : ret = 0;
    4026           0 : e = encode_HDB_Ext_Constrained_delegation_acl(p, len, &((&(data)->data))->u.allowed_to_delegate_to, &l);
    4027           0 : if (e) return e;
    4028           0 : p -= l; len -= l; ret += l;
    4029             : 
    4030           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    4031           0 : if (e) return e;
    4032           0 : p -= l; len -= l; ret += l;
    4033             : 
    4034           0 : ret += data_tag_oldret;
    4035           0 : break;
    4036             : }
    4037           0 : case choice_HDB_extension_data_pkinit_cert_hash: {size_t data_tag_oldret = ret;
    4038           0 : ret = 0;
    4039           0 : e = encode_HDB_Ext_PKINIT_hash(p, len, &((&(data)->data))->u.pkinit_cert_hash, &l);
    4040           0 : if (e) return e;
    4041           0 : p -= l; len -= l; ret += l;
    4042             : 
    4043           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    4044           0 : if (e) return e;
    4045           0 : p -= l; len -= l; ret += l;
    4046             : 
    4047           0 : ret += data_tag_oldret;
    4048           0 : break;
    4049             : }
    4050           0 : case choice_HDB_extension_data_pkinit_acl: {size_t data_tag_oldret = ret;
    4051           0 : ret = 0;
    4052           0 : e = encode_HDB_Ext_PKINIT_acl(p, len, &((&(data)->data))->u.pkinit_acl, &l);
    4053           0 : if (e) return e;
    4054           0 : p -= l; len -= l; ret += l;
    4055             : 
    4056           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    4057           0 : if (e) return e;
    4058           0 : p -= l; len -= l; ret += l;
    4059             : 
    4060           0 : ret += data_tag_oldret;
    4061           0 : break;
    4062             : }
    4063           0 : case choice_HDB_extension_data_asn1_ellipsis: {
    4064           0 : if (len < (&(data)->data)->u.asn1_ellipsis.length)
    4065           0 : return ASN1_OVERFLOW;
    4066           0 : p -= (&(data)->data)->u.asn1_ellipsis.length;
    4067           0 : ret += (&(data)->data)->u.asn1_ellipsis.length;
    4068           0 : memcpy(p + 1, (&(data)->data)->u.asn1_ellipsis.data, (&(data)->data)->u.asn1_ellipsis.length);
    4069           0 : break;
    4070             : }
    4071           0 : };
    4072           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    4073           0 : if (e) return e;
    4074           0 : p -= l; len -= l; ret += l;
    4075             : 
    4076           0 : ret += Top_tag_oldret;
    4077             : }
    4078             : /* mandatory */
    4079             : {
    4080           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    4081           0 : ret = 0;
    4082           0 : e = der_put_boolean(p, len, &(data)->mandatory, &l);
    4083           0 : if (e) return e;
    4084           0 : p -= l; len -= l; ret += l;
    4085             : 
    4086           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Boolean, &l);
    4087           0 : if (e) return e;
    4088           0 : p -= l; len -= l; ret += l;
    4089             : 
    4090           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    4091           0 : if (e) return e;
    4092           0 : p -= l; len -= l; ret += l;
    4093             : 
    4094           0 : ret += Top_tag_oldret;
    4095             : }
    4096           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    4097           0 : if (e) return e;
    4098           0 : p -= l; len -= l; ret += l;
    4099             : 
    4100           0 : *size = ret;
    4101           0 : return 0;
    4102             : }
    4103             : 
    4104             : int ASN1CALL
    4105           0 : decode_HDB_extension(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_extension *data, size_t *size)
    4106             : {
    4107           0 : size_t ret = 0;
    4108           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    4109           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    4110             : 
    4111           0 : memset(data, 0, sizeof(*data));
    4112             : {
    4113           0 : size_t Top_datalen;
    4114           0 : Der_type Top_type;
    4115           0 : size_t Top_oldlen;
    4116           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    4117           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    4118           0 : if (e) goto fail;
    4119           0 : p += l; len -= l; ret += l;
    4120           0 : Top_oldlen = len;
    4121           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4122           0 : len = Top_datalen;
    4123             : {
    4124           0 : size_t mandatory_datalen;
    4125           0 : Der_type mandatory_type;
    4126           0 : size_t mandatory_oldlen;
    4127           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &mandatory_type, 0, &mandatory_datalen, &l);
    4128           0 : if (e == 0 && mandatory_type != CONS) { e = ASN1_BAD_ID; }
    4129           0 : if (e) goto fail;
    4130           0 : p += l; len -= l; ret += l;
    4131           0 : mandatory_oldlen = len;
    4132           0 : if (mandatory_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4133           0 : len = mandatory_datalen;
    4134             : {
    4135           0 : size_t mandatory_Tag_datalen;
    4136           0 : Der_type mandatory_Tag_type;
    4137           0 : size_t mandatory_Tag_oldlen;
    4138           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &mandatory_Tag_type, UT_Boolean, &mandatory_Tag_datalen, &l);
    4139           0 : if (e == 0 && mandatory_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4140           0 : if (e) goto fail;
    4141           0 : p += l; len -= l; ret += l;
    4142           0 : mandatory_Tag_oldlen = len;
    4143           0 : if (mandatory_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4144           0 : len = mandatory_Tag_datalen;
    4145           0 : e = der_get_boolean(p, len, &(data)->mandatory, &l);
    4146           0 : if(e) goto fail;
    4147           0 : p += l; len -= l; ret += l;
    4148           0 : len = mandatory_Tag_oldlen - mandatory_Tag_datalen;
    4149             : }
    4150           0 : len = mandatory_oldlen - mandatory_datalen;
    4151             : }
    4152             : {
    4153           0 : size_t data_datalen;
    4154           0 : Der_type data_type;
    4155           0 : size_t data_oldlen;
    4156           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &data_type, 1, &data_datalen, &l);
    4157           0 : if (e == 0 && data_type != CONS) { e = ASN1_BAD_ID; }
    4158           0 : if (e) goto fail;
    4159           0 : p += l; len -= l; ret += l;
    4160           0 : data_oldlen = len;
    4161           0 : if (data_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4162           0 : len = data_datalen;
    4163           0 : if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 0, NULL) == 0) {
    4164           0 : (&(data)->data)->element = choice_HDB_extension_data_pkinit_acl;
    4165             : {
    4166           0 : size_t pkinit_acl_datalen;
    4167           0 : Der_type pkinit_acl_type;
    4168           0 : size_t pkinit_acl_oldlen;
    4169           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &pkinit_acl_type, 0, &pkinit_acl_datalen, &l);
    4170           0 : if (e == 0 && pkinit_acl_type != CONS) { e = ASN1_BAD_ID; }
    4171           0 : if (e) goto fail;
    4172           0 : p += l; len -= l; ret += l;
    4173           0 : pkinit_acl_oldlen = len;
    4174           0 : if (pkinit_acl_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4175           0 : len = pkinit_acl_datalen;
    4176           0 : e = decode_HDB_Ext_PKINIT_acl(p, len, &(&(data)->data)->u.pkinit_acl, &l);
    4177           0 : if(e) goto fail;
    4178           0 : p += l; len -= l; ret += l;
    4179           0 : len = pkinit_acl_oldlen - pkinit_acl_datalen;
    4180             : }
    4181             : }
    4182           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 1, NULL) == 0) {
    4183           0 : (&(data)->data)->element = choice_HDB_extension_data_pkinit_cert_hash;
    4184             : {
    4185           0 : size_t pkinit_cert_hash_datalen;
    4186           0 : Der_type pkinit_cert_hash_type;
    4187           0 : size_t pkinit_cert_hash_oldlen;
    4188           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &pkinit_cert_hash_type, 1, &pkinit_cert_hash_datalen, &l);
    4189           0 : if (e == 0 && pkinit_cert_hash_type != CONS) { e = ASN1_BAD_ID; }
    4190           0 : if (e) goto fail;
    4191           0 : p += l; len -= l; ret += l;
    4192           0 : pkinit_cert_hash_oldlen = len;
    4193           0 : if (pkinit_cert_hash_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4194           0 : len = pkinit_cert_hash_datalen;
    4195           0 : e = decode_HDB_Ext_PKINIT_hash(p, len, &(&(data)->data)->u.pkinit_cert_hash, &l);
    4196           0 : if(e) goto fail;
    4197           0 : p += l; len -= l; ret += l;
    4198           0 : len = pkinit_cert_hash_oldlen - pkinit_cert_hash_datalen;
    4199             : }
    4200             : }
    4201           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 2, NULL) == 0) {
    4202           0 : (&(data)->data)->element = choice_HDB_extension_data_allowed_to_delegate_to;
    4203             : {
    4204           0 : size_t allowed_to_delegate_to_datalen;
    4205           0 : Der_type allowed_to_delegate_to_type;
    4206           0 : size_t allowed_to_delegate_to_oldlen;
    4207           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &allowed_to_delegate_to_type, 2, &allowed_to_delegate_to_datalen, &l);
    4208           0 : if (e == 0 && allowed_to_delegate_to_type != CONS) { e = ASN1_BAD_ID; }
    4209           0 : if (e) goto fail;
    4210           0 : p += l; len -= l; ret += l;
    4211           0 : allowed_to_delegate_to_oldlen = len;
    4212           0 : if (allowed_to_delegate_to_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4213           0 : len = allowed_to_delegate_to_datalen;
    4214           0 : e = decode_HDB_Ext_Constrained_delegation_acl(p, len, &(&(data)->data)->u.allowed_to_delegate_to, &l);
    4215           0 : if(e) goto fail;
    4216           0 : p += l; len -= l; ret += l;
    4217           0 : len = allowed_to_delegate_to_oldlen - allowed_to_delegate_to_datalen;
    4218             : }
    4219             : }
    4220           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 4, NULL) == 0) {
    4221           0 : (&(data)->data)->element = choice_HDB_extension_data_lm_owf;
    4222             : {
    4223           0 : size_t lm_owf_datalen;
    4224           0 : Der_type lm_owf_type;
    4225           0 : size_t lm_owf_oldlen;
    4226           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &lm_owf_type, 4, &lm_owf_datalen, &l);
    4227           0 : if (e == 0 && lm_owf_type != CONS) { e = ASN1_BAD_ID; }
    4228           0 : if (e) goto fail;
    4229           0 : p += l; len -= l; ret += l;
    4230           0 : lm_owf_oldlen = len;
    4231           0 : if (lm_owf_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4232           0 : len = lm_owf_datalen;
    4233           0 : e = decode_HDB_Ext_Lan_Manager_OWF(p, len, &(&(data)->data)->u.lm_owf, &l);
    4234           0 : if(e) goto fail;
    4235           0 : p += l; len -= l; ret += l;
    4236           0 : len = lm_owf_oldlen - lm_owf_datalen;
    4237             : }
    4238             : }
    4239           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 5, NULL) == 0) {
    4240           0 : (&(data)->data)->element = choice_HDB_extension_data_password;
    4241             : {
    4242           0 : size_t password_datalen;
    4243           0 : Der_type password_type;
    4244           0 : size_t password_oldlen;
    4245           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &password_type, 5, &password_datalen, &l);
    4246           0 : if (e == 0 && password_type != CONS) { e = ASN1_BAD_ID; }
    4247           0 : if (e) goto fail;
    4248           0 : p += l; len -= l; ret += l;
    4249           0 : password_oldlen = len;
    4250           0 : if (password_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4251           0 : len = password_datalen;
    4252           0 : e = decode_HDB_Ext_Password(p, len, &(&(data)->data)->u.password, &l);
    4253           0 : if(e) goto fail;
    4254           0 : p += l; len -= l; ret += l;
    4255           0 : len = password_oldlen - password_datalen;
    4256             : }
    4257             : }
    4258           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 6, NULL) == 0) {
    4259           0 : (&(data)->data)->element = choice_HDB_extension_data_aliases;
    4260             : {
    4261           0 : size_t aliases_datalen;
    4262           0 : Der_type aliases_type;
    4263           0 : size_t aliases_oldlen;
    4264           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &aliases_type, 6, &aliases_datalen, &l);
    4265           0 : if (e == 0 && aliases_type != CONS) { e = ASN1_BAD_ID; }
    4266           0 : if (e) goto fail;
    4267           0 : p += l; len -= l; ret += l;
    4268           0 : aliases_oldlen = len;
    4269           0 : if (aliases_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4270           0 : len = aliases_datalen;
    4271           0 : e = decode_HDB_Ext_Aliases(p, len, &(&(data)->data)->u.aliases, &l);
    4272           0 : if(e) goto fail;
    4273           0 : p += l; len -= l; ret += l;
    4274           0 : len = aliases_oldlen - aliases_datalen;
    4275             : }
    4276             : }
    4277           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 7, NULL) == 0) {
    4278           0 : (&(data)->data)->element = choice_HDB_extension_data_last_pw_change;
    4279             : {
    4280           0 : size_t last_pw_change_datalen;
    4281           0 : Der_type last_pw_change_type;
    4282           0 : size_t last_pw_change_oldlen;
    4283           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &last_pw_change_type, 7, &last_pw_change_datalen, &l);
    4284           0 : if (e == 0 && last_pw_change_type != CONS) { e = ASN1_BAD_ID; }
    4285           0 : if (e) goto fail;
    4286           0 : p += l; len -= l; ret += l;
    4287           0 : last_pw_change_oldlen = len;
    4288           0 : if (last_pw_change_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4289           0 : len = last_pw_change_datalen;
    4290           0 : e = decode_KerberosTime(p, len, &(&(data)->data)->u.last_pw_change, &l);
    4291           0 : if(e) goto fail;
    4292           0 : p += l; len -= l; ret += l;
    4293           0 : len = last_pw_change_oldlen - last_pw_change_datalen;
    4294             : }
    4295             : }
    4296           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 8, NULL) == 0) {
    4297           0 : (&(data)->data)->element = choice_HDB_extension_data_pkinit_cert;
    4298             : {
    4299           0 : size_t pkinit_cert_datalen;
    4300           0 : Der_type pkinit_cert_type;
    4301           0 : size_t pkinit_cert_oldlen;
    4302           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &pkinit_cert_type, 8, &pkinit_cert_datalen, &l);
    4303           0 : if (e == 0 && pkinit_cert_type != CONS) { e = ASN1_BAD_ID; }
    4304           0 : if (e) goto fail;
    4305           0 : p += l; len -= l; ret += l;
    4306           0 : pkinit_cert_oldlen = len;
    4307           0 : if (pkinit_cert_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4308           0 : len = pkinit_cert_datalen;
    4309           0 : e = decode_HDB_Ext_PKINIT_cert(p, len, &(&(data)->data)->u.pkinit_cert, &l);
    4310           0 : if(e) goto fail;
    4311           0 : p += l; len -= l; ret += l;
    4312           0 : len = pkinit_cert_oldlen - pkinit_cert_datalen;
    4313             : }
    4314             : }
    4315           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 9, NULL) == 0) {
    4316           0 : (&(data)->data)->element = choice_HDB_extension_data_hist_keys;
    4317             : {
    4318           0 : size_t hist_keys_datalen;
    4319           0 : Der_type hist_keys_type;
    4320           0 : size_t hist_keys_oldlen;
    4321           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &hist_keys_type, 9, &hist_keys_datalen, &l);
    4322           0 : if (e == 0 && hist_keys_type != CONS) { e = ASN1_BAD_ID; }
    4323           0 : if (e) goto fail;
    4324           0 : p += l; len -= l; ret += l;
    4325           0 : hist_keys_oldlen = len;
    4326           0 : if (hist_keys_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4327           0 : len = hist_keys_datalen;
    4328           0 : e = decode_HDB_Ext_KeySet(p, len, &(&(data)->data)->u.hist_keys, &l);
    4329           0 : if(e) goto fail;
    4330           0 : p += l; len -= l; ret += l;
    4331           0 : len = hist_keys_oldlen - hist_keys_datalen;
    4332             : }
    4333             : }
    4334           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 10, NULL) == 0) {
    4335           0 : (&(data)->data)->element = choice_HDB_extension_data_hist_kvno_diff_clnt;
    4336             : {
    4337           0 : size_t hist_kvno_diff_clnt_datalen;
    4338           0 : Der_type hist_kvno_diff_clnt_type;
    4339           0 : size_t hist_kvno_diff_clnt_oldlen;
    4340           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &hist_kvno_diff_clnt_type, 10, &hist_kvno_diff_clnt_datalen, &l);
    4341           0 : if (e == 0 && hist_kvno_diff_clnt_type != CONS) { e = ASN1_BAD_ID; }
    4342           0 : if (e) goto fail;
    4343           0 : p += l; len -= l; ret += l;
    4344           0 : hist_kvno_diff_clnt_oldlen = len;
    4345           0 : if (hist_kvno_diff_clnt_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4346           0 : len = hist_kvno_diff_clnt_datalen;
    4347             : {
    4348           0 : size_t hist_kvno_diff_clnt_Tag_datalen;
    4349           0 : Der_type hist_kvno_diff_clnt_Tag_type;
    4350           0 : size_t hist_kvno_diff_clnt_Tag_oldlen;
    4351           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &hist_kvno_diff_clnt_Tag_type, UT_Integer, &hist_kvno_diff_clnt_Tag_datalen, &l);
    4352           0 : if (e == 0 && hist_kvno_diff_clnt_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4353           0 : if (e) goto fail;
    4354           0 : p += l; len -= l; ret += l;
    4355           0 : hist_kvno_diff_clnt_Tag_oldlen = len;
    4356           0 : if (hist_kvno_diff_clnt_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4357           0 : len = hist_kvno_diff_clnt_Tag_datalen;
    4358           0 : e = der_get_unsigned(p, len, &(&(data)->data)->u.hist_kvno_diff_clnt, &l);
    4359           0 : if(e) goto fail;
    4360           0 : p += l; len -= l; ret += l;
    4361           0 : len = hist_kvno_diff_clnt_Tag_oldlen - hist_kvno_diff_clnt_Tag_datalen;
    4362             : }
    4363           0 : len = hist_kvno_diff_clnt_oldlen - hist_kvno_diff_clnt_datalen;
    4364             : }
    4365             : }
    4366           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 11, NULL) == 0) {
    4367           0 : (&(data)->data)->element = choice_HDB_extension_data_hist_kvno_diff_svc;
    4368             : {
    4369           0 : size_t hist_kvno_diff_svc_datalen;
    4370           0 : Der_type hist_kvno_diff_svc_type;
    4371           0 : size_t hist_kvno_diff_svc_oldlen;
    4372           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &hist_kvno_diff_svc_type, 11, &hist_kvno_diff_svc_datalen, &l);
    4373           0 : if (e == 0 && hist_kvno_diff_svc_type != CONS) { e = ASN1_BAD_ID; }
    4374           0 : if (e) goto fail;
    4375           0 : p += l; len -= l; ret += l;
    4376           0 : hist_kvno_diff_svc_oldlen = len;
    4377           0 : if (hist_kvno_diff_svc_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4378           0 : len = hist_kvno_diff_svc_datalen;
    4379             : {
    4380           0 : size_t hist_kvno_diff_svc_Tag_datalen;
    4381           0 : Der_type hist_kvno_diff_svc_Tag_type;
    4382           0 : size_t hist_kvno_diff_svc_Tag_oldlen;
    4383           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &hist_kvno_diff_svc_Tag_type, UT_Integer, &hist_kvno_diff_svc_Tag_datalen, &l);
    4384           0 : if (e == 0 && hist_kvno_diff_svc_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4385           0 : if (e) goto fail;
    4386           0 : p += l; len -= l; ret += l;
    4387           0 : hist_kvno_diff_svc_Tag_oldlen = len;
    4388           0 : if (hist_kvno_diff_svc_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4389           0 : len = hist_kvno_diff_svc_Tag_datalen;
    4390           0 : e = der_get_unsigned(p, len, &(&(data)->data)->u.hist_kvno_diff_svc, &l);
    4391           0 : if(e) goto fail;
    4392           0 : p += l; len -= l; ret += l;
    4393           0 : len = hist_kvno_diff_svc_Tag_oldlen - hist_kvno_diff_svc_Tag_datalen;
    4394             : }
    4395           0 : len = hist_kvno_diff_svc_oldlen - hist_kvno_diff_svc_datalen;
    4396             : }
    4397             : }
    4398           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 12, NULL) == 0) {
    4399           0 : (&(data)->data)->element = choice_HDB_extension_data_policy;
    4400             : {
    4401           0 : size_t policy_datalen;
    4402           0 : Der_type policy_type;
    4403           0 : size_t policy_oldlen;
    4404           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &policy_type, 12, &policy_datalen, &l);
    4405           0 : if (e == 0 && policy_type != CONS) { e = ASN1_BAD_ID; }
    4406           0 : if (e) goto fail;
    4407           0 : p += l; len -= l; ret += l;
    4408           0 : policy_oldlen = len;
    4409           0 : if (policy_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4410           0 : len = policy_datalen;
    4411             : {
    4412           0 : size_t policy_Tag_datalen;
    4413           0 : Der_type policy_Tag_type;
    4414           0 : size_t policy_Tag_oldlen;
    4415           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &policy_Tag_type, UT_UTF8String, &policy_Tag_datalen, &l);
    4416           0 : if (e == 0 && policy_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4417           0 : if (e) goto fail;
    4418           0 : p += l; len -= l; ret += l;
    4419           0 : policy_Tag_oldlen = len;
    4420           0 : if (policy_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4421           0 : len = policy_Tag_datalen;
    4422           0 : e = der_get_utf8string(p, len, &(&(data)->data)->u.policy, &l);
    4423           0 : if(e) goto fail;
    4424           0 : p += l; len -= l; ret += l;
    4425           0 : len = policy_Tag_oldlen - policy_Tag_datalen;
    4426             : }
    4427           0 : len = policy_oldlen - policy_datalen;
    4428             : }
    4429             : }
    4430           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 13, NULL) == 0) {
    4431           0 : (&(data)->data)->element = choice_HDB_extension_data_principal_id;
    4432             : {
    4433           0 : size_t principal_id_datalen;
    4434           0 : Der_type principal_id_type;
    4435           0 : size_t principal_id_oldlen;
    4436           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &principal_id_type, 13, &principal_id_datalen, &l);
    4437           0 : if (e == 0 && principal_id_type != CONS) { e = ASN1_BAD_ID; }
    4438           0 : if (e) goto fail;
    4439           0 : p += l; len -= l; ret += l;
    4440           0 : principal_id_oldlen = len;
    4441           0 : if (principal_id_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4442           0 : len = principal_id_datalen;
    4443             : {
    4444           0 : size_t principal_id_Tag_datalen;
    4445           0 : Der_type principal_id_Tag_type;
    4446           0 : size_t principal_id_Tag_oldlen;
    4447           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &principal_id_Tag_type, UT_Integer, &principal_id_Tag_datalen, &l);
    4448           0 : if (e == 0 && principal_id_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4449           0 : if (e) goto fail;
    4450           0 : p += l; len -= l; ret += l;
    4451           0 : principal_id_Tag_oldlen = len;
    4452           0 : if (principal_id_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4453           0 : len = principal_id_Tag_datalen;
    4454           0 : e = der_get_integer64(p, len, &(&(data)->data)->u.principal_id, &l);
    4455           0 : if(e) goto fail;
    4456           0 : p += l; len -= l; ret += l;
    4457           0 : len = principal_id_Tag_oldlen - principal_id_Tag_datalen;
    4458             : }
    4459           0 : len = principal_id_oldlen - principal_id_datalen;
    4460             : }
    4461             : }
    4462           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 14, NULL) == 0) {
    4463           0 : (&(data)->data)->element = choice_HDB_extension_data_key_rotation;
    4464             : {
    4465           0 : size_t key_rotation_datalen;
    4466           0 : Der_type key_rotation_type;
    4467           0 : size_t key_rotation_oldlen;
    4468           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &key_rotation_type, 14, &key_rotation_datalen, &l);
    4469           0 : if (e == 0 && key_rotation_type != CONS) { e = ASN1_BAD_ID; }
    4470           0 : if (e) goto fail;
    4471           0 : p += l; len -= l; ret += l;
    4472           0 : key_rotation_oldlen = len;
    4473           0 : if (key_rotation_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4474           0 : len = key_rotation_datalen;
    4475           0 : e = decode_HDB_Ext_KeyRotation(p, len, &(&(data)->data)->u.key_rotation, &l);
    4476           0 : if(e) goto fail;
    4477           0 : p += l; len -= l; ret += l;
    4478           0 : len = key_rotation_oldlen - key_rotation_datalen;
    4479             : }
    4480             : }
    4481           0 : else if (der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 15, NULL) == 0) {
    4482           0 : (&(data)->data)->element = choice_HDB_extension_data_krb5_config;
    4483             : {
    4484           0 : size_t krb5_config_datalen;
    4485           0 : Der_type krb5_config_type;
    4486           0 : size_t krb5_config_oldlen;
    4487           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &krb5_config_type, 15, &krb5_config_datalen, &l);
    4488           0 : if (e == 0 && krb5_config_type != CONS) { e = ASN1_BAD_ID; }
    4489           0 : if (e) goto fail;
    4490           0 : p += l; len -= l; ret += l;
    4491           0 : krb5_config_oldlen = len;
    4492           0 : if (krb5_config_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4493           0 : len = krb5_config_datalen;
    4494             : {
    4495           0 : size_t krb5_config_Tag_datalen;
    4496           0 : Der_type krb5_config_Tag_type;
    4497           0 : size_t krb5_config_Tag_oldlen;
    4498           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &krb5_config_Tag_type, UT_OctetString, &krb5_config_Tag_datalen, &l);
    4499           0 : if (e == 0 && krb5_config_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    4500           0 : if (e) goto fail;
    4501           0 : p += l; len -= l; ret += l;
    4502           0 : krb5_config_Tag_oldlen = len;
    4503           0 : if (krb5_config_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4504           0 : len = krb5_config_Tag_datalen;
    4505           0 : e = der_get_octet_string(p, len, &(&(data)->data)->u.krb5_config, &l);
    4506           0 : if(e) goto fail;
    4507           0 : p += l; len -= l; ret += l;
    4508           0 : len = krb5_config_Tag_oldlen - krb5_config_Tag_datalen;
    4509             : }
    4510           0 : len = krb5_config_oldlen - krb5_config_datalen;
    4511             : }
    4512             : }
    4513             : else {
    4514           0 : (&(data)->data)->element = choice_HDB_extension_data_asn1_ellipsis;
    4515           0 : (&(data)->data)->u.asn1_ellipsis.data = calloc(1, len);
    4516           0 : if ((&(data)->data)->u.asn1_ellipsis.data == NULL) {
    4517           0 : e = ENOMEM; goto fail;
    4518             : }
    4519           0 : (&(data)->data)->u.asn1_ellipsis.length = len;
    4520           0 : memcpy((&(data)->data)->u.asn1_ellipsis.data, p, len);
    4521           0 : p += len;
    4522           0 : ret += len;
    4523           0 : len = 0;
    4524             : }
    4525           0 : len = data_oldlen - data_datalen;
    4526             : }
    4527           0 : len = Top_oldlen - Top_datalen;
    4528             : }
    4529           0 : if(size) *size = ret;
    4530           0 : return 0;
    4531           0 : fail:
    4532           0 : free_HDB_extension(data);
    4533           0 : return e;
    4534             : }
    4535             : 
    4536             : void ASN1CALL
    4537        8593 : free_HDB_extension(HDB_extension *data)
    4538             : {
    4539        8593 : *&(data)->mandatory = 0;
    4540        8593 : switch((&(data)->data)->element) {
    4541           0 : case choice_HDB_extension_data_pkinit_acl:
    4542           0 : free_HDB_Ext_PKINIT_acl(&(&(data)->data)->u.pkinit_acl);
    4543           0 : break;
    4544           0 : case choice_HDB_extension_data_pkinit_cert_hash:
    4545           0 : free_HDB_Ext_PKINIT_hash(&(&(data)->data)->u.pkinit_cert_hash);
    4546           0 : break;
    4547           0 : case choice_HDB_extension_data_allowed_to_delegate_to:
    4548           0 : free_HDB_Ext_Constrained_delegation_acl(&(&(data)->data)->u.allowed_to_delegate_to);
    4549           0 : break;
    4550           0 : case choice_HDB_extension_data_lm_owf:
    4551           0 : free_HDB_Ext_Lan_Manager_OWF(&(&(data)->data)->u.lm_owf);
    4552           0 : break;
    4553           0 : case choice_HDB_extension_data_password:
    4554           0 : free_HDB_Ext_Password(&(&(data)->data)->u.password);
    4555           0 : break;
    4556           0 : case choice_HDB_extension_data_aliases:
    4557           0 : free_HDB_Ext_Aliases(&(&(data)->data)->u.aliases);
    4558           0 : break;
    4559           0 : case choice_HDB_extension_data_last_pw_change:
    4560           0 : free_KerberosTime(&(&(data)->data)->u.last_pw_change);
    4561           0 : break;
    4562           0 : case choice_HDB_extension_data_pkinit_cert:
    4563           0 : free_HDB_Ext_PKINIT_cert(&(&(data)->data)->u.pkinit_cert);
    4564           0 : break;
    4565        3288 : case choice_HDB_extension_data_hist_keys:
    4566        3288 : free_HDB_Ext_KeySet(&(&(data)->data)->u.hist_keys);
    4567        3288 : break;
    4568           0 : case choice_HDB_extension_data_hist_kvno_diff_clnt:
    4569           0 : *&(&(data)->data)->u.hist_kvno_diff_clnt = 0;
    4570           0 : break;
    4571           0 : case choice_HDB_extension_data_hist_kvno_diff_svc:
    4572           0 : *&(&(data)->data)->u.hist_kvno_diff_svc = 0;
    4573           0 : break;
    4574           0 : case choice_HDB_extension_data_policy:
    4575           0 : der_free_utf8string(&(&(data)->data)->u.policy);
    4576           0 : break;
    4577           0 : case choice_HDB_extension_data_principal_id:
    4578           0 : *&(&(data)->data)->u.principal_id = 0;
    4579           0 : break;
    4580           0 : case choice_HDB_extension_data_key_rotation:
    4581           0 : free_HDB_Ext_KeyRotation(&(&(data)->data)->u.key_rotation);
    4582           0 : break;
    4583           0 : case choice_HDB_extension_data_krb5_config:
    4584           0 : der_free_octet_string(&(&(data)->data)->u.krb5_config);
    4585           0 : break;
    4586        5305 : case choice_HDB_extension_data_asn1_ellipsis:
    4587        5305 : der_free_octet_string(&(&(data)->data)->u.asn1_ellipsis);
    4588        5305 : break;}
    4589        8593 : }
    4590             : 
    4591             : size_t ASN1CALL
    4592           0 : length_HDB_extension(const HDB_extension *data)
    4593             : {
    4594           0 : size_t ret = 0;
    4595             : {
    4596           0 : size_t Top_tag_oldret = ret;
    4597           0 : ret = 0;
    4598           0 : ret += 1;
    4599           0 : ret += 1 + der_length_len (ret);
    4600           0 : ret += 1 + der_length_len (ret);
    4601           0 : ret += Top_tag_oldret;
    4602             : }
    4603             : {
    4604           0 : size_t Top_tag_oldret = ret;
    4605           0 : ret = 0;
    4606           0 : switch((&(data)->data)->element) {
    4607           0 : case choice_HDB_extension_data_pkinit_acl:
    4608             : {
    4609           0 : size_t data_tag_oldret = ret;
    4610           0 : ret = 0;
    4611           0 : ret += length_HDB_Ext_PKINIT_acl(&(&(data)->data)->u.pkinit_acl);
    4612           0 : ret += 1 + der_length_len (ret);
    4613           0 : ret += data_tag_oldret;
    4614             : }
    4615           0 : break;
    4616           0 : case choice_HDB_extension_data_pkinit_cert_hash:
    4617             : {
    4618           0 : size_t data_tag_oldret = ret;
    4619           0 : ret = 0;
    4620           0 : ret += length_HDB_Ext_PKINIT_hash(&(&(data)->data)->u.pkinit_cert_hash);
    4621           0 : ret += 1 + der_length_len (ret);
    4622           0 : ret += data_tag_oldret;
    4623             : }
    4624           0 : break;
    4625           0 : case choice_HDB_extension_data_allowed_to_delegate_to:
    4626             : {
    4627           0 : size_t data_tag_oldret = ret;
    4628           0 : ret = 0;
    4629           0 : ret += length_HDB_Ext_Constrained_delegation_acl(&(&(data)->data)->u.allowed_to_delegate_to);
    4630           0 : ret += 1 + der_length_len (ret);
    4631           0 : ret += data_tag_oldret;
    4632             : }
    4633           0 : break;
    4634           0 : case choice_HDB_extension_data_lm_owf:
    4635             : {
    4636           0 : size_t data_tag_oldret = ret;
    4637           0 : ret = 0;
    4638           0 : ret += length_HDB_Ext_Lan_Manager_OWF(&(&(data)->data)->u.lm_owf);
    4639           0 : ret += 1 + der_length_len (ret);
    4640           0 : ret += data_tag_oldret;
    4641             : }
    4642           0 : break;
    4643           0 : case choice_HDB_extension_data_password:
    4644             : {
    4645           0 : size_t data_tag_oldret = ret;
    4646           0 : ret = 0;
    4647           0 : ret += length_HDB_Ext_Password(&(&(data)->data)->u.password);
    4648           0 : ret += 1 + der_length_len (ret);
    4649           0 : ret += data_tag_oldret;
    4650             : }
    4651           0 : break;
    4652           0 : case choice_HDB_extension_data_aliases:
    4653             : {
    4654           0 : size_t data_tag_oldret = ret;
    4655           0 : ret = 0;
    4656           0 : ret += length_HDB_Ext_Aliases(&(&(data)->data)->u.aliases);
    4657           0 : ret += 1 + der_length_len (ret);
    4658           0 : ret += data_tag_oldret;
    4659             : }
    4660           0 : break;
    4661           0 : case choice_HDB_extension_data_last_pw_change:
    4662             : {
    4663           0 : size_t data_tag_oldret = ret;
    4664           0 : ret = 0;
    4665           0 : ret += length_KerberosTime(&(&(data)->data)->u.last_pw_change);
    4666           0 : ret += 1 + der_length_len (ret);
    4667           0 : ret += data_tag_oldret;
    4668             : }
    4669           0 : break;
    4670           0 : case choice_HDB_extension_data_pkinit_cert:
    4671             : {
    4672           0 : size_t data_tag_oldret = ret;
    4673           0 : ret = 0;
    4674           0 : ret += length_HDB_Ext_PKINIT_cert(&(&(data)->data)->u.pkinit_cert);
    4675           0 : ret += 1 + der_length_len (ret);
    4676           0 : ret += data_tag_oldret;
    4677             : }
    4678           0 : break;
    4679           0 : case choice_HDB_extension_data_hist_keys:
    4680             : {
    4681           0 : size_t data_tag_oldret = ret;
    4682           0 : ret = 0;
    4683           0 : ret += length_HDB_Ext_KeySet(&(&(data)->data)->u.hist_keys);
    4684           0 : ret += 1 + der_length_len (ret);
    4685           0 : ret += data_tag_oldret;
    4686             : }
    4687           0 : break;
    4688           0 : case choice_HDB_extension_data_hist_kvno_diff_clnt:
    4689             : {
    4690           0 : size_t data_tag_oldret = ret;
    4691           0 : ret = 0;
    4692           0 : ret += der_length_unsigned(&(&(data)->data)->u.hist_kvno_diff_clnt);
    4693           0 : ret += 1 + der_length_len (ret);
    4694           0 : ret += 1 + der_length_len (ret);
    4695           0 : ret += data_tag_oldret;
    4696             : }
    4697           0 : break;
    4698           0 : case choice_HDB_extension_data_hist_kvno_diff_svc:
    4699             : {
    4700           0 : size_t data_tag_oldret = ret;
    4701           0 : ret = 0;
    4702           0 : ret += der_length_unsigned(&(&(data)->data)->u.hist_kvno_diff_svc);
    4703           0 : ret += 1 + der_length_len (ret);
    4704           0 : ret += 1 + der_length_len (ret);
    4705           0 : ret += data_tag_oldret;
    4706             : }
    4707           0 : break;
    4708           0 : case choice_HDB_extension_data_policy:
    4709             : {
    4710           0 : size_t data_tag_oldret = ret;
    4711           0 : ret = 0;
    4712           0 : ret += der_length_utf8string(&(&(data)->data)->u.policy);
    4713           0 : ret += 1 + der_length_len (ret);
    4714           0 : ret += 1 + der_length_len (ret);
    4715           0 : ret += data_tag_oldret;
    4716             : }
    4717           0 : break;
    4718           0 : case choice_HDB_extension_data_principal_id:
    4719             : {
    4720           0 : size_t data_tag_oldret = ret;
    4721           0 : ret = 0;
    4722           0 : ret += der_length_integer64(&(&(data)->data)->u.principal_id);
    4723           0 : ret += 1 + der_length_len (ret);
    4724           0 : ret += 1 + der_length_len (ret);
    4725           0 : ret += data_tag_oldret;
    4726             : }
    4727           0 : break;
    4728           0 : case choice_HDB_extension_data_key_rotation:
    4729             : {
    4730           0 : size_t data_tag_oldret = ret;
    4731           0 : ret = 0;
    4732           0 : ret += length_HDB_Ext_KeyRotation(&(&(data)->data)->u.key_rotation);
    4733           0 : ret += 1 + der_length_len (ret);
    4734           0 : ret += data_tag_oldret;
    4735             : }
    4736           0 : break;
    4737           0 : case choice_HDB_extension_data_krb5_config:
    4738             : {
    4739           0 : size_t data_tag_oldret = ret;
    4740           0 : ret = 0;
    4741           0 : ret += der_length_octet_string(&(&(data)->data)->u.krb5_config);
    4742           0 : ret += 1 + der_length_len (ret);
    4743           0 : ret += 1 + der_length_len (ret);
    4744           0 : ret += data_tag_oldret;
    4745             : }
    4746           0 : break;
    4747           0 : case choice_HDB_extension_data_asn1_ellipsis:
    4748           0 : ret += (&(data)->data)->u.asn1_ellipsis.length;
    4749           0 : break;
    4750             : }
    4751           0 : ret += 1 + der_length_len (ret);
    4752           0 : ret += Top_tag_oldret;
    4753             : }
    4754           0 : ret += 1 + der_length_len (ret);
    4755           0 : return ret;
    4756             : }
    4757             : 
    4758             : int ASN1CALL
    4759        1645 : copy_HDB_extension(const HDB_extension *from, HDB_extension *to)
    4760             : {
    4761        1645 : memset(to, 0, sizeof(*to));
    4762        1645 : *(&(to)->mandatory) = *(&(from)->mandatory);
    4763        1645 : (&(to)->data)->element = (&(from)->data)->element;
    4764        1645 : switch((&(from)->data)->element) {
    4765           0 : case choice_HDB_extension_data_pkinit_acl:
    4766           0 : if(copy_HDB_Ext_PKINIT_acl(&(&(from)->data)->u.pkinit_acl, &(&(to)->data)->u.pkinit_acl)) goto fail;
    4767           0 : break;
    4768           0 : case choice_HDB_extension_data_pkinit_cert_hash:
    4769           0 : if(copy_HDB_Ext_PKINIT_hash(&(&(from)->data)->u.pkinit_cert_hash, &(&(to)->data)->u.pkinit_cert_hash)) goto fail;
    4770           0 : break;
    4771           0 : case choice_HDB_extension_data_allowed_to_delegate_to:
    4772           0 : if(copy_HDB_Ext_Constrained_delegation_acl(&(&(from)->data)->u.allowed_to_delegate_to, &(&(to)->data)->u.allowed_to_delegate_to)) goto fail;
    4773           0 : break;
    4774           0 : case choice_HDB_extension_data_lm_owf:
    4775           0 : if(copy_HDB_Ext_Lan_Manager_OWF(&(&(from)->data)->u.lm_owf, &(&(to)->data)->u.lm_owf)) goto fail;
    4776           0 : break;
    4777           0 : case choice_HDB_extension_data_password:
    4778           0 : if(copy_HDB_Ext_Password(&(&(from)->data)->u.password, &(&(to)->data)->u.password)) goto fail;
    4779           0 : break;
    4780           0 : case choice_HDB_extension_data_aliases:
    4781           0 : if(copy_HDB_Ext_Aliases(&(&(from)->data)->u.aliases, &(&(to)->data)->u.aliases)) goto fail;
    4782           0 : break;
    4783           0 : case choice_HDB_extension_data_last_pw_change:
    4784           0 : if(copy_KerberosTime(&(&(from)->data)->u.last_pw_change, &(&(to)->data)->u.last_pw_change)) goto fail;
    4785           0 : break;
    4786           0 : case choice_HDB_extension_data_pkinit_cert:
    4787           0 : if(copy_HDB_Ext_PKINIT_cert(&(&(from)->data)->u.pkinit_cert, &(&(to)->data)->u.pkinit_cert)) goto fail;
    4788           0 : break;
    4789        1645 : case choice_HDB_extension_data_hist_keys:
    4790        1645 : if(copy_HDB_Ext_KeySet(&(&(from)->data)->u.hist_keys, &(&(to)->data)->u.hist_keys)) goto fail;
    4791        1627 : break;
    4792           0 : case choice_HDB_extension_data_hist_kvno_diff_clnt:
    4793           0 : *(&(&(to)->data)->u.hist_kvno_diff_clnt) = *(&(&(from)->data)->u.hist_kvno_diff_clnt);
    4794           0 : break;
    4795           0 : case choice_HDB_extension_data_hist_kvno_diff_svc:
    4796           0 : *(&(&(to)->data)->u.hist_kvno_diff_svc) = *(&(&(from)->data)->u.hist_kvno_diff_svc);
    4797           0 : break;
    4798           0 : case choice_HDB_extension_data_policy:
    4799           0 : if(der_copy_utf8string(&(&(from)->data)->u.policy, &(&(to)->data)->u.policy)) goto fail;
    4800           0 : break;
    4801           0 : case choice_HDB_extension_data_principal_id:
    4802           0 : *(&(&(to)->data)->u.principal_id) = *(&(&(from)->data)->u.principal_id);
    4803           0 : break;
    4804           0 : case choice_HDB_extension_data_key_rotation:
    4805           0 : if(copy_HDB_Ext_KeyRotation(&(&(from)->data)->u.key_rotation, &(&(to)->data)->u.key_rotation)) goto fail;
    4806           0 : break;
    4807           0 : case choice_HDB_extension_data_krb5_config:
    4808           0 : if(der_copy_octet_string(&(&(from)->data)->u.krb5_config, &(&(to)->data)->u.krb5_config)) goto fail;
    4809           0 : break;
    4810           0 : case choice_HDB_extension_data_asn1_ellipsis: {
    4811           0 : int ret;
    4812           0 : ret=der_copy_octet_string(&(&(from)->data)->u.asn1_ellipsis, &(&(to)->data)->u.asn1_ellipsis);
    4813           0 : if (ret) goto fail;
    4814           0 : break;
    4815             : }
    4816             : }
    4817        1627 : return 0;
    4818           0 : fail:
    4819           0 : free_HDB_extension(to);
    4820           0 : return ENOMEM;
    4821             : }
    4822             : 
    4823             : char * ASN1CALL
    4824           0 : print_HDB_extension(const HDB_extension *data, int flags)
    4825           0 : { errno = EINVAL; return 0; }
    4826             : 
    4827             : int ASN1CALL
    4828           0 : encode_HDB_extensions(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_extensions *data, size_t *size)
    4829             : {
    4830           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    4831           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    4832           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    4833             : 
    4834           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    4835           0 : size_t Top_tag_for_oldret = ret;
    4836           0 : ret = 0;
    4837           0 : e = encode_HDB_extension(p, len, &(data)->val[i], &l);
    4838           0 : if (e) return e;
    4839           0 : p -= l; len -= l; ret += l;
    4840             : 
    4841           0 : ret += Top_tag_for_oldret;
    4842             : }
    4843           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    4844           0 : if (e) return e;
    4845           0 : p -= l; len -= l; ret += l;
    4846             : 
    4847           0 : *size = ret;
    4848           0 : return 0;
    4849             : }
    4850             : 
    4851             : int ASN1CALL
    4852           0 : decode_HDB_extensions(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_extensions *data, size_t *size)
    4853             : {
    4854           0 : size_t ret = 0;
    4855           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    4856           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    4857             : 
    4858           0 : memset(data, 0, sizeof(*data));
    4859             : {
    4860           0 : size_t Top_datalen;
    4861           0 : Der_type Top_type;
    4862           0 : size_t Top_oldlen;
    4863           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    4864           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    4865           0 : if (e) goto fail;
    4866           0 : p += l; len -= l; ret += l;
    4867           0 : Top_oldlen = len;
    4868           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    4869           0 : len = Top_datalen;
    4870             : {
    4871           0 : size_t Top_Tag_origlen = len;
    4872           0 : size_t Top_Tag_oldret = ret;
    4873           0 : size_t Top_Tag_olen = 0;
    4874           0 : void *Top_Tag_tmp;
    4875           0 : ret = 0;
    4876           0 : (data)->len = 0;
    4877           0 : (data)->val = NULL;
    4878           0 : while(ret < Top_Tag_origlen) {
    4879           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    4880           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    4881           0 : Top_Tag_olen = Top_Tag_nlen;
    4882           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    4883           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    4884           0 : (data)->val = Top_Tag_tmp;
    4885           0 : e = decode_HDB_extension(p, len, &(data)->val[(data)->len], &l);
    4886           0 : if(e) goto fail;
    4887           0 : p += l; len -= l; ret += l;
    4888           0 : (data)->len++;
    4889           0 : len = Top_Tag_origlen - ret;
    4890             : }
    4891           0 : ret += Top_Tag_oldret;
    4892             : }
    4893           0 : len = Top_oldlen - Top_datalen;
    4894             : }
    4895           0 : if(size) *size = ret;
    4896           0 : return 0;
    4897           0 : fail:
    4898           0 : free_HDB_extensions(data);
    4899           0 : return e;
    4900             : }
    4901             : 
    4902             : void ASN1CALL
    4903        1643 : free_HDB_extensions(HDB_extensions *data)
    4904             : {
    4905        1643 : if ((data)->val)
    4906        3286 : while((data)->len){
    4907        1643 : free_HDB_extension(&(data)->val[(data)->len-1]);
    4908        1643 : (data)->len--;
    4909           0 : } else (data)->len = 0;
    4910        1643 : free((data)->val);
    4911        1643 : (data)->val = NULL;
    4912        1643 : }
    4913             : 
    4914             : size_t ASN1CALL
    4915           0 : length_HDB_extensions(const HDB_extensions *data)
    4916             : {
    4917           0 : size_t ret = 0;
    4918             : {
    4919           0 : size_t Top_tag_oldret = ret;
    4920           0 : unsigned int n_Top_tag;
    4921           0 : ret = 0;
    4922           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    4923           0 : size_t Top_tag_for_oldret = ret;
    4924           0 : ret = 0;
    4925           0 : ret += length_HDB_extension(&(data)->val[n_Top_tag - 1]);
    4926           0 : ret += Top_tag_for_oldret;
    4927             : }
    4928           0 : ret += Top_tag_oldret;
    4929             : }
    4930           0 : ret += 1 + der_length_len (ret);
    4931           0 : return ret;
    4932             : }
    4933             : 
    4934             : int ASN1CALL
    4935           0 : copy_HDB_extensions(const HDB_extensions *from, HDB_extensions *to)
    4936             : {
    4937           0 : memset(to, 0, sizeof(*to));
    4938           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    4939           0 : goto fail;
    4940           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    4941           0 : if(copy_HDB_extension(&(from)->val[(to)->len], &(to)->val[(to)->len])) goto fail;
    4942             : }
    4943           0 : return 0;
    4944           0 : fail:
    4945           0 : free_HDB_extensions(to);
    4946           0 : return ENOMEM;
    4947             : }
    4948             : 
    4949             : char * ASN1CALL
    4950           0 : print_HDB_extensions(const HDB_extensions *data, int flags)
    4951           0 : { errno = EINVAL; return 0; }
    4952             : 
    4953             : int ASN1CALL
    4954        1645 : add_HDB_extensions(HDB_extensions *data, const HDB_extension *element)
    4955             : {
    4956          18 : int ret;
    4957          18 : void *ptr;
    4958             : 
    4959        1645 : ptr = realloc(data->val, 
    4960        1645 :         (data->len + 1) * sizeof(data->val[0]));
    4961        1645 : if (ptr == NULL) return ENOMEM;
    4962        1645 : data->val = ptr;
    4963             : 
    4964        1645 : ret = copy_HDB_extension(element, &data->val[data->len]);
    4965        1645 : if (ret) return ret;
    4966        1645 : data->len++;
    4967        1645 : return 0;
    4968             : }
    4969             : 
    4970             : int ASN1CALL
    4971           0 : remove_HDB_extensions(HDB_extensions *data, unsigned int element)
    4972             : {
    4973           0 : void *ptr;
    4974             : 
    4975           0 : if (data->len == 0 || element >= data->len)
    4976           0 :         return ASN1_OVERRUN;
    4977           0 : free_HDB_extension(&data->val[element]);
    4978           0 : data->len--;
    4979           0 : if (element < data->len)
    4980           0 :         memmove(&data->val[element], &data->val[element + 1], 
    4981           0 :                 sizeof(data->val[0]) * (data->len - element));
    4982           0 : ptr = realloc(data->val, data->len * sizeof(data->val[0]));
    4983           0 : if (ptr != NULL || data->len == 0) data->val = ptr;
    4984           0 : return 0;
    4985             : }
    4986             : 
    4987             : int ASN1CALL
    4988           0 : encode_HDB_EncTypeList(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_EncTypeList *data, size_t *size)
    4989             : {
    4990           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    4991           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    4992           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    4993             : 
    4994           0 : for(i = (int)(data)->len - 1; i >= 0; --i) {
    4995           0 : size_t Top_tag_for_oldret = ret;
    4996           0 : ret = 0;
    4997           0 : e = der_put_unsigned(p, len, &(data)->val[i], &l);
    4998           0 : if (e) return e;
    4999           0 : p -= l; len -= l; ret += l;
    5000             : 
    5001           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    5002           0 : if (e) return e;
    5003           0 : p -= l; len -= l; ret += l;
    5004             : 
    5005           0 : ret += Top_tag_for_oldret;
    5006             : }
    5007           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    5008           0 : if (e) return e;
    5009           0 : p -= l; len -= l; ret += l;
    5010             : 
    5011           0 : *size = ret;
    5012           0 : return 0;
    5013             : }
    5014             : 
    5015             : int ASN1CALL
    5016           0 : decode_HDB_EncTypeList(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_EncTypeList *data, size_t *size)
    5017             : {
    5018           0 : size_t ret = 0;
    5019           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    5020           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    5021             : 
    5022           0 : memset(data, 0, sizeof(*data));
    5023             : {
    5024           0 : size_t Top_datalen;
    5025           0 : Der_type Top_type;
    5026           0 : size_t Top_oldlen;
    5027           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    5028           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    5029           0 : if (e) goto fail;
    5030           0 : p += l; len -= l; ret += l;
    5031           0 : Top_oldlen = len;
    5032           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5033           0 : len = Top_datalen;
    5034             : {
    5035           0 : size_t Top_Tag_origlen = len;
    5036           0 : size_t Top_Tag_oldret = ret;
    5037           0 : size_t Top_Tag_olen = 0;
    5038           0 : void *Top_Tag_tmp;
    5039           0 : ret = 0;
    5040           0 : (data)->len = 0;
    5041           0 : (data)->val = NULL;
    5042           0 : while(ret < Top_Tag_origlen) {
    5043           0 : size_t Top_Tag_nlen = Top_Tag_olen + sizeof(*((data)->val));
    5044           0 : if (Top_Tag_olen > Top_Tag_nlen) { e = ASN1_OVERFLOW; goto fail; }
    5045           0 : Top_Tag_olen = Top_Tag_nlen;
    5046           0 : Top_Tag_tmp = realloc((data)->val, Top_Tag_olen);
    5047           0 : if (Top_Tag_tmp == NULL) { e = ENOMEM; goto fail; }
    5048           0 : (data)->val = Top_Tag_tmp;
    5049             : {
    5050           0 : size_t Top_Tag_s_of_datalen;
    5051           0 : Der_type Top_Tag_s_of_type;
    5052           0 : size_t Top_Tag_s_of_oldlen;
    5053           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_Tag_s_of_type, UT_Integer, &Top_Tag_s_of_datalen, &l);
    5054           0 : if (e == 0 && Top_Tag_s_of_type != PRIM) { e = ASN1_BAD_ID; }
    5055           0 : if (e) goto fail;
    5056           0 : p += l; len -= l; ret += l;
    5057           0 : Top_Tag_s_of_oldlen = len;
    5058           0 : if (Top_Tag_s_of_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5059           0 : len = Top_Tag_s_of_datalen;
    5060           0 : e = der_get_unsigned(p, len, &(data)->val[(data)->len], &l);
    5061           0 : if(e) goto fail;
    5062           0 : p += l; len -= l; ret += l;
    5063           0 : len = Top_Tag_s_of_oldlen - Top_Tag_s_of_datalen;
    5064             : }
    5065           0 : (data)->len++;
    5066           0 : len = Top_Tag_origlen - ret;
    5067             : }
    5068           0 : ret += Top_Tag_oldret;
    5069             : }
    5070           0 : len = Top_oldlen - Top_datalen;
    5071             : }
    5072           0 : if(size) *size = ret;
    5073           0 : return 0;
    5074           0 : fail:
    5075           0 : free_HDB_EncTypeList(data);
    5076           0 : return e;
    5077             : }
    5078             : 
    5079             : void ASN1CALL
    5080      532149 : free_HDB_EncTypeList(HDB_EncTypeList *data)
    5081             : {
    5082      532149 : if ((data)->val)
    5083     1706389 : while((data)->len){
    5084     1174240 : *&(data)->val[(data)->len-1] = 0;
    5085     1174240 : (data)->len--;
    5086           0 : } else (data)->len = 0;
    5087      532149 : free((data)->val);
    5088      532149 : (data)->val = NULL;
    5089      532149 : }
    5090             : 
    5091             : size_t ASN1CALL
    5092           0 : length_HDB_EncTypeList(const HDB_EncTypeList *data)
    5093             : {
    5094           0 : size_t ret = 0;
    5095             : {
    5096           0 : size_t Top_tag_oldret = ret;
    5097           0 : unsigned int n_Top_tag;
    5098           0 : ret = 0;
    5099           0 : for(n_Top_tag = (data)->len; n_Top_tag > 0; --n_Top_tag){
    5100           0 : size_t Top_tag_for_oldret = ret;
    5101           0 : ret = 0;
    5102           0 : ret += der_length_unsigned(&(data)->val[n_Top_tag - 1]);
    5103           0 : ret += 1 + der_length_len (ret);
    5104           0 : ret += Top_tag_for_oldret;
    5105             : }
    5106           0 : ret += Top_tag_oldret;
    5107             : }
    5108           0 : ret += 1 + der_length_len (ret);
    5109           0 : return ret;
    5110             : }
    5111             : 
    5112             : int ASN1CALL
    5113           0 : copy_HDB_EncTypeList(const HDB_EncTypeList *from, HDB_EncTypeList *to)
    5114             : {
    5115           0 : memset(to, 0, sizeof(*to));
    5116           0 : if(((to)->val = calloc(1, (from)->len * sizeof(*(to)->val))) == NULL && (from)->len != 0)
    5117           0 : goto fail;
    5118           0 : for((to)->len = 0; (to)->len < (from)->len; (to)->len++){
    5119           0 : *(&(to)->val[(to)->len]) = *(&(from)->val[(to)->len]);
    5120             : }
    5121           0 : return 0;
    5122           0 : fail:
    5123           0 : free_HDB_EncTypeList(to);
    5124           0 : return ENOMEM;
    5125             : }
    5126             : 
    5127             : char * ASN1CALL
    5128           0 : print_HDB_EncTypeList(const HDB_EncTypeList *data, int flags)
    5129           0 : { errno = EINVAL; return 0; }
    5130             : 
    5131             : int ASN1CALL
    5132           0 : encode_HDB_entry(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_entry *data, size_t *size)
    5133             : {
    5134           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    5135           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    5136           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    5137             : 
    5138             : /* session-etypes */
    5139           0 : if((data)->session_etypes) {
    5140           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5141           0 : ret = 0;
    5142           0 : e = encode_HDB_EncTypeList(p, len, (data)->session_etypes, &l);
    5143           0 : if (e) return e;
    5144           0 : p -= l; len -= l; ret += l;
    5145             : 
    5146           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 14, &l);
    5147           0 : if (e) return e;
    5148           0 : p -= l; len -= l; ret += l;
    5149             : 
    5150           0 : ret += Top_tag_oldret;
    5151             : }
    5152             : /* extensions */
    5153           0 : if((data)->extensions) {
    5154           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5155           0 : ret = 0;
    5156           0 : e = encode_HDB_extensions(p, len, (data)->extensions, &l);
    5157           0 : if (e) return e;
    5158           0 : p -= l; len -= l; ret += l;
    5159             : 
    5160           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 13, &l);
    5161           0 : if (e) return e;
    5162           0 : p -= l; len -= l; ret += l;
    5163             : 
    5164           0 : ret += Top_tag_oldret;
    5165             : }
    5166             : /* generation */
    5167           0 : if((data)->generation) {
    5168           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5169           0 : ret = 0;
    5170           0 : e = encode_GENERATION(p, len, (data)->generation, &l);
    5171           0 : if (e) return e;
    5172           0 : p -= l; len -= l; ret += l;
    5173             : 
    5174           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 12, &l);
    5175           0 : if (e) return e;
    5176           0 : p -= l; len -= l; ret += l;
    5177             : 
    5178           0 : ret += Top_tag_oldret;
    5179             : }
    5180             : /* etypes */
    5181           0 : if((data)->etypes) {
    5182           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5183           0 : ret = 0;
    5184           0 : e = encode_HDB_EncTypeList(p, len, (data)->etypes, &l);
    5185           0 : if (e) return e;
    5186           0 : p -= l; len -= l; ret += l;
    5187             : 
    5188           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 11, &l);
    5189           0 : if (e) return e;
    5190           0 : p -= l; len -= l; ret += l;
    5191             : 
    5192           0 : ret += Top_tag_oldret;
    5193             : }
    5194             : /* flags */
    5195             : {
    5196           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5197           0 : ret = 0;
    5198           0 : e = encode_HDBFlags(p, len, &(data)->flags, &l);
    5199           0 : if (e) return e;
    5200           0 : p -= l; len -= l; ret += l;
    5201             : 
    5202           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 10, &l);
    5203           0 : if (e) return e;
    5204           0 : p -= l; len -= l; ret += l;
    5205             : 
    5206           0 : ret += Top_tag_oldret;
    5207             : }
    5208             : /* max-renew */
    5209           0 : if((data)->max_renew) {
    5210           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5211           0 : ret = 0;
    5212           0 : e = der_put_integer(p, len, (data)->max_renew, &l);
    5213           0 : if (e) return e;
    5214           0 : p -= l; len -= l; ret += l;
    5215             : 
    5216           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    5217           0 : if (e) return e;
    5218           0 : p -= l; len -= l; ret += l;
    5219             : 
    5220           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 9, &l);
    5221           0 : if (e) return e;
    5222           0 : p -= l; len -= l; ret += l;
    5223             : 
    5224           0 : ret += Top_tag_oldret;
    5225             : }
    5226             : /* max-life */
    5227           0 : if((data)->max_life) {
    5228           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5229           0 : ret = 0;
    5230           0 : e = der_put_integer(p, len, (data)->max_life, &l);
    5231           0 : if (e) return e;
    5232           0 : p -= l; len -= l; ret += l;
    5233             : 
    5234           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    5235           0 : if (e) return e;
    5236           0 : p -= l; len -= l; ret += l;
    5237             : 
    5238           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 8, &l);
    5239           0 : if (e) return e;
    5240           0 : p -= l; len -= l; ret += l;
    5241             : 
    5242           0 : ret += Top_tag_oldret;
    5243             : }
    5244             : /* pw-end */
    5245           0 : if((data)->pw_end) {
    5246           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5247           0 : ret = 0;
    5248           0 : e = encode_KerberosTime(p, len, (data)->pw_end, &l);
    5249           0 : if (e) return e;
    5250           0 : p -= l; len -= l; ret += l;
    5251             : 
    5252           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 7, &l);
    5253           0 : if (e) return e;
    5254           0 : p -= l; len -= l; ret += l;
    5255             : 
    5256           0 : ret += Top_tag_oldret;
    5257             : }
    5258             : /* valid-end */
    5259           0 : if((data)->valid_end) {
    5260           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5261           0 : ret = 0;
    5262           0 : e = encode_KerberosTime(p, len, (data)->valid_end, &l);
    5263           0 : if (e) return e;
    5264           0 : p -= l; len -= l; ret += l;
    5265             : 
    5266           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 6, &l);
    5267           0 : if (e) return e;
    5268           0 : p -= l; len -= l; ret += l;
    5269             : 
    5270           0 : ret += Top_tag_oldret;
    5271             : }
    5272             : /* valid-start */
    5273           0 : if((data)->valid_start) {
    5274           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5275           0 : ret = 0;
    5276           0 : e = encode_KerberosTime(p, len, (data)->valid_start, &l);
    5277           0 : if (e) return e;
    5278           0 : p -= l; len -= l; ret += l;
    5279             : 
    5280           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 5, &l);
    5281           0 : if (e) return e;
    5282           0 : p -= l; len -= l; ret += l;
    5283             : 
    5284           0 : ret += Top_tag_oldret;
    5285             : }
    5286             : /* modified-by */
    5287           0 : if((data)->modified_by) {
    5288           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5289           0 : ret = 0;
    5290           0 : e = encode_Event(p, len, (data)->modified_by, &l);
    5291           0 : if (e) return e;
    5292           0 : p -= l; len -= l; ret += l;
    5293             : 
    5294           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 4, &l);
    5295           0 : if (e) return e;
    5296           0 : p -= l; len -= l; ret += l;
    5297             : 
    5298           0 : ret += Top_tag_oldret;
    5299             : }
    5300             : /* created-by */
    5301             : {
    5302           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5303           0 : ret = 0;
    5304           0 : e = encode_Event(p, len, &(data)->created_by, &l);
    5305           0 : if (e) return e;
    5306           0 : p -= l; len -= l; ret += l;
    5307             : 
    5308           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 3, &l);
    5309           0 : if (e) return e;
    5310           0 : p -= l; len -= l; ret += l;
    5311             : 
    5312           0 : ret += Top_tag_oldret;
    5313             : }
    5314             : /* keys */
    5315             : {
    5316           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5317           0 : ret = 0;
    5318           0 : e = encode_Keys(p, len, &(data)->keys, &l);
    5319           0 : if (e) return e;
    5320           0 : p -= l; len -= l; ret += l;
    5321             : 
    5322           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 2, &l);
    5323           0 : if (e) return e;
    5324           0 : p -= l; len -= l; ret += l;
    5325             : 
    5326           0 : ret += Top_tag_oldret;
    5327             : }
    5328             : /* kvno */
    5329             : {
    5330           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5331           0 : ret = 0;
    5332           0 : e = der_put_unsigned(p, len, &(data)->kvno, &l);
    5333           0 : if (e) return e;
    5334           0 : p -= l; len -= l; ret += l;
    5335             : 
    5336           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM, UT_Integer, &l);
    5337           0 : if (e) return e;
    5338           0 : p -= l; len -= l; ret += l;
    5339             : 
    5340           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 1, &l);
    5341           0 : if (e) return e;
    5342           0 : p -= l; len -= l; ret += l;
    5343             : 
    5344           0 : ret += Top_tag_oldret;
    5345             : }
    5346             : /* principal */
    5347           0 : if((data)->principal) {
    5348           0 : size_t Top_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    5349           0 : ret = 0;
    5350           0 : e = encode_Principal(p, len, (data)->principal, &l);
    5351           0 : if (e) return e;
    5352           0 : p -= l; len -= l; ret += l;
    5353             : 
    5354           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    5355           0 : if (e) return e;
    5356           0 : p -= l; len -= l; ret += l;
    5357             : 
    5358           0 : ret += Top_tag_oldret;
    5359             : }
    5360           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    5361           0 : if (e) return e;
    5362           0 : p -= l; len -= l; ret += l;
    5363             : 
    5364           0 : *size = ret;
    5365           0 : return 0;
    5366             : }
    5367             : 
    5368             : int ASN1CALL
    5369           0 : decode_HDB_entry(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_entry *data, size_t *size)
    5370             : {
    5371           0 : size_t ret = 0;
    5372           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    5373           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    5374             : 
    5375           0 : memset(data, 0, sizeof(*data));
    5376             : {
    5377           0 : size_t Top_datalen;
    5378           0 : Der_type Top_type;
    5379           0 : size_t Top_oldlen;
    5380           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_type, UT_Sequence, &Top_datalen, &l);
    5381           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    5382           0 : if (e) goto fail;
    5383           0 : p += l; len -= l; ret += l;
    5384           0 : Top_oldlen = len;
    5385           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5386           0 : len = Top_datalen;
    5387             : {
    5388           0 : size_t principal_datalen;
    5389           0 : Der_type principal_type;
    5390           0 : size_t principal_oldlen;
    5391           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &principal_type, 0, &principal_datalen, &l);
    5392           0 : if (e == 0 && principal_type != CONS) { e = ASN1_BAD_ID; }
    5393           0 : if(e) {
    5394           0 : (data)->principal = NULL;
    5395             : } else {
    5396           0 : (data)->principal = calloc(1, sizeof(*(data)->principal));
    5397           0 : if ((data)->principal == NULL) { e = ENOMEM; goto fail; }
    5398           0 : p += l; len -= l; ret += l;
    5399           0 : principal_oldlen = len;
    5400           0 : if (principal_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5401           0 : len = principal_datalen;
    5402           0 : e = decode_Principal(p, len, (data)->principal, &l);
    5403           0 : if(e) goto fail;
    5404           0 : p += l; len -= l; ret += l;
    5405           0 : len = principal_oldlen - principal_datalen;
    5406             : }
    5407             : }
    5408             : {
    5409           0 : size_t kvno_datalen;
    5410           0 : Der_type kvno_type;
    5411           0 : size_t kvno_oldlen;
    5412           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &kvno_type, 1, &kvno_datalen, &l);
    5413           0 : if (e == 0 && kvno_type != CONS) { e = ASN1_BAD_ID; }
    5414           0 : if (e) goto fail;
    5415           0 : p += l; len -= l; ret += l;
    5416           0 : kvno_oldlen = len;
    5417           0 : if (kvno_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5418           0 : len = kvno_datalen;
    5419             : {
    5420           0 : size_t kvno_Tag_datalen;
    5421           0 : Der_type kvno_Tag_type;
    5422           0 : size_t kvno_Tag_oldlen;
    5423           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &kvno_Tag_type, UT_Integer, &kvno_Tag_datalen, &l);
    5424           0 : if (e == 0 && kvno_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    5425           0 : if (e) goto fail;
    5426           0 : p += l; len -= l; ret += l;
    5427           0 : kvno_Tag_oldlen = len;
    5428           0 : if (kvno_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5429           0 : len = kvno_Tag_datalen;
    5430           0 : e = der_get_unsigned(p, len, &(data)->kvno, &l);
    5431           0 : if(e) goto fail;
    5432           0 : p += l; len -= l; ret += l;
    5433           0 : len = kvno_Tag_oldlen - kvno_Tag_datalen;
    5434             : }
    5435           0 : len = kvno_oldlen - kvno_datalen;
    5436             : }
    5437             : {
    5438           0 : size_t keys_datalen;
    5439           0 : Der_type keys_type;
    5440           0 : size_t keys_oldlen;
    5441           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &keys_type, 2, &keys_datalen, &l);
    5442           0 : if (e == 0 && keys_type != CONS) { e = ASN1_BAD_ID; }
    5443           0 : if (e) goto fail;
    5444           0 : p += l; len -= l; ret += l;
    5445           0 : keys_oldlen = len;
    5446           0 : if (keys_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5447           0 : len = keys_datalen;
    5448           0 : e = decode_Keys(p, len, &(data)->keys, &l);
    5449           0 : if(e) goto fail;
    5450           0 : p += l; len -= l; ret += l;
    5451           0 : len = keys_oldlen - keys_datalen;
    5452             : }
    5453             : {
    5454           0 : size_t created_by_datalen;
    5455           0 : Der_type created_by_type;
    5456           0 : size_t created_by_oldlen;
    5457           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &created_by_type, 3, &created_by_datalen, &l);
    5458           0 : if (e == 0 && created_by_type != CONS) { e = ASN1_BAD_ID; }
    5459           0 : if (e) goto fail;
    5460           0 : p += l; len -= l; ret += l;
    5461           0 : created_by_oldlen = len;
    5462           0 : if (created_by_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5463           0 : len = created_by_datalen;
    5464           0 : e = decode_Event(p, len, &(data)->created_by, &l);
    5465           0 : if(e) goto fail;
    5466           0 : p += l; len -= l; ret += l;
    5467           0 : len = created_by_oldlen - created_by_datalen;
    5468             : }
    5469             : {
    5470           0 : size_t modified_by_datalen;
    5471           0 : Der_type modified_by_type;
    5472           0 : size_t modified_by_oldlen;
    5473           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &modified_by_type, 4, &modified_by_datalen, &l);
    5474           0 : if (e == 0 && modified_by_type != CONS) { e = ASN1_BAD_ID; }
    5475           0 : if(e) {
    5476           0 : (data)->modified_by = NULL;
    5477             : } else {
    5478           0 : (data)->modified_by = calloc(1, sizeof(*(data)->modified_by));
    5479           0 : if ((data)->modified_by == NULL) { e = ENOMEM; goto fail; }
    5480           0 : p += l; len -= l; ret += l;
    5481           0 : modified_by_oldlen = len;
    5482           0 : if (modified_by_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5483           0 : len = modified_by_datalen;
    5484           0 : e = decode_Event(p, len, (data)->modified_by, &l);
    5485           0 : if(e) goto fail;
    5486           0 : p += l; len -= l; ret += l;
    5487           0 : len = modified_by_oldlen - modified_by_datalen;
    5488             : }
    5489             : }
    5490             : {
    5491           0 : size_t valid_start_datalen;
    5492           0 : Der_type valid_start_type;
    5493           0 : size_t valid_start_oldlen;
    5494           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &valid_start_type, 5, &valid_start_datalen, &l);
    5495           0 : if (e == 0 && valid_start_type != CONS) { e = ASN1_BAD_ID; }
    5496           0 : if(e) {
    5497           0 : (data)->valid_start = NULL;
    5498             : } else {
    5499           0 : (data)->valid_start = calloc(1, sizeof(*(data)->valid_start));
    5500           0 : if ((data)->valid_start == NULL) { e = ENOMEM; goto fail; }
    5501           0 : p += l; len -= l; ret += l;
    5502           0 : valid_start_oldlen = len;
    5503           0 : if (valid_start_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5504           0 : len = valid_start_datalen;
    5505           0 : e = decode_KerberosTime(p, len, (data)->valid_start, &l);
    5506           0 : if(e) goto fail;
    5507           0 : p += l; len -= l; ret += l;
    5508           0 : len = valid_start_oldlen - valid_start_datalen;
    5509             : }
    5510             : }
    5511             : {
    5512           0 : size_t valid_end_datalen;
    5513           0 : Der_type valid_end_type;
    5514           0 : size_t valid_end_oldlen;
    5515           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &valid_end_type, 6, &valid_end_datalen, &l);
    5516           0 : if (e == 0 && valid_end_type != CONS) { e = ASN1_BAD_ID; }
    5517           0 : if(e) {
    5518           0 : (data)->valid_end = NULL;
    5519             : } else {
    5520           0 : (data)->valid_end = calloc(1, sizeof(*(data)->valid_end));
    5521           0 : if ((data)->valid_end == NULL) { e = ENOMEM; goto fail; }
    5522           0 : p += l; len -= l; ret += l;
    5523           0 : valid_end_oldlen = len;
    5524           0 : if (valid_end_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5525           0 : len = valid_end_datalen;
    5526           0 : e = decode_KerberosTime(p, len, (data)->valid_end, &l);
    5527           0 : if(e) goto fail;
    5528           0 : p += l; len -= l; ret += l;
    5529           0 : len = valid_end_oldlen - valid_end_datalen;
    5530             : }
    5531             : }
    5532             : {
    5533           0 : size_t pw_end_datalen;
    5534           0 : Der_type pw_end_type;
    5535           0 : size_t pw_end_oldlen;
    5536           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &pw_end_type, 7, &pw_end_datalen, &l);
    5537           0 : if (e == 0 && pw_end_type != CONS) { e = ASN1_BAD_ID; }
    5538           0 : if(e) {
    5539           0 : (data)->pw_end = NULL;
    5540             : } else {
    5541           0 : (data)->pw_end = calloc(1, sizeof(*(data)->pw_end));
    5542           0 : if ((data)->pw_end == NULL) { e = ENOMEM; goto fail; }
    5543           0 : p += l; len -= l; ret += l;
    5544           0 : pw_end_oldlen = len;
    5545           0 : if (pw_end_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5546           0 : len = pw_end_datalen;
    5547           0 : e = decode_KerberosTime(p, len, (data)->pw_end, &l);
    5548           0 : if(e) goto fail;
    5549           0 : p += l; len -= l; ret += l;
    5550           0 : len = pw_end_oldlen - pw_end_datalen;
    5551             : }
    5552             : }
    5553             : {
    5554           0 : size_t max_life_datalen;
    5555           0 : Der_type max_life_type;
    5556           0 : size_t max_life_oldlen;
    5557           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &max_life_type, 8, &max_life_datalen, &l);
    5558           0 : if (e == 0 && max_life_type != CONS) { e = ASN1_BAD_ID; }
    5559           0 : if(e) {
    5560           0 : (data)->max_life = NULL;
    5561             : } else {
    5562           0 : (data)->max_life = calloc(1, sizeof(*(data)->max_life));
    5563           0 : if ((data)->max_life == NULL) { e = ENOMEM; goto fail; }
    5564           0 : p += l; len -= l; ret += l;
    5565           0 : max_life_oldlen = len;
    5566           0 : if (max_life_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5567           0 : len = max_life_datalen;
    5568             : {
    5569           0 : size_t max_life_Tag_datalen;
    5570           0 : Der_type max_life_Tag_type;
    5571           0 : size_t max_life_Tag_oldlen;
    5572           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &max_life_Tag_type, UT_Integer, &max_life_Tag_datalen, &l);
    5573           0 : if (e == 0 && max_life_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    5574           0 : if (e) goto fail;
    5575           0 : p += l; len -= l; ret += l;
    5576           0 : max_life_Tag_oldlen = len;
    5577           0 : if (max_life_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5578           0 : len = max_life_Tag_datalen;
    5579           0 : e = der_get_integer(p, len, (data)->max_life, &l);
    5580           0 : if(e) goto fail;
    5581           0 : p += l; len -= l; ret += l;
    5582           0 : len = max_life_Tag_oldlen - max_life_Tag_datalen;
    5583             : }
    5584           0 : len = max_life_oldlen - max_life_datalen;
    5585             : }
    5586             : }
    5587             : {
    5588           0 : size_t max_renew_datalen;
    5589           0 : Der_type max_renew_type;
    5590           0 : size_t max_renew_oldlen;
    5591           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &max_renew_type, 9, &max_renew_datalen, &l);
    5592           0 : if (e == 0 && max_renew_type != CONS) { e = ASN1_BAD_ID; }
    5593           0 : if(e) {
    5594           0 : (data)->max_renew = NULL;
    5595             : } else {
    5596           0 : (data)->max_renew = calloc(1, sizeof(*(data)->max_renew));
    5597           0 : if ((data)->max_renew == NULL) { e = ENOMEM; goto fail; }
    5598           0 : p += l; len -= l; ret += l;
    5599           0 : max_renew_oldlen = len;
    5600           0 : if (max_renew_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5601           0 : len = max_renew_datalen;
    5602             : {
    5603           0 : size_t max_renew_Tag_datalen;
    5604           0 : Der_type max_renew_Tag_type;
    5605           0 : size_t max_renew_Tag_oldlen;
    5606           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &max_renew_Tag_type, UT_Integer, &max_renew_Tag_datalen, &l);
    5607           0 : if (e == 0 && max_renew_Tag_type != PRIM) { e = ASN1_BAD_ID; }
    5608           0 : if (e) goto fail;
    5609           0 : p += l; len -= l; ret += l;
    5610           0 : max_renew_Tag_oldlen = len;
    5611           0 : if (max_renew_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5612           0 : len = max_renew_Tag_datalen;
    5613           0 : e = der_get_integer(p, len, (data)->max_renew, &l);
    5614           0 : if(e) goto fail;
    5615           0 : p += l; len -= l; ret += l;
    5616           0 : len = max_renew_Tag_oldlen - max_renew_Tag_datalen;
    5617             : }
    5618           0 : len = max_renew_oldlen - max_renew_datalen;
    5619             : }
    5620             : }
    5621             : {
    5622           0 : size_t flags_datalen;
    5623           0 : Der_type flags_type;
    5624           0 : size_t flags_oldlen;
    5625           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &flags_type, 10, &flags_datalen, &l);
    5626           0 : if (e == 0 && flags_type != CONS) { e = ASN1_BAD_ID; }
    5627           0 : if (e) goto fail;
    5628           0 : p += l; len -= l; ret += l;
    5629           0 : flags_oldlen = len;
    5630           0 : if (flags_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5631           0 : len = flags_datalen;
    5632           0 : e = decode_HDBFlags(p, len, &(data)->flags, &l);
    5633           0 : if(e) goto fail;
    5634           0 : p += l; len -= l; ret += l;
    5635           0 : len = flags_oldlen - flags_datalen;
    5636             : }
    5637             : {
    5638           0 : size_t etypes_datalen;
    5639           0 : Der_type etypes_type;
    5640           0 : size_t etypes_oldlen;
    5641           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &etypes_type, 11, &etypes_datalen, &l);
    5642           0 : if (e == 0 && etypes_type != CONS) { e = ASN1_BAD_ID; }
    5643           0 : if(e) {
    5644           0 : (data)->etypes = NULL;
    5645             : } else {
    5646           0 : (data)->etypes = calloc(1, sizeof(*(data)->etypes));
    5647           0 : if ((data)->etypes == NULL) { e = ENOMEM; goto fail; }
    5648           0 : p += l; len -= l; ret += l;
    5649           0 : etypes_oldlen = len;
    5650           0 : if (etypes_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5651           0 : len = etypes_datalen;
    5652           0 : e = decode_HDB_EncTypeList(p, len, (data)->etypes, &l);
    5653           0 : if(e) goto fail;
    5654           0 : p += l; len -= l; ret += l;
    5655           0 : len = etypes_oldlen - etypes_datalen;
    5656             : }
    5657             : }
    5658             : {
    5659           0 : size_t generation_datalen;
    5660           0 : Der_type generation_type;
    5661           0 : size_t generation_oldlen;
    5662           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &generation_type, 12, &generation_datalen, &l);
    5663           0 : if (e == 0 && generation_type != CONS) { e = ASN1_BAD_ID; }
    5664           0 : if(e) {
    5665           0 : (data)->generation = NULL;
    5666             : } else {
    5667           0 : (data)->generation = calloc(1, sizeof(*(data)->generation));
    5668           0 : if ((data)->generation == NULL) { e = ENOMEM; goto fail; }
    5669           0 : p += l; len -= l; ret += l;
    5670           0 : generation_oldlen = len;
    5671           0 : if (generation_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5672           0 : len = generation_datalen;
    5673           0 : e = decode_GENERATION(p, len, (data)->generation, &l);
    5674           0 : if(e) goto fail;
    5675           0 : p += l; len -= l; ret += l;
    5676           0 : len = generation_oldlen - generation_datalen;
    5677             : }
    5678             : }
    5679             : {
    5680           0 : size_t extensions_datalen;
    5681           0 : Der_type extensions_type;
    5682           0 : size_t extensions_oldlen;
    5683           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &extensions_type, 13, &extensions_datalen, &l);
    5684           0 : if (e == 0 && extensions_type != CONS) { e = ASN1_BAD_ID; }
    5685           0 : if(e) {
    5686           0 : (data)->extensions = NULL;
    5687             : } else {
    5688           0 : (data)->extensions = calloc(1, sizeof(*(data)->extensions));
    5689           0 : if ((data)->extensions == NULL) { e = ENOMEM; goto fail; }
    5690           0 : p += l; len -= l; ret += l;
    5691           0 : extensions_oldlen = len;
    5692           0 : if (extensions_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5693           0 : len = extensions_datalen;
    5694           0 : e = decode_HDB_extensions(p, len, (data)->extensions, &l);
    5695           0 : if(e) goto fail;
    5696           0 : p += l; len -= l; ret += l;
    5697           0 : len = extensions_oldlen - extensions_datalen;
    5698             : }
    5699             : }
    5700             : {
    5701           0 : size_t session_etypes_datalen;
    5702           0 : Der_type session_etypes_type;
    5703           0 : size_t session_etypes_oldlen;
    5704           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &session_etypes_type, 14, &session_etypes_datalen, &l);
    5705           0 : if (e == 0 && session_etypes_type != CONS) { e = ASN1_BAD_ID; }
    5706           0 : if(e) {
    5707           0 : (data)->session_etypes = NULL;
    5708             : } else {
    5709           0 : (data)->session_etypes = calloc(1, sizeof(*(data)->session_etypes));
    5710           0 : if ((data)->session_etypes == NULL) { e = ENOMEM; goto fail; }
    5711           0 : p += l; len -= l; ret += l;
    5712           0 : session_etypes_oldlen = len;
    5713           0 : if (session_etypes_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    5714           0 : len = session_etypes_datalen;
    5715           0 : e = decode_HDB_EncTypeList(p, len, (data)->session_etypes, &l);
    5716           0 : if(e) goto fail;
    5717           0 : p += l; len -= l; ret += l;
    5718           0 : len = session_etypes_oldlen - session_etypes_datalen;
    5719             : }
    5720             : }
    5721           0 : len = Top_oldlen - Top_datalen;
    5722             : }
    5723           0 : if(size) *size = ret;
    5724           0 : return 0;
    5725           0 : fail:
    5726           0 : free_HDB_entry(data);
    5727           0 : return e;
    5728             : }
    5729             : 
    5730             : void ASN1CALL
    5731      313571 : free_HDB_entry(HDB_entry *data)
    5732             : {
    5733      313571 : if((data)->principal) {
    5734      308801 : free_Principal((data)->principal);
    5735      308801 : free((data)->principal);
    5736      308801 : (data)->principal = NULL;
    5737             : }
    5738      313571 : *&(data)->kvno = 0;
    5739      313571 : free_Keys(&(data)->keys);
    5740      313571 : free_Event(&(data)->created_by);
    5741      313571 : if((data)->modified_by) {
    5742           0 : free_Event((data)->modified_by);
    5743           0 : free((data)->modified_by);
    5744           0 : (data)->modified_by = NULL;
    5745             : }
    5746      313571 : if((data)->valid_start) {
    5747           0 : free_KerberosTime((data)->valid_start);
    5748           0 : free((data)->valid_start);
    5749           0 : (data)->valid_start = NULL;
    5750             : }
    5751      313571 : if((data)->valid_end) {
    5752           0 : free_KerberosTime((data)->valid_end);
    5753           0 : free((data)->valid_end);
    5754           0 : (data)->valid_end = NULL;
    5755             : }
    5756      313571 : if((data)->pw_end) {
    5757       82635 : free_KerberosTime((data)->pw_end);
    5758       82635 : free((data)->pw_end);
    5759       82635 : (data)->pw_end = NULL;
    5760             : }
    5761      313571 : if((data)->max_life) {
    5762      305022 : *(data)->max_life = 0;
    5763      305022 : free((data)->max_life);
    5764      305022 : (data)->max_life = NULL;
    5765             : }
    5766      313571 : if((data)->max_renew) {
    5767      305022 : *(data)->max_renew = 0;
    5768      305022 : free((data)->max_renew);
    5769      305022 : (data)->max_renew = NULL;
    5770             : }
    5771      313571 : free_HDBFlags(&(data)->flags);
    5772      313571 : if((data)->etypes) {
    5773      307111 : free_HDB_EncTypeList((data)->etypes);
    5774      307111 : free((data)->etypes);
    5775      307111 : (data)->etypes = NULL;
    5776             : }
    5777      313571 : if((data)->generation) {
    5778           0 : free_GENERATION((data)->generation);
    5779           0 : free((data)->generation);
    5780           0 : (data)->generation = NULL;
    5781             : }
    5782      313571 : if((data)->extensions) {
    5783        1643 : free_HDB_extensions((data)->extensions);
    5784        1643 : free((data)->extensions);
    5785        1643 : (data)->extensions = NULL;
    5786             : }
    5787      313571 : if((data)->session_etypes) {
    5788      225038 : free_HDB_EncTypeList((data)->session_etypes);
    5789      225038 : free((data)->session_etypes);
    5790      225038 : (data)->session_etypes = NULL;
    5791             : }
    5792      313571 : memset(&(data)->context, 0, sizeof((data)->context));
    5793      313571 : memset(&(data)->aliased, 0, sizeof((data)->aliased));
    5794      313571 : }
    5795             : 
    5796             : size_t ASN1CALL
    5797           0 : length_HDB_entry(const HDB_entry *data)
    5798             : {
    5799           0 : size_t ret = 0;
    5800           0 : if((data)->principal){
    5801           0 : size_t Top_tag_oldret = ret;
    5802           0 : ret = 0;
    5803           0 : ret += length_Principal((data)->principal);
    5804           0 : ret += 1 + der_length_len (ret);
    5805           0 : ret += Top_tag_oldret;
    5806             : }
    5807             : {
    5808           0 : size_t Top_tag_oldret = ret;
    5809           0 : ret = 0;
    5810           0 : ret += der_length_unsigned(&(data)->kvno);
    5811           0 : ret += 1 + der_length_len (ret);
    5812           0 : ret += 1 + der_length_len (ret);
    5813           0 : ret += Top_tag_oldret;
    5814             : }
    5815             : {
    5816           0 : size_t Top_tag_oldret = ret;
    5817           0 : ret = 0;
    5818           0 : ret += length_Keys(&(data)->keys);
    5819           0 : ret += 1 + der_length_len (ret);
    5820           0 : ret += Top_tag_oldret;
    5821             : }
    5822             : {
    5823           0 : size_t Top_tag_oldret = ret;
    5824           0 : ret = 0;
    5825           0 : ret += length_Event(&(data)->created_by);
    5826           0 : ret += 1 + der_length_len (ret);
    5827           0 : ret += Top_tag_oldret;
    5828             : }
    5829           0 : if((data)->modified_by){
    5830           0 : size_t Top_tag_oldret = ret;
    5831           0 : ret = 0;
    5832           0 : ret += length_Event((data)->modified_by);
    5833           0 : ret += 1 + der_length_len (ret);
    5834           0 : ret += Top_tag_oldret;
    5835             : }
    5836           0 : if((data)->valid_start){
    5837           0 : size_t Top_tag_oldret = ret;
    5838           0 : ret = 0;
    5839           0 : ret += length_KerberosTime((data)->valid_start);
    5840           0 : ret += 1 + der_length_len (ret);
    5841           0 : ret += Top_tag_oldret;
    5842             : }
    5843           0 : if((data)->valid_end){
    5844           0 : size_t Top_tag_oldret = ret;
    5845           0 : ret = 0;
    5846           0 : ret += length_KerberosTime((data)->valid_end);
    5847           0 : ret += 1 + der_length_len (ret);
    5848           0 : ret += Top_tag_oldret;
    5849             : }
    5850           0 : if((data)->pw_end){
    5851           0 : size_t Top_tag_oldret = ret;
    5852           0 : ret = 0;
    5853           0 : ret += length_KerberosTime((data)->pw_end);
    5854           0 : ret += 1 + der_length_len (ret);
    5855           0 : ret += Top_tag_oldret;
    5856             : }
    5857           0 : if((data)->max_life){
    5858           0 : size_t Top_tag_oldret = ret;
    5859           0 : ret = 0;
    5860           0 : ret += der_length_integer((data)->max_life);
    5861           0 : ret += 1 + der_length_len (ret);
    5862           0 : ret += 1 + der_length_len (ret);
    5863           0 : ret += Top_tag_oldret;
    5864             : }
    5865           0 : if((data)->max_renew){
    5866           0 : size_t Top_tag_oldret = ret;
    5867           0 : ret = 0;
    5868           0 : ret += der_length_integer((data)->max_renew);
    5869           0 : ret += 1 + der_length_len (ret);
    5870           0 : ret += 1 + der_length_len (ret);
    5871           0 : ret += Top_tag_oldret;
    5872             : }
    5873             : {
    5874           0 : size_t Top_tag_oldret = ret;
    5875           0 : ret = 0;
    5876           0 : ret += length_HDBFlags(&(data)->flags);
    5877           0 : ret += 1 + der_length_len (ret);
    5878           0 : ret += Top_tag_oldret;
    5879             : }
    5880           0 : if((data)->etypes){
    5881           0 : size_t Top_tag_oldret = ret;
    5882           0 : ret = 0;
    5883           0 : ret += length_HDB_EncTypeList((data)->etypes);
    5884           0 : ret += 1 + der_length_len (ret);
    5885           0 : ret += Top_tag_oldret;
    5886             : }
    5887           0 : if((data)->generation){
    5888           0 : size_t Top_tag_oldret = ret;
    5889           0 : ret = 0;
    5890           0 : ret += length_GENERATION((data)->generation);
    5891           0 : ret += 1 + der_length_len (ret);
    5892           0 : ret += Top_tag_oldret;
    5893             : }
    5894           0 : if((data)->extensions){
    5895           0 : size_t Top_tag_oldret = ret;
    5896           0 : ret = 0;
    5897           0 : ret += length_HDB_extensions((data)->extensions);
    5898           0 : ret += 1 + der_length_len (ret);
    5899           0 : ret += Top_tag_oldret;
    5900             : }
    5901           0 : if((data)->session_etypes){
    5902           0 : size_t Top_tag_oldret = ret;
    5903           0 : ret = 0;
    5904           0 : ret += length_HDB_EncTypeList((data)->session_etypes);
    5905           0 : ret += 1 + der_length_len (ret);
    5906           0 : ret += Top_tag_oldret;
    5907             : }
    5908           0 : ret += 1 + der_length_len (ret);
    5909           0 : return ret;
    5910             : }
    5911             : 
    5912             : int ASN1CALL
    5913           0 : copy_HDB_entry(const HDB_entry *from, HDB_entry *to)
    5914             : {
    5915           0 : memset(to, 0, sizeof(*to));
    5916           0 : if((from)->principal) {
    5917           0 : (to)->principal = calloc(1, sizeof(*(to)->principal));
    5918           0 : if((to)->principal == NULL) goto fail;
    5919           0 : if(copy_Principal((from)->principal, (to)->principal)) goto fail;
    5920             : }else
    5921           0 : (to)->principal = NULL;
    5922           0 : *(&(to)->kvno) = *(&(from)->kvno);
    5923           0 : if(copy_Keys(&(from)->keys, &(to)->keys)) goto fail;
    5924           0 : if(copy_Event(&(from)->created_by, &(to)->created_by)) goto fail;
    5925           0 : if((from)->modified_by) {
    5926           0 : (to)->modified_by = calloc(1, sizeof(*(to)->modified_by));
    5927           0 : if((to)->modified_by == NULL) goto fail;
    5928           0 : if(copy_Event((from)->modified_by, (to)->modified_by)) goto fail;
    5929             : }else
    5930           0 : (to)->modified_by = NULL;
    5931           0 : if((from)->valid_start) {
    5932           0 : (to)->valid_start = calloc(1, sizeof(*(to)->valid_start));
    5933           0 : if((to)->valid_start == NULL) goto fail;
    5934           0 : if(copy_KerberosTime((from)->valid_start, (to)->valid_start)) goto fail;
    5935             : }else
    5936           0 : (to)->valid_start = NULL;
    5937           0 : if((from)->valid_end) {
    5938           0 : (to)->valid_end = calloc(1, sizeof(*(to)->valid_end));
    5939           0 : if((to)->valid_end == NULL) goto fail;
    5940           0 : if(copy_KerberosTime((from)->valid_end, (to)->valid_end)) goto fail;
    5941             : }else
    5942           0 : (to)->valid_end = NULL;
    5943           0 : if((from)->pw_end) {
    5944           0 : (to)->pw_end = calloc(1, sizeof(*(to)->pw_end));
    5945           0 : if((to)->pw_end == NULL) goto fail;
    5946           0 : if(copy_KerberosTime((from)->pw_end, (to)->pw_end)) goto fail;
    5947             : }else
    5948           0 : (to)->pw_end = NULL;
    5949           0 : if((from)->max_life) {
    5950           0 : (to)->max_life = calloc(1, sizeof(*(to)->max_life));
    5951           0 : if((to)->max_life == NULL) goto fail;
    5952           0 : *((to)->max_life) = *((from)->max_life);
    5953             : }else
    5954           0 : (to)->max_life = NULL;
    5955           0 : if((from)->max_renew) {
    5956           0 : (to)->max_renew = calloc(1, sizeof(*(to)->max_renew));
    5957           0 : if((to)->max_renew == NULL) goto fail;
    5958           0 : *((to)->max_renew) = *((from)->max_renew);
    5959             : }else
    5960           0 : (to)->max_renew = NULL;
    5961           0 : if(copy_HDBFlags(&(from)->flags, &(to)->flags)) goto fail;
    5962           0 : if((from)->etypes) {
    5963           0 : (to)->etypes = calloc(1, sizeof(*(to)->etypes));
    5964           0 : if((to)->etypes == NULL) goto fail;
    5965           0 : if(copy_HDB_EncTypeList((from)->etypes, (to)->etypes)) goto fail;
    5966             : }else
    5967           0 : (to)->etypes = NULL;
    5968           0 : if((from)->generation) {
    5969           0 : (to)->generation = calloc(1, sizeof(*(to)->generation));
    5970           0 : if((to)->generation == NULL) goto fail;
    5971           0 : if(copy_GENERATION((from)->generation, (to)->generation)) goto fail;
    5972             : }else
    5973           0 : (to)->generation = NULL;
    5974           0 : if((from)->extensions) {
    5975           0 : (to)->extensions = calloc(1, sizeof(*(to)->extensions));
    5976           0 : if((to)->extensions == NULL) goto fail;
    5977           0 : if(copy_HDB_extensions((from)->extensions, (to)->extensions)) goto fail;
    5978             : }else
    5979           0 : (to)->extensions = NULL;
    5980           0 : if((from)->session_etypes) {
    5981           0 : (to)->session_etypes = calloc(1, sizeof(*(to)->session_etypes));
    5982           0 : if((to)->session_etypes == NULL) goto fail;
    5983           0 : if(copy_HDB_EncTypeList((from)->session_etypes, (to)->session_etypes)) goto fail;
    5984             : }else
    5985           0 : (to)->session_etypes = NULL;
    5986           0 : memset(&(to)->context, 0, sizeof((to)->context));
    5987           0 : memset(&(to)->aliased, 0, sizeof((to)->aliased));
    5988           0 : return 0;
    5989           0 : fail:
    5990           0 : free_HDB_entry(to);
    5991           0 : return ENOMEM;
    5992             : }
    5993             : 
    5994             : char * ASN1CALL
    5995           0 : print_HDB_entry(const HDB_entry *data, int flags)
    5996           0 : { errno = EINVAL; return 0; }
    5997             : 
    5998             : int ASN1CALL
    5999           0 : encode_HDB_entry_alias(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_entry_alias *data, size_t *size)
    6000             : {
    6001           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    6002           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    6003           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    6004             : 
    6005             : /* principal */
    6006           0 : if((data)->principal) {
    6007           0 : size_t Top_tag_tag_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;
    6008           0 : ret = 0;
    6009           0 : e = encode_Principal(p, len, (data)->principal, &l);
    6010           0 : if (e) return e;
    6011           0 : p -= l; len -= l; ret += l;
    6012             : 
    6013           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, 0, &l);
    6014           0 : if (e) return e;
    6015           0 : p -= l; len -= l; ret += l;
    6016             : 
    6017           0 : ret += Top_tag_tag_oldret;
    6018             : }
    6019           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);
    6020           0 : if (e) return e;
    6021           0 : p -= l; len -= l; ret += l;
    6022             : 
    6023           0 : e = der_put_length_and_tag (p, len, ret, ASN1_C_APPL, CONS, 0, &l);
    6024           0 : if (e) return e;
    6025           0 : p -= l; len -= l; ret += l;
    6026             : 
    6027           0 : *size = ret;
    6028           0 : return 0;
    6029             : }
    6030             : 
    6031             : int ASN1CALL
    6032           0 : decode_HDB_entry_alias(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_entry_alias *data, size_t *size)
    6033             : {
    6034           0 : size_t ret = 0;
    6035           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    6036           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    6037             : 
    6038           0 : memset(data, 0, sizeof(*data));
    6039             : {
    6040           0 : size_t Top_datalen;
    6041           0 : Der_type Top_type;
    6042           0 : size_t Top_oldlen;
    6043           0 : e = der_match_tag_and_length(p, len, ASN1_C_APPL, &Top_type, 0, &Top_datalen, &l);
    6044           0 : if (e == 0 && Top_type != CONS) { e = ASN1_BAD_ID; }
    6045           0 : if (e) goto fail;
    6046           0 : p += l; len -= l; ret += l;
    6047           0 : Top_oldlen = len;
    6048           0 : if (Top_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    6049           0 : len = Top_datalen;
    6050             : {
    6051           0 : size_t Top_Tag_datalen;
    6052           0 : Der_type Top_Tag_type;
    6053           0 : size_t Top_Tag_oldlen;
    6054           0 : e = der_match_tag_and_length(p, len, ASN1_C_UNIV, &Top_Tag_type, UT_Sequence, &Top_Tag_datalen, &l);
    6055           0 : if (e == 0 && Top_Tag_type != CONS) { e = ASN1_BAD_ID; }
    6056           0 : if (e) goto fail;
    6057           0 : p += l; len -= l; ret += l;
    6058           0 : Top_Tag_oldlen = len;
    6059           0 : if (Top_Tag_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    6060           0 : len = Top_Tag_datalen;
    6061             : {
    6062           0 : size_t principal_datalen;
    6063           0 : Der_type principal_type;
    6064           0 : size_t principal_oldlen;
    6065           0 : e = der_match_tag_and_length(p, len, ASN1_C_CONTEXT, &principal_type, 0, &principal_datalen, &l);
    6066           0 : if (e == 0 && principal_type != CONS) { e = ASN1_BAD_ID; }
    6067           0 : if(e) {
    6068           0 : (data)->principal = NULL;
    6069             : } else {
    6070           0 : (data)->principal = calloc(1, sizeof(*(data)->principal));
    6071           0 : if ((data)->principal == NULL) { e = ENOMEM; goto fail; }
    6072           0 : p += l; len -= l; ret += l;
    6073           0 : principal_oldlen = len;
    6074           0 : if (principal_datalen > len) { e = ASN1_OVERRUN; goto fail; }
    6075           0 : len = principal_datalen;
    6076           0 : e = decode_Principal(p, len, (data)->principal, &l);
    6077           0 : if(e) goto fail;
    6078           0 : p += l; len -= l; ret += l;
    6079           0 : len = principal_oldlen - principal_datalen;
    6080             : }
    6081             : }
    6082           0 : len = Top_Tag_oldlen - Top_Tag_datalen;
    6083             : }
    6084           0 : len = Top_oldlen - Top_datalen;
    6085             : }
    6086           0 : if(size) *size = ret;
    6087           0 : return 0;
    6088           0 : fail:
    6089           0 : free_HDB_entry_alias(data);
    6090           0 : return e;
    6091             : }
    6092             : 
    6093             : void ASN1CALL
    6094           0 : free_HDB_entry_alias(HDB_entry_alias *data)
    6095             : {
    6096           0 : if((data)->principal) {
    6097           0 : free_Principal((data)->principal);
    6098           0 : free((data)->principal);
    6099           0 : (data)->principal = NULL;
    6100             : }
    6101           0 : }
    6102             : 
    6103             : size_t ASN1CALL
    6104           0 : length_HDB_entry_alias(const HDB_entry_alias *data)
    6105             : {
    6106           0 : size_t ret = 0;
    6107           0 : if((data)->principal){
    6108           0 : size_t Top_tag_tag_oldret = ret;
    6109           0 : ret = 0;
    6110           0 : ret += length_Principal((data)->principal);
    6111           0 : ret += 1 + der_length_len (ret);
    6112           0 : ret += Top_tag_tag_oldret;
    6113             : }
    6114           0 : ret += 1 + der_length_len (ret);
    6115           0 : ret += 1 + der_length_len (ret);
    6116           0 : return ret;
    6117             : }
    6118             : 
    6119             : int ASN1CALL
    6120           0 : copy_HDB_entry_alias(const HDB_entry_alias *from, HDB_entry_alias *to)
    6121             : {
    6122           0 : memset(to, 0, sizeof(*to));
    6123           0 : if((from)->principal) {
    6124           0 : (to)->principal = calloc(1, sizeof(*(to)->principal));
    6125           0 : if((to)->principal == NULL) goto fail;
    6126           0 : if(copy_Principal((from)->principal, (to)->principal)) goto fail;
    6127             : }else
    6128           0 : (to)->principal = NULL;
    6129           0 : return 0;
    6130           0 : fail:
    6131           0 : free_HDB_entry_alias(to);
    6132           0 : return ENOMEM;
    6133             : }
    6134             : 
    6135             : char * ASN1CALL
    6136           0 : print_HDB_entry_alias(const HDB_entry_alias *data, int flags)
    6137           0 : { errno = EINVAL; return 0; }
    6138             : 
    6139             : int ASN1CALL
    6140           0 : encode_HDB_EntryOrAlias(unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, const HDB_EntryOrAlias *data, size_t *size)
    6141             : {
    6142           0 : size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;
    6143           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    6144           0 : int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;
    6145             : 
    6146             : 
    6147           0 : switch((data)->element) {
    6148           0 : case choice_HDB_EntryOrAlias_alias: {size_t Top_oldret = ret;
    6149           0 : ret = 0;
    6150           0 : e = encode_HDB_entry_alias(p, len, &((data))->u.alias, &l);
    6151           0 : if (e) return e;
    6152           0 : p -= l; len -= l; ret += l;
    6153             : 
    6154           0 : ret += Top_oldret;
    6155           0 : break;
    6156             : }
    6157           0 : case choice_HDB_EntryOrAlias_entry: {size_t Top_oldret = ret;
    6158           0 : ret = 0;
    6159           0 : e = encode_HDB_entry(p, len, &((data))->u.entry, &l);
    6160           0 : if (e) return e;
    6161           0 : p -= l; len -= l; ret += l;
    6162             : 
    6163           0 : ret += Top_oldret;
    6164           0 : break;
    6165             : }
    6166           0 : };
    6167           0 : *size = ret;
    6168           0 : return 0;
    6169             : }
    6170             : 
    6171             : int ASN1CALL
    6172           0 : decode_HDB_EntryOrAlias(const unsigned char *p HEIMDAL_UNUSED_ATTRIBUTE, size_t len HEIMDAL_UNUSED_ATTRIBUTE, HDB_EntryOrAlias *data, size_t *size)
    6173             : {
    6174           0 : size_t ret = 0;
    6175           0 : size_t l HEIMDAL_UNUSED_ATTRIBUTE;
    6176           0 : int e HEIMDAL_UNUSED_ATTRIBUTE;
    6177             : 
    6178           0 : memset(data, 0, sizeof(*data));
    6179           0 : if (der_match_tag(p, len, ASN1_C_UNIV, CONS, UT_Sequence, NULL) == 0) {
    6180           0 : (data)->element = choice_HDB_EntryOrAlias_entry;
    6181           0 : e = decode_HDB_entry(p, len, &(data)->u.entry, &l);
    6182           0 : if(e) goto fail;
    6183           0 : p += l; len -= l; ret += l;
    6184             : }
    6185           0 : else if (der_match_tag(p, len, ASN1_C_APPL, CONS, 0, NULL) == 0) {
    6186           0 : (data)->element = choice_HDB_EntryOrAlias_alias;
    6187           0 : e = decode_HDB_entry_alias(p, len, &(data)->u.alias, &l);
    6188           0 : if(e) goto fail;
    6189           0 : p += l; len -= l; ret += l;
    6190             : }
    6191             : else {
    6192           0 : e = ASN1_PARSE_ERROR;
    6193           0 : goto fail;
    6194             : }
    6195           0 : if(size) *size = ret;
    6196           0 : return 0;
    6197           0 : fail:
    6198           0 : free_HDB_EntryOrAlias(data);
    6199           0 : return e;
    6200             : }
    6201             : 
    6202             : void ASN1CALL
    6203           0 : free_HDB_EntryOrAlias(HDB_EntryOrAlias *data)
    6204             : {
    6205           0 : switch((data)->element) {
    6206           0 : case choice_HDB_EntryOrAlias_entry:
    6207           0 : free_HDB_entry(&(data)->u.entry);
    6208           0 : break;
    6209           0 : case choice_HDB_EntryOrAlias_alias:
    6210           0 : free_HDB_entry_alias(&(data)->u.alias);
    6211           0 : break;
    6212             : }
    6213           0 : }
    6214             : 
    6215             : size_t ASN1CALL
    6216           0 : length_HDB_EntryOrAlias(const HDB_EntryOrAlias *data)
    6217             : {
    6218           0 : size_t ret = 0;
    6219           0 : switch((data)->element) {
    6220           0 : case choice_HDB_EntryOrAlias_entry:
    6221             : {
    6222           0 : size_t Top_oldret = ret;
    6223           0 : ret = 0;
    6224           0 : ret += length_HDB_entry(&(data)->u.entry);
    6225           0 : ret += Top_oldret;
    6226             : }
    6227           0 : break;
    6228           0 : case choice_HDB_EntryOrAlias_alias:
    6229             : {
    6230           0 : size_t Top_oldret = ret;
    6231           0 : ret = 0;
    6232           0 : ret += length_HDB_entry_alias(&(data)->u.alias);
    6233           0 : ret += Top_oldret;
    6234             : }
    6235           0 : break;
    6236             : }
    6237           0 : return ret;
    6238             : }
    6239             : 
    6240             : int ASN1CALL
    6241           0 : copy_HDB_EntryOrAlias(const HDB_EntryOrAlias *from, HDB_EntryOrAlias *to)
    6242             : {
    6243           0 : memset(to, 0, sizeof(*to));
    6244           0 : (to)->element = (from)->element;
    6245           0 : switch((from)->element) {
    6246           0 : case choice_HDB_EntryOrAlias_entry:
    6247           0 : if(copy_HDB_entry(&(from)->u.entry, &(to)->u.entry)) goto fail;
    6248           0 : break;
    6249           0 : case choice_HDB_EntryOrAlias_alias:
    6250           0 : if(copy_HDB_entry_alias(&(from)->u.alias, &(to)->u.alias)) goto fail;
    6251           0 : break;
    6252             : }
    6253           0 : return 0;
    6254           0 : fail:
    6255           0 : free_HDB_EntryOrAlias(to);
    6256           0 : return ENOMEM;
    6257             : }
    6258             : 
    6259             : char * ASN1CALL
    6260           0 : print_HDB_EntryOrAlias(const HDB_EntryOrAlias *data, int flags)
    6261           0 : { errno = EINVAL; return 0; }
    6262             : 

Generated by: LCOV version 1.14