M_ASN1_D2I_* replacement in OpenSSL 1.1.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bonjour,

Something like this?

/*

MyChoice ::= CHOICE {
  anInteger INTEGER,
  anOctetString OCTET STRING
  anASCIIString IA5STRING
}

MyStruct ::= SEQUENCE {
  item1 MyChoice
}

*/

__ File mytypes.h __

#include <openssl/asn1.h>

#define ASN1_OBJECT_dup(x) ASN1_dup_of(ASN1_OBJECT,i2d_ASN1_OBJECT,d2i_ASN1_OBJECT,x)
#define DECLARE_ASN1_DUP_FUNCTION(stname) stname * stname##_dup(stname *x);

typedef struct {
  int type;
  union {
    ASN1_INTEGER *anInteger;
    ASN1_OCTET_STRING *anOctetString;
    ASN1_IA5STRING *anASCIIString;
  } value;
} MYCHOICE;

DECLARE_ASN1_FUNCTIONS(MYCHOICE)
DECLARE_ASN1_DUP_FUNCTION(MYCHOICE)
DECLARE_ASN1_PRINT_FUNCTION(MYCHOICE)
#define d2i_MYCHOICE_bio(bp,p) ASN1_d2i_bio_of(MYCHOICE, MYCHOICE_new,d2i_ MYCHOICE,bp,p)
#define i2d_MYCHOICE_bio(bp,o) ASN1_i2d_bio_of(MYCHOICE,i2d_ MYCHOICE,bp,o)
#define d2i_MYCHOICE_fp(fp,p) ASN1_d2i_fp_of(MYCHOICE, MYCHOICE_new,d2i_ MYCHOICE,fp,p)
#define i2d_MYCHOICE_fp(fp,p) ASN1_i2d_fp_of(MYCHOICE,i2d_ MYCHOICE,fp,p)


typedef struct {
  MYCHOICE *item1;
} MYSTRUCT;

DECLARE_ASN1_FUNCTIONS(MYSTRUCT)
DECLARE_ASN1_DUP_FUNCTION(MYSTRUCT)
DECLARE_ASN1_PRINT_FUNCTION(MYSTRUCT)
#define d2i_MYSTRUCT_bio(bp,p) ASN1_d2i_bio_of(MYSTRUCT, MYSTRUCT_new,d2i_ MYSTRUCT,bp,p)
#define i2d_MYSTRUCT_bio(bp,o) ASN1_i2d_bio_of(MYSTRUCT,i2d_ MYSTRUCT,bp,o)
#define d2i_MYSTRUCT_fp(fp,p) ASN1_d2i_fp_of(MYSTRUCT, MYSTRUCT_new,d2i_ MYSTRUCT,fp,p)
#define i2d_MYSTRUCT_fp(fp,p) ASN1_i2d_fp_of(MYSTRUCT,i2d_ MYSTRUCT,fp,p)
____

__ File mytypes.c __
#include <openssl/asn1t.h>
#include "mytypes.h"

ASN1_CHOICE(MYCHOICE) = {
  ASN1_SIMPLE(MYCHOICE, value.anInteger, ASN1_INTEGER),
  ASN1_SIMPLE(MYCHOICE, value.anOctetString, ASN1_OCTET_STRING),
  ASN1_SIMPLE(MYCHOICE, value.anASCIIString, ASN1_IA5STRING)
} ASN1_CHOICE_END(MYCHOICE)

IMPLEMENT_ASN1_FUNCTIONS(MYCHOICE)
IMPLEMENT_ASN1_DUP_FUNCTION(MYCHOICE)
IMPLEMENT_ASN1_PRINT_FUNCTION(MYCHOICE)


ASN1_SEQUENCE(MYSTRUCT) = {
  ASN1_SIMPLE(MYSTRUCT, item1, MYCHOICE)
} ASN1_SEQUENCE_END(MYSTRUCT)

IMPLEMENT_ASN1_FUNCTIONS(MYSTRUCT)
IMPLEMENT_ASN1_DUP_FUNCTION(MYSTRUCT)
IMPLEMENT_ASN1_PRINT_FUNCTION(MYSTRUCT)
____

Now you can call i2d_MYSTRUCT()/d2i_MYSTRUCT() to encode/decode such a data type, and similar _bio, _fp, _dup functions as well.

Cordialement,
Erwann Abalea

Le 20 sept. 2016 ? 11:45, Aleksandr Konstantinov <aleksandr.v.konstantinov at gmail.com<mailto:aleksandr.v.konstantinov at gmail.com>> a ?crit :

Hello,

Thanks a lot. One more question if possible. Is there any way to express single element of the ASN1 sequence which can be any of ASN1_OCTET_STRING or ASN1_UTF8STRING and potentially other types?
Or maybe there is some tutorial for new interface similar to something like http://www.umich.edu/~x509/ssleay/asn1-macros.html for old one?

Best regards,


A.K.



On Mon, Sep 19, 2016 at 3:05 PM, Dr. Stephen Henson <steve at openssl.org<mailto:steve at openssl.org>> wrote:
On Mon, Sep 19, 2016, Aleksandr Konstantinov wrote:

>
> Thanks. Your answer helped a lot and I'm progressing now. Could You please
> also give me a hint what M_ASN1_BIT_STRING_dup/ASN1_BIT_STRING_dup could be
> replaced with?
>

ASN1_STRING_dup should work fine: ASN1_BIT_STRING is actually typedefed to
ASN1_STRING.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org<http://www.openssl.org/>
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-users/attachments/20160920/cda727c7/attachment-0001.html>


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux