Cryptography Reference
In-Depth Information
token->data = ptr_begin;
token->children = ( struct asn1struct * )
malloc( sizeof( struct asn1struct ) );
asn1parse( ptr, tag_length, token->children );
}
5. When it returns, or if it wasn't called because the tag was a non-constructed
tag, you're either at the end of the data or you're pointing at the next ele-
ment relative to the one that was just parsed.
if ( length )
{
token->next = ( struct asn1struct * )
malloc( sizeof( struct asn1struct ) );
token = token->next;
}
6. If there is another element to parse, allocate space for it, update the target
token pointer, and loop back around to process this element. When you're
fi nished the supplied top_level_token structure points to the root of a
fully parsed ASN.1 tree.
7. Finally, because a lot of memory is allocated by the ASN.1 parsing process,
defi ne a function to recursively go through and clean it all up as shown
in Listing 5-6.
Listing 5-6: “asn1.c” asn1free
/**
* Recurse through the given node and free all of the memory that was allocated
* by asn1parse. Don't free the “data” pointers, since that points to memory
* that was not allocated by asn1parse.
*/
void asn1free( struct asn1struct *node )
{
if ( !node )
{
return;
}
asn1free( node->children );
free( node->children );
asn1free( node->next );
free( node->next );
}
 
Search WWH ::




Custom Search