[openssl-users] SKM_ASN1_SET_OF_i2d
Dr. Stephen Henson
steve at openssl.org
Tue Sep 13 20:32:22 UTC 2016
On Tue, Sep 13, 2016, Thomas Francis, Jr. wrote:
> What???s the replacement for code that used SKM_ASN1_SET_OF_i2d in OpenSSL 1.1? The code I???ve got that calls this function is getting the DER encoding of a STACK_OF() as a sorted SET. This STACK_OF() is of a custom ASN1 type; and is a member of another structure that is also a custom ASN1 structure.
>
> The call looks like this:
>
> int len = SKM_ASN1_SET_OF_i2d(structureName, containingStructure->member, NULL, i2d_structureName, V_ASN1_SET, V_ASN1_UNIVERSAL, IS_SET);*
>
>
> ???structureName??? is the typedef???d name of the C struct, which was also passed to the DEFINE_STACK_OF() and DECLARE_ASN1_FUNCTIONS() macros (in OpenSSL < 1.1, it???s DECLARE_STACK_OF(), not DEFINE_STACK_OF() ).
>
> ???containingStructure??? is a pointer to a C struct, and its member, ???member??? is of the type, STACK_OF(structureName).
>
There isn't a precise equivalent but it looks like you need an i2d function to
encode as SET OF. You can do that.
First you need a typedef for the STACK_OF something like:
typedef STACK_OF(FOO) FOOS
Then you create an ASN.1 ITEM template like this:
ASN1_ITEM_TEMPLATE(FOOS) =
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, foos, FOO)
ASN1_ITEM_TEMPLATE_END(FOOS)
You then add IMPLEMENT_ASN1_FUNCTIONS(FOOS) and DECLARE_ASN1_FUINCTION(FOOS).
This will produce new functions i2d_FOOS, d2i_FOOS, FOOS_new() and
FOOS_free() which should do what you want. If you don't want the new/free ones
you can use IMPLEMENT_ASN1_ENCODE_FUNCTIONS instead.
This is used in OpenSSL in a few places such as the implementation of
GeneralNames which is a SEQUENCE_OF GeneralName.
Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
More information about the openssl-users
mailing list