Skip to content

Commit

Permalink
Refactor emv_read_application_data() to use emv_ctx_t
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlynch committed May 9, 2024
1 parent 71c3542 commit 6919bbd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 81 deletions.
15 changes: 6 additions & 9 deletions src/emv.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,7 @@ int emv_initiate_application_processing(struct emv_ctx_t* ctx)
return r;
}

int emv_read_application_data(
struct emv_ttl_t* ttl,
struct emv_tlv_list_t* icc
)
int emv_read_application_data(struct emv_ctx_t* ctx)
{
int r;
const struct emv_tlv_t* afl;
Expand All @@ -634,22 +631,22 @@ int emv_read_application_data(
bool found_8C = false;
bool found_8D = false;

if (!ttl || !icc) {
emv_debug_trace_msg("ttl=%p, icc=%p", ttl, icc);
if (!ctx) {
emv_debug_trace_msg("ctx=%p", ctx);
emv_debug_error("Invalid parameter");
return EMV_ERROR_INVALID_PARAMETER;
}

// Process Application File Locator (AFL)
// See EMV 4.4 Book 3, 10.2
afl = emv_tlv_list_find_const(icc, EMV_TAG_94_APPLICATION_FILE_LOCATOR);
afl = emv_tlv_list_find_const(&ctx->icc, EMV_TAG_94_APPLICATION_FILE_LOCATOR);
if (!afl) {
// AFL not found; terminate session
// See EMV 4.4 Book 3, 6.5.8.4
emv_debug_error("AFL not found");
return EMV_OUTCOME_CARD_ERROR;
}
r = emv_tal_read_afl_records(ttl, afl->value, afl->length, &record_data);
r = emv_tal_read_afl_records(ctx->ttl, afl->value, afl->length, &record_data);
if (r) {
emv_debug_trace_msg("emv_tal_read_afl_records() failed; r=%d", r);
if (r < 0) {
Expand Down Expand Up @@ -702,7 +699,7 @@ int emv_read_application_data(
goto exit;
}

r = emv_tlv_list_append(icc, &record_data);
r = emv_tlv_list_append(&ctx->icc, &record_data);
if (r) {
emv_debug_trace_msg("emv_tlv_list_append() failed; r=%d", r);

Expand Down
14 changes: 6 additions & 8 deletions src/emv.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,19 @@ int emv_initiate_application_processing(struct emv_ctx_t* ctx);
* specified by the Application File Locator (AFL), checking that there are no
* redundant TLV fields provided by the application records, and checking for
* the mandatory fields.
* @note Upon success, this function will append the TLV data to the ICC data
* output
*
* @note Upon success, this function will append the application data to the
* ICC data list
*
* @remark See EMV 4.4 Book 3, 10.2
*
* @param ttl EMV Terminal Transport Layer context
* @param icc ICC data output
* @param ctx EMV processing context
*
* @return Zero for success
* @return Less than zero for errors. See @ref emv_error_t
* @return Greater than zero for EMV processing outcome. See @ref emv_outcome_t
*/
int emv_read_application_data(
struct emv_ttl_t* ttl,
struct emv_tlv_list_t* icc
);
int emv_read_application_data(struct emv_ctx_t* ctx);

__END_DECLS

Expand Down
Loading

0 comments on commit 6919bbd

Please sign in to comment.