Cryptography Reference
In-Depth Information
tag |= *ptr & 0x7F;
}
}
X.509 doesn't defi ne any of these, but you ought to recognize them for
completeness — if for no other reason than to be able to safely ignore them
if you happen to come across one.
2. Parse out the length of the structure itself; this is always present. If the
fi rst byte is a multi-length byte, the processing is a bit complex in part
because of the endian-ness issue.
if ( tag_length_byte & 0x80 )
{
const unsigned char *len_ptr = ptr;
tag_length = 0;
while ( ( len_ptr - ptr ) < ( tag_length_byte & 0x7F ) )
{
tag_length <<= 8;
tag_length |= *(len_ptr++);
length--;
}
ptr = len_ptr;
}
else
{
tag_length = tag_length_byte;
}
3. Now that you know the type of tag and the length of its contents — whether
they are data or other ASN.1 structures — you can start fi lling out the
asn1struct instance:
token->constructed = tag & 0x20;
token->tag_class = ( tag & 0xC0 ) >> 6;
token->tag = tag & 0x1F;
token->length = tag_length;
token->data = ptr;
token->children = NULL;
token->next = NULL;
4. Now the tricky part — if this is a constructed tag, its contents are more
ASN.1 structures, which must be appended to the children list. If it is
then allocate a new structure to store the children and recursively call this
routine:
if ( tag & 0x20 )
{
token->length = tag_length + ( ptr - ptr_begin );
Search WWH ::




Custom Search