Cryptography Reference
In-Depth Information
token->tag_class = ( tag & 0xC0 ) >> 6;
token->tag = tag & 0x1F;
token->length = tag_length;
token->data = ptr;
token->children = NULL;
token->next = NULL;
if ( tag & 0x20 )
{
token->length = tag_length + ( ptr - ptr_begin );
token->data = ptr_begin;
// Append a child to this tag and recurse into it
token->children = ( struct asn1struct * )
malloc( sizeof( struct asn1struct ) );
asn1parse( ptr, tag_length, token->children );
}
ptr += tag_length;
length -= tag_length;
// At this point, we're pointed at the tag for the next token in the buffer.
if ( length )
{
token->next = ( struct asn1struct * ) malloc( sizeof( struct asn1struct ) );
token = token->next;
}
}
return 0;
}
This routine is passed a complete certifi cate structure, so the whole thing
must be resident in memory before this routine is called; this approach might
need to be revisited in, say, a handheld device where memory is constrained. It
reads through the whole buffer, recognizing ASN.1 structures, and allocating
asn1struct instances to represent them.
1. Check to see if this is a multi-byte tag:
if ( ( tag & 0x1F ) == 0x1F )
{
tag = 0;
while ( *ptr & 0x80 )
{
tag <<= 8;
Search WWH ::




Custom Search