Skip to content

Commit

Permalink
Simplify print_emv_tlv()
Browse files Browse the repository at this point in the history
It was only used internally so it made more sense to simplify it for
external use while creating a new print_emv_tlv_internal() function for
internal use. This also allows print_emv_tlv_internal() to gain extra
parameters in future without impacting print_emv_tlv().
  • Loading branch information
leonlynch committed Nov 17, 2024
1 parent d11f31a commit 5838c7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 8 additions & 3 deletions tools/print_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void print_ber_buf(const void* ptr, size_t len, const char* prefix, unsigned int
}
}

void print_emv_tlv(const struct emv_tlv_t* tlv, const char* prefix, unsigned int depth)
static void print_emv_tlv_internal(const struct emv_tlv_t* tlv, const char* prefix, unsigned int depth)
{
struct emv_tlv_info_t info;
char value_str[2048];
Expand Down Expand Up @@ -464,20 +464,25 @@ void print_emv_buf(const void* ptr, size_t len, const char* prefix, unsigned int
while ((r = iso8825_ber_itr_next(&itr, &tlv)) > 0) {
struct emv_tlv_t emv_tlv;
emv_tlv.ber = tlv;
print_emv_tlv(&emv_tlv, prefix, depth);
print_emv_tlv_internal(&emv_tlv, prefix, depth);
}

if (r < 0) {
printf("BER decoding error %d\n", r);
}
}

void print_emv_tlv(const struct emv_tlv_t* tlv)
{
print_emv_tlv_internal(tlv, " ", 0);
}

void print_emv_tlv_list(const struct emv_tlv_list_t* list)
{
const struct emv_tlv_t* tlv;

for (tlv = list->front; tlv != NULL; tlv = tlv->next) {
print_emv_tlv(tlv, " ", 1);
print_emv_tlv_internal(tlv, " ", 1);
}
}

Expand Down
14 changes: 6 additions & 8 deletions tools/print_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ void print_sw1sw2(uint8_t SW1, uint8_t SW2);
*/
void print_ber_buf(const void* ptr, size_t len, const char* prefix, unsigned int depth);

/**
* Print EMV TLV field
* @param tlv EMV TLV field
* @param prefix Recursion prefix to print before every string
* @param depth Depth of current recursion
*/
void print_emv_tlv(const struct emv_tlv_t* tlv, const char* prefix, unsigned int depth);

/**
* Print EMV TLV data
* @param ptr EMV TLV data
Expand All @@ -118,6 +110,12 @@ void print_emv_tlv(const struct emv_tlv_t* tlv, const char* prefix, unsigned int
*/
void print_emv_buf(const void* ptr, size_t len, const char* prefix, unsigned int depth);

/**
* Print EMV TLV field
* @param tlv EMV TLV field
*/
void print_emv_tlv(const struct emv_tlv_t* tlv);

/**
* Print EMV TLV list
* @param list EMV TLV list object
Expand Down

0 comments on commit 5838c7f

Please sign in to comment.