Allocate memory at once

2005-03-03 Thread Zerg
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)
Thanks.



__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Allocate memory at once

2005-03-03 Thread Dunceor .
Damnit, stop send everything twice and stop reply with a new topic to old mails.

Damn.

// Dunceor


On Thu, 3 Mar 2005 15:09:11 +0200, Zerg <[EMAIL PROTECTED]> 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)
> Thanks.
> 
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Allocate memory at once

2005-03-03 Thread Dr. Stephen Henson
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 Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]