Function silc_asn1_decode
SYNOPSIS
SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...);
DESCRIPTION
Decodes the ASN.1 encoded buffer `src' by the ASN.1 types sent
as argument. The ASN.1 types sent as argument must be found from
the `src' for this function to decode successfully.
The memory allocated for the results are allocated from `asn1' and
they become invalid if `asn1' becomes invalid. Next (second) call
to this function does NOT invalidate the previous results. However,
third call to this function does invalidate the results of the first
call but not second. On the other hand, fourth call invalidates
the results of the second call but not third, fifth call invalidates
the results of the third call but not fourth, and so on. This allows
efficient decoding, when silc_asn1_decode must be called multiple times
to decode all data, without new memory allocations. However, caller
must be cautios and understand that the every second call invalidates
the results of every second previous results.
If the SILC_ASN1_OPTS macro with SILC_ASN1_ALLOC option is given then
all results are dynamically allocated and caller must free them by
itself. Alternatively if SILC_ASN1_ACCUMUL is given then memory is
accumulated from `asn1' for results and they are freed only when the
silc_asn1_free or silc_asn1_uninit is called. Next calls to the
silc_asn1_decode will NOT invalidate the old results, but will
accumulate more memory for new results. If the SILC_ASN1_OPTS is not
given at all then the default allocation method (decribed above)
applies.
If caller needs to store the results even after `asn1' becomes invalid
then call must either use SILC_ASN1_ALLOC option or duplicate the
results by itself.
EXAMPLE
SilcBool bool_val, foo;
unsigned char *string, string2;
SilcUInt32 string_len, string2_len;
silc_asn1_decode(asn1, tree,
SILC_ASN1_SEQUENCE,
SILC_ASN1_BOOLEAN(&bool_val),
SILC_ASN1_OCTET_STRING(&string, &string_len),
SILC_ASN1_SEQUENCE_T(0, 2),
SILC_ASN1_BOOLEAN_T(SILC_ASN1_EXPLICIT, 100, &foo),
SILC_ASN1_END,
SILC_ASN1_OCTET_STRING_T(0, 1, &str2, &str2_len),
SILC_ASN1_END, SILC_ASN1_END);
|