title: der_encode() fails to encode ASN1 message
body: <p>I am using open source ASN1 compiler at <a href="https://github.com/vlm/asn1" rel="nofollow noreferrer">https://github.com/vlm/asn1</a> and I am having a problem when trying to encode my message.</p>
  <p>I have the following <code>TCIMsg_t</code> type:</p>
  <pre><code>typedef struct TCIMsg {
      long     version;
      Time64_t     time;
      Frame_t  frame;
      /*
       * This type is extensible,
       * possible extensions are below.
       */
      
      /* Context for parsing across buffer boundaries */
      asn_struct_ctx_t _asn_ctx;
  } TCIMsg_t;
  </code></pre>
  <p>When I try encoding with der_encode() function as below,</p>
  <pre><code>        TCIMsg_t* tci_msg = (TCIMsg_t *)calloc(1, sizeof(TCIMsg_t));
          const char *filename = av[1];
          FILE *fp = fopen(filename, &quot;wb&quot;);
  
          if(!fp){
              perror(&quot;filename&quot;);
              exit(1);
          }
  
          ec = der_encode(&amp;asn_DEF_TCIMsg, tci_msg, write_out, fp);
          // ec = oer_encode_to_buffer(&amp;asn_DEF_TCIMsg, 0, tci_msg, buffer, sizeof(buffer));
          fclose(fp);
          if(ec.encoded == -1){
              fprintf(stderr, &quot;Could not encode TCIMsg (at %s)\n&quot;,
              ec.failed_type ? ec.failed_type -&gt; name:&quot;unknown&quot;);
              exit(1);
          } else {
              fprintf(stderr, &quot;Created %s with BER encoded Event\n&quot;, filename);
          }
  </code></pre>
  <p>it fails to encode and I get the <code>Could not encode TCIMsg (at Frame)</code> message. <code>Frame</code> is just another nested struct like below</p>
  <pre><code>typedef struct Frame {
      Frame_PR present;
      union Frame_u {
          TCI16093_t   d16093;
          TCI80211_t   d80211;
          TCI16094_t   d16094;
          TCI29451_t   d29451;
          TCISutControl_t  sutCtrl;
          /*
           * This type is extensible,
           * possible extensions are below.
           */
      } choice;
      
      /* Context for parsing across buffer boundaries */
      asn_struct_ctx_t _asn_ctx;
  } Frame_t;
  </code></pre>