1 //-----------------------------------------------------------------------------
2 // Borrowed initially from https://github.com/lumag/emv-tools/
3 // Copyright (C) 2012, 2015 Dmitry Eremin-Solenikov
4 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // See LICENSE.txt for the text of the license.
17 //-----------------------------------------------------------------------------
18 // libopenemv - a library to work with EMV family of smart cards
19 //-----------------------------------------------------------------------------
27 typedef uint32_t tlv_tag_t
;
32 const unsigned char *value
;
39 struct tlvdb
*children
;
48 typedef void (*tlv_cb
)(void *data
, const struct tlv
*tlv
, int level
, bool is_leaf
);
50 struct tlvdb
*tlvdb_fixed(tlv_tag_t tag
, size_t len
, const unsigned char *value
);
51 struct tlvdb
*tlvdb_external(tlv_tag_t tag
, size_t len
, const unsigned char *value
);
52 struct tlvdb
*tlvdb_parse(const unsigned char *buf
, size_t len
);
53 struct tlvdb
*tlvdb_parse_multi(const unsigned char *buf
, size_t len
);
55 bool tlvdb_parse_root(struct tlvdb_root
*root
);
56 bool tlvdb_parse_root_multi(struct tlvdb_root
*root
);
58 void tlvdb_free(struct tlvdb
*tlvdb
);
59 void tlvdb_root_free(struct tlvdb_root
*root
);
61 struct tlvdb
*tlvdb_elm_get_next(struct tlvdb
*tlvdb
);
62 struct tlvdb
*tlvdb_elm_get_children(struct tlvdb
*tlvdb
);
63 struct tlvdb
*tlvdb_elm_get_parent(struct tlvdb
*tlvdb
);
65 struct tlvdb
*tlvdb_find_full(struct tlvdb
*tlvdb
, tlv_tag_t tag
); // search also in childrens
66 struct tlvdb
*tlvdb_find(struct tlvdb
*tlvdb
, tlv_tag_t tag
);
67 struct tlvdb
*tlvdb_find_next(struct tlvdb
*tlvdb
, tlv_tag_t tag
);
68 struct tlvdb
*tlvdb_find_path(struct tlvdb
*tlvdb
, tlv_tag_t tag
[]);
70 void tlvdb_add(struct tlvdb
*tlvdb
, struct tlvdb
*other
);
71 void tlvdb_change_or_add_node(struct tlvdb
*tlvdb
, tlv_tag_t tag
, size_t len
, const unsigned char *value
);
72 void tlvdb_change_or_add_node_ex(struct tlvdb
*tlvdb
, tlv_tag_t tag
, size_t len
, const unsigned char *value
, struct tlvdb
**tlvdb_elm
);
74 void tlvdb_visit(const struct tlvdb
*tlvdb
, tlv_cb cb
, void *data
, int level
);
75 const struct tlv
*tlvdb_get(const struct tlvdb
*tlvdb
, tlv_tag_t tag
, const struct tlv
*prev
);
76 const struct tlv
*tlvdb_get_inchild(const struct tlvdb
*tlvdb
, tlv_tag_t tag
, const struct tlv
*prev
);
77 const struct tlv
*tlvdb_get_tlv(const struct tlvdb
*tlvdb
);
79 bool tlv_parse_tl(const unsigned char **buf
, size_t *len
, struct tlv
*tlv
);
80 unsigned char *tlv_encode(const struct tlv
*tlv
, size_t *len
);
81 bool tlv_is_constructed(const struct tlv
*tlv
);
82 bool tlv_equal(const struct tlv
*a
, const struct tlv
*b
);
84 bool tlv_get_uint8(const struct tlv
*etlv
, uint8_t *value
);
85 bool tlv_get_int(const struct tlv
*etlv
, int *value
);
87 bool tlvdb_get_uint8(struct tlvdb
*tlvRoot
, tlv_tag_t tag
, uint8_t *value
);