Like this article? We recommend
String Parser
Listing 4 illustrates the parsing code for a string type.
Listing 4 String Parser
case STR_CLASS: printf("String character "); for (i = *offset + 2; i <= *offset + elementLength + 1; i++) printf("%c", dataSet[i]); printf("\n\n"); *offset += elementLength + 1; parseAsnElement(dataSet, offset, elementLength, overallLength); break;
As for the integer case, the first four lines of Listing 4 extract the string data from the ASN.1 encoding. After the data extraction is done, I move the offset along past the string element and then recursively call into parseAsnElement(). The latter call is made to see if there is more ASN.1 data to process. In the present case, we’re done because there’s no more data after the string.