]> git.zerfleddert.de Git - proxmark3-svn/blame - client/emv/tlv.h
fix 'hf iclass sim':
[proxmark3-svn] / client / emv / tlv.h
CommitLineData
a2bb2735 1/*
2 * libopenemv - a library to work with EMV family of smart cards
3 * Copyright (C) 2012, 2015 Dmitry Eremin-Solenikov
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * https://github.com/lumag/emv-tools/blob/master/lib/include/openemv/tlv.h
16 */
17
18#ifndef TLV_H
19#define TLV_H
20
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
24
25typedef uint16_t tlv_tag_t;
26
27struct tlv {
28 tlv_tag_t tag;
29 size_t len;
30 const unsigned char *value;
31};
32
33struct tlvdb;
33a9982c 34typedef bool (*tlv_cb)(void *data, const struct tlv *tlv, int level, bool is_leaf);
a2bb2735 35
36struct tlvdb *tlvdb_fixed(tlv_tag_t tag, size_t len, const unsigned char *value);
37struct tlvdb *tlvdb_external(tlv_tag_t tag, size_t len, const unsigned char *value);
38struct tlvdb *tlvdb_parse(const unsigned char *buf, size_t len);
39struct tlvdb *tlvdb_parse_multi(const unsigned char *buf, size_t len);
40void tlvdb_free(struct tlvdb *tlvdb);
41
95b697f0
OM
42struct tlvdb *tlvdb_elm_get_next(struct tlvdb *tlvdb);
43struct tlvdb *tlvdb_elm_get_children(struct tlvdb *tlvdb);
44struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb);
45
556826b5 46struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag); // search also in childrens
3c5fce2b
OM
47struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag);
48struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag);
49struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[]);
50
a2bb2735 51void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other);
556826b5 52void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value);
4cdd63b2 53void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value, struct tlvdb **tlvdb_elm);
a2bb2735 54
43912d63 55void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level);
a2bb2735 56const struct tlv *tlvdb_get(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev);
3c5fce2b 57const struct tlv *tlvdb_get_inchild(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev);
95b697f0 58const struct tlv *tlvdb_get_tlv(const struct tlvdb *tlvdb);
a2bb2735 59
60bool tlv_parse_tl(const unsigned char **buf, size_t *len, struct tlv *tlv);
61unsigned char *tlv_encode(const struct tlv *tlv, size_t *len);
62bool tlv_is_constructed(const struct tlv *tlv);
63bool tlv_equal(const struct tlv *a, const struct tlv *b);
64
4cdd63b2 65bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value);
66bool tlv_get_int(const struct tlv *etlv, int *value);
67
0b6efd01 68bool tlvdb_get_uint8(struct tlvdb *tlvRoot, tlv_tag_t tag, uint8_t *value);
4cdd63b2 69
a2bb2735 70#endif
Impressum, Datenschutz