static uint32_t * tlv_next_item_ptr( __in tlv_cursor_t *cursor) { uint32_t length; length = tlv_length(cursor); return (cursor->current + TLV_DWORD_COUNT(length)); }
// This will should only be called by "parse_as_sequence_or_hex...." // Should be renamed: "check_and_parse_sequence_or_hex" or "...sub" or similar.... bool check_and_parse_sequence_of_asn1_tags(vdchunk_base *tag, int depth, bool strict, VDCHUNK_ASN1_ACTION_TYPE_ABSTRACT *action) //! Parses the buffer (zero position) under the assumption that //! it might contain a sequence of tags or otherwise has to be //! displayed as hex code. //! In principle, this function parses the "V" part of a tag (TLV) //! that contains a sequence of nested tags. //! Please note: Resets parse counter (XXYa) //! \param tag Buffer to be parsed //! \param depth Number of spaces for indention //! \param action Actions to be performed //! \return TRUE, if sequence/set; FALSE, otherwise { #ifdef VDCHUNK_ASN1_DEBUG_MSG3 fprintf(VDCHUNK_ASN1_DEBUG_STREAM, "check_and_parse_sequence_of_asn1_tags(%s, ...) [c] Length: 0x%04X, Depth: %d\n", tag->name.c_str(), (int)(tag->entries), depth); #endif long int slen; bool finished, result, isseq; unsigned long int tlv_len; vdchunk_base_cutout *next2; string tabs; tabs = asn1_simple_spaces(depth); tag->parse_reset(); // No action if tag is empty if (tag->entries == 0) return false; isseq = is_sequence_of_asn1_tags(tag, action); /* Temporarily not available // Check if the tag is a sequence of valid tags.... if (strict) { isseq = is_sequence_of_asn1_tags(tag, action); } else { isseq = is_sequence_of_asn1_tags_not_strict(tag, action); } */ tag->parse_reset(); if (isseq) { // If yes .... result = true; if (action->get_byte(VDCHUNK_ASN1_ACTION_COMMENTS6) != 0) { fprintf(VDCHUNK_ASN1_STREAM, "%s Check whether content might be a sequence of embedded ASN1 tags .... yes\n", tabs.c_str()); }; tag->parse_reset(); finished = false; do { tlv_len = tlv_length(tag, action); next2 = new vdchunk_base_cutout(tag->name + "OS3", tag, tag->get_parse_counter(), tag->get_parse_counter()+tlv_len); parse_asn1(next2, depth, &slen, action); // This part of "tag" has now been parsed; correct the parse // counter accordingly delete(next2); tag->parse_skip_bytes(tlv_len); if (tag->parse_counter() >= tag->entries) finished = true; } while (!finished); } else { // Buffer does not contain a sequence of ASN1 tags. result = false; if (action->get_byte(VDCHUNK_ASN1_ACTION_COMMENTS6) != 0) { fprintf(VDCHUNK_ASN1_STREAM, "%s Check whether content might be a sequence of embedded ASN1 tags .... no\n", tabs.c_str()); }; // Just print the buffer, if required. if (action->get_byte(VDCHUNK_ASN1_ACTION_COMMENTS4) != 0) { if (action->get_byte(VDCHUNK_ASN1_ACTION_DISPLAY_LEAD0) != 0) { // DISPLAY LEAD0 defines whether leading zero bytes // should be displayed separately if (tag->parse_look_ahead(0) == 0) { tag->parse_read(); fprintf(VDCHUNK_ASN1_STREAM,"%s 00\n", tabs.c_str()); }; // if leading zero byte }; assert(tag->get_parse_counter() <= tag->entries); if (tag->get_parse_counter() < tag->entries) { next2 = new vdchunk_base_cutout(tag->name + "OS3", tag, tag->get_parse_counter(), tag->entries); assert(depth > 0); vdchunk_asn1_write_hex(next2, depth-1); // next2->write_hex(VDCHUNK_ASN1_STREAM, tabs + " ", // VDCHUNK_ASN1_CHARPERLINE, 32, VDCHUNK_ASN1_CHARTOTAL); // fprintf(VDCHUNK_ASN1_STREAM,"\n"); delete(next2); }; }; }; // else return result; }