aboutsummaryrefslogtreecommitdiffstats
path: root/common/tlv.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/tlv.h')
-rw-r--r--common/tlv.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/common/tlv.h b/common/tlv.h
index 51a0ef455..3e2d1dfb1 100644
--- a/common/tlv.h
+++ b/common/tlv.h
@@ -72,10 +72,22 @@ enum tlv_tag_type {
TAG_BMP_STRING = 30
};
+struct tag_info
+{
+ int class;
+ int is_constructed;
+ unsigned long tag;
+ size_t length; /* length part of the TLV */
+ size_t nhdr;
+ int ndef; /* It is an indefinite length */
+};
struct tlv_builder_s;
typedef struct tlv_builder_s *tlv_builder_t;
+struct tlv_parser_s;
+typedef struct tlv_parser_s *tlv_parser_t;
+
/*-- tlv.c --*/
/* Locate a TLV encoded data object in BUFFER of LENGTH and return a
@@ -138,6 +150,59 @@ void put_tlv_to_membuf (membuf_t *membuf, int class, int tag,
size_t get_tlv_length (int class, int tag, int constructed, size_t length);
+/*-- tlv-parser.c --*/
+#define TLV_PARSER_FLAG_T5793 1 /* Enable workaround for Mozilla bug. */
+
+tlv_parser_t _tlv_parser_new (const unsigned char *buffer, size_t bufsize,
+ int verbosity, tlv_parser_t lasttlv, int lno);
+tlv_parser_t _tlv_parser_release (tlv_parser_t tlv, int lno);
+
+void _tlv_parser_dump_tag (const char *text, int lno, tlv_parser_t tlv);
+void _tlv_parser_dump_state (const char *text, const char *text2,
+ int lno, tlv_parser_t tlv);
+
+gpg_error_t _tlv_parser_next (tlv_parser_t tlv, unsigned int flags, int lno);
+
+unsigned int tlv_parser_level (tlv_parser_t tlv);
+size_t tlv_parser_offset (tlv_parser_t tlv);
+const char *tlv_parser_lastfunc (tlv_parser_t tlv);
+const char *tlv_parser_lasterrstr (tlv_parser_t tlv);
+void tlv_parser_set_pending (tlv_parser_t tlv);
+size_t tlv_parser_tag_length (tlv_parser_t tlv, int with_header);
+
+void tlv_parser_skip (tlv_parser_t tlv);
+
+gpg_error_t tlv_expect_sequence (tlv_parser_t tlv);
+gpg_error_t tlv_expect_context_tag (tlv_parser_t tlv, int *r_tag);
+gpg_error_t tlv_expect_set (tlv_parser_t tlv);
+gpg_error_t tlv_expect_object (tlv_parser_t tlv, int class, int tag,
+ unsigned char const **r_data,
+ size_t *r_datalen);
+gpg_error_t tlv_expect_octet_string (tlv_parser_t tlv,
+ unsigned char const **r_data,
+ size_t *r_datalen);
+gpg_error_t tlv_expect_integer (tlv_parser_t tlv, int *r_value);
+#ifdef GCRYPT_VERSION
+gpg_error_t tlv_expect_mpinteger (tlv_parser_t tlv, int ignore_zero,
+ gcry_mpi_t *r_value);
+#endif
+gpg_error_t tlv_expect_object_id (tlv_parser_t tlv,
+ unsigned char const **r_oid,
+ size_t *r_oidlen);
+gpg_error_t tlv_expect_null (tlv_parser_t tlv);
+
+/* Easier to use wrapper around parse_ber_header. */
+gpg_error_t tlv_parse_tag (unsigned char const **buffer,
+ size_t *size, struct tag_info *ti);
+
+/* Convenience macro and macros to include the line number. */
+#define tlv_parser_new(a,b,c,d) _tlv_parser_new ((a),(b),(c),(d), __LINE__)
+#define tlv_parser_release(a) _tlv_parser_release ((a), __LINE__)
+#define tlv_parser_dump_tag(a,b) _tlv_parser_dump_tag ((a),__LINE__,(b))
+#define tlv_parser_dump_state(a,b,c) \
+ _tlv_parser_dump_state ((a),(b),__LINE__,(c))
+#define tlv_next(a) _tlv_parser_next ((a),0, __LINE__)
+#define tlv_next_with_flag(a,b) _tlv_parser_next ((a),(b), __LINE__)
#endif /* SCD_TLV_H */