title: Building an ASN1 set using the openssl C API
body: <p>I'm trying to build a set of sequences using the openssl C API. As was noted in various places, the documentation is VERY sparse on this and code samples seem to be non-existent.</p>
  
  <p>I've found various suggestions on the web but none that seemed to work correctly.</p>
  
  <p>I've gotten that far in order to create sequences:</p>
  
  <pre><code>#include &lt;openssl/asn1t.h&gt;
  
  countdef struct StringStructure {
      ASN1_INTEGER *count;
      ASN1_INTEGER *asnVersion;
      ASN1_OCTET_STRING *value;
  } StringSequence;
  
  DECLARE_ASN1_FUNCTIONS(StringSequence)
  
  ASN1_SEQUENCE(StringSequence) = {
      ASN1_SIMPLE(StringSequence, count, ASN1_INTEGER),
      ASN1_SIMPLE(StringSequence, asnVersion, ASN1_INTEGER),
      ASN1_SIMPLE(StringSequence, value, ASN1_OCTET_STRING),
  } ASN1_SEQUENCE_END(StringSequence)
  
  IMPLEMENT_ASN1_FUNCTIONS(StringSequence)
  
  auto aSeq = StringSequence_new();
  aSeq-&gt;count = ASN1_INTEGER_new();
  aSeq-&gt;asnVersion = ASN1_INTEGER_new();
  aSeq-&gt;value = ASN1_OCTET_STRING_new();
  if (!ASN1_INTEGER_set(aSeq-&gt;count, 10) ||
      !ASN1_INTEGER_set(aSeq-&gt;asnVersion, 1) ||
      !ASN1_STRING_set(aSeq-&gt;value, "Test", -1)) {
      // -- Error
  }
  
  auto anotherSeq = StringSequence_new();
  anotherSeq-&gt;count = ASN1_INTEGER_new();
  anotherSeq-&gt;asnVersion = ASN1_INTEGER_new();
  anotherSeq-&gt;value = ASN1_OCTET_STRING_new();
  if (!ASN1_INTEGER_set(anotherSeq-&gt;count, 32) ||
      !ASN1_INTEGER_set(anotherSeq-&gt;asnVersion, 1) ||
      !ASN1_STRING_set(anotherSeq-&gt;value, "Something Else", -1)) {
      // -- Error
  }
  </code></pre>
  
  <p>Where do I go from there in order to build a set of these?</p>