+unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
+ uint8_t buf[2048] = {0};
+ size_t len = 0;
+
+ *sdatl_len = 0;
+
+ const struct tlv *sda_tl = tlvdb_get(db, 0x9f4a, NULL);
+ if (!sda_tl || sda_tl->len <= 0)
+ return NULL;
+
+ for (int i = 0; i < sda_tl->len; i++) {
+ uint32_t tag = sda_tl->value[i]; // here may be multibyte, but now not
+ const struct tlv *elm = tlvdb_get(db, tag, NULL);
+ if (elm) {
+ memcpy(&buf[len], elm->value, elm->len);
+ len += elm->len;
+ }
+ }
+
+ if (len) {
+ *sdatl_len = len;
+ unsigned char *value = malloc(len);
+ memcpy(value, buf, len);
+ return value;
+ }
+
+ return NULL;
+}
+
+