buffer\datum questions
Nikos Mavrogiannopoulos
nmav at gnutls.org
Thu Aug 2 09:37:14 CEST 2012
On Thu, Aug 2, 2012 at 6:02 AM, Olya <olyasib12 at gmail.com> wrote:
>> There is _gnutls_bin2hex() that given your buffer's data and length
>> fields it would save the hex output in the array you specified.
> Do I have to allocate that char * array or _gnutls_bin2hex() will take care of that?
You need to take care of allocation. Typically functions that return
allocated data they do it inside a gnutls_datum_t (and should be
explicit about it).
>>> 5) What does various _prefix() functions do?
>> They are used to store the TLS variable length fields. That is they
>> prepend the size of the buffer before the data. The prefix size is the
>> number of bits used for the length (8,16,24,32).
> What's the meaning of check in
> _gnutls_buffer_pop_prefix (gnutls_buffer_st * buf, size_t * data_size, int check) ?
It reads a 32-bit integer from the buffer and checks whether the
remaining data length are less than that.
> And few more related questions:
> 1) Why _gnutls_buffer_replace_data( gnutls_buffer_st * buf, gnutls_datum_t * data)
> uses datum while _append() uses data & size?
It could have been that most of calls to replace_data() were using
datums. No particular reason.
> 2) Do I have to pre-allocate memory for the datum, copy my data to datum, call
> _replace() and deallocate datum? Could you give simple example of _replace() usage?
The replace, will copy the datum you provide (already allocated) to the buffer.
> 3) When should I use _gnutls_buffer_reset() ?
If you want to re-use a buffer. I.e. you appended some data, sent it
to the peer, and want to use a new buffer. Instead of initializing a
new one you reset that one.
> Thank you for detailed explanations - it's too good to leave it be in my inbox :-)
> Should I add them to doc/cha-internals.texi or there's more appropriate place for that?
I think the best is to add inline comments like:
http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=blob;f=lib/gnutls_cert.c;h=01636cc35326a7931fbb3083c116bc71411da461;hb=HEAD#l140
That way once the function is updated it is easy to modify its description.
regards,
Nikos
More information about the Gnutls-devel
mailing list