<div dir="ltr"><div dir="ltr">Bonjour,<div><br></div><div>Taking your example, the following works here (Mac, OpenSSL 3.0.5).</div><div><br></div><div>$ cat myobj.h<br>#pragma once<br>#include <openssl/asn1.h><br><br>#define ASN1_OBJECT_dup(x) ASN1_dup_of(ASN1_OBJECT,i2d_ASN1_OBJECT,d2i_ASN1_OBJECT,x)<br><br>/*<br> * MyObj ::= SEQUENCE {<br> *   a OBJECT IDENTIFIER,<br> *   b OBJECT IDENTIFIER }<br> */<br><br>typedef struct {<br>  ASN1_OBJECT *a;<br>  ASN1_OBJECT *b;<br>} MYOBJ;<br><br>DECLARE_ASN1_FUNCTIONS(MYOBJ);<br>DECLARE_ASN1_DUP_FUNCTION(MYOBJ);<br>DECLARE_ASN1_PRINT_FUNCTION(MYOBJ);<br>#define d2i_MYOBJ_bio(bp,p) ASN1_d2i_bio_of(MYOBJ,MYOBJ_new,d2i_MYOBJ,bp,p)<br>#define i2d_MYOBJ_bio(bp,o) ASN1_i2d_bio_of(MYOBJ,i2d_MYOBJ,bp,o)<br>#define d2i_MYOBJ_fp(fp,p) ASN1_d2i_fp_of(MYOBJ,MYOBJ_new,d2i_MYOBJ,fp,p)<br>#define i2d_MYOBJ_fp(fp,p) ASN1_i2d_fp_of(MYOBJ,i2d_MYOBJ,fp,p)<br></div></div><div><br></div><div><br></div><div>$ cat myobj.c<br>#include "myobj.h"<br>#include <openssl/asn1t.h><br><br>/* MyObj */<br>ASN1_SEQUENCE(MYOBJ) = {<br>  ASN1_SIMPLE(MYOBJ, a, ASN1_OBJECT),<br>  ASN1_SIMPLE(MYOBJ, b, ASN1_OBJECT)<br>} ASN1_SEQUENCE_END(MYOBJ)<br><br>IMPLEMENT_ASN1_FUNCTIONS(MYOBJ);<br>IMPLEMENT_ASN1_DUP_FUNCTION(MYOBJ);<br>IMPLEMENT_ASN1_PRINT_FUNCTION(MYOBJ);<br></div><div><br></div><div><br></div>$ cat myprg.c<br>#include "myobj.h"<br>#include <stdio.h><br>#include <stdlib.h><br>#include <openssl/err.h><br>#include <openssl/objects.h><div>#include <openssl/bio.h><br><br>int main(void)<br>{<br>  FILE *fout = NULL;</div><div>  BIO *bout = NULL;<br>  MYOBJ *myobj = NULL;<br><br>  printf("Openssl Version: %s\n", OPENSSL_VERSION_STR);<br><br>  myobj = MYOBJ_new();<br>  myobj->a = OBJ_nid2obj(NID_commonName);<br>  myobj->b = OBJ_nid2obj(NID_countryName);<br><br>  bout = BIO_new_fp(stdout, BIO_NOCLOSE);<br>  MYOBJ_print_ctx(bout, myobj, 0, NULL);<br>  BIO_flush(bout);<br>  BIO_free(bout);</div><div><br>  fout = fopen("myobj.der", "wb");<br>  i2d_MYOBJ_fp(fout, myobj);<br>  fclose(fout);<br><br>  ERR_print_errors_fp(stderr);<br>  return 0;<br>}<div><br></div><div>$ gcc -o myprg -I /opt/local/include -L /opt/local/lib myprg.c myobj.c -lcrypto<br></div><div><br></div><div>$ ./myprg</div><div>Openssl Version: 3.0.5<br>MYOBJ:<br>  a: commonName (2.5.4.3)<br>  b: countryName (2.5.4.6)<br></div><div><br></div><div>And there's a file myobj.der created in the current directory.</div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 26, 2023 at 6:57 PM Ladd, Watson via openssl-users <<a href="mailto:openssl-users@openssl.org">openssl-users@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Dear OpenSSL Users,<br>
<br>
I have a structure of the form<br>
<br>
typdef struct {<br>
      ASN1_OBJECT *a;<br>
       ASN1_OBJECT *b;<br>
} example;<br>
<br>
and I cannot figure out how to make the ASN.1 macros serialize it correctly.<br>
<br>
When I tried to use an ASN1_SEQUENCE with two ASN1_SIMPLEs the code failed to serialize the structure.<br>
I've been trying to use various ASN1_TYPE, but it seems those only work when ASN1_OPTS are used or some variant.<br>
<br>
Any suggestions/pointers to documentation on how to do this? It seems like the resources that used to exist for the very old<br>
macros don't exist anymore, and the newer more explicit stuff is only used inside of providers and not exposed elsewhere.<br>
<br>
Sincerely,<br>
Watson Ladd</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Cordialement,<div>Erwann Abalea.</div></div></div></div></div></div>