On Thu, Mar 03, 2005, Zerg wrote:

> Hi.
> We have such ASN structre...
> I am doing  PRIVATEKEY_new(). Is the memory allocated for all the member of
> this structure?
> The same question to PRIVATEKEY_free().
> And what I have to write in callback in case of using ASN1_SEQUENCE_cb to
> allocate all nedeed memory for this structure at once.
> ASN1_SEQUENCE(PRIVATEKEY) = {
>         ASN1_SIMPLE(PRIVATEKEY,  privateKey, ASN1_OCTET_STRING),
>         ASN1_EXP_OPT(PRIVATEKEY, parameters,PKPARAMETERS, 0),
>         ASN1_EXP_OPT(PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1)
> } ASN1_SEQUENCE_END(PRIVATEKEY)
> 
> DECLARE_ASN1_FUNCTIONS_const(PRIVATEKEY)
> DECLARE_ASN1_ENCODE_FUNCTIONS_const(PRIVATEKEY, PRIVATEKEY)
> IMPLEMENT_ASN1_FUNCTIONS_const(PRIVATEKEY)

All non-ambiguous cases are handled automatically in the _new() function.

That means:

Memory is allocated for mandatory fields.
OPTIONAL fields need to be set up when you populate the structure. 
The CHOICE type also needs to be partly setup.


Any additonal allocation should be done when the structure is populated *not*
in a callback.

When a structure is freed *all* fields are freed up.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to