# HG changeset patch # User Mychaela Falconia # Date 1612657386 0 # Node ID 250d172662ca5dfd887c9e354e3d7dc0aa140dde # Parent d515cfbb3f396c2d16184b454560288f0ec199fc fc-simtool a38 command: use generalized hex string parsing function diff -r d515cfbb3f39 -r 250d172662ca simtool/a38.c --- a/simtool/a38.c Sun Feb 07 00:18:30 2021 +0000 +++ b/simtool/a38.c Sun Feb 07 00:23:06 2021 +0000 @@ -11,39 +11,6 @@ #include #include "globals.h" -static -hexarg_16bytes(arg, databuf) - char *arg; - u_char *databuf; -{ - unsigned count; - - for (count = 0; ; count++) { - while (isspace(*arg)) - arg++; - if (!*arg) - break; - if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { - fprintf(stderr, "error: invalid hex string input\n"); - return(-1); - } - if (count >= 16) { - fprintf(stderr, - "error: hex string is longer than required 16 bytes\n"); - return(-1); - } - databuf[count] = (decode_hex_digit(arg[0]) << 4) | - decode_hex_digit(arg[1]); - arg += 2; - } - if (count < 16) { - fprintf(stderr, - "error: hex string is shorter than required 16 bytes\n"); - return(-1); - } - return(0); -} - cmd_a38(argc, argv) char **argv; { @@ -56,7 +23,7 @@ cmd[2] = 0; cmd[3] = 0; cmd[4] = 16; - rc = hexarg_16bytes(argv[1], cmd + 5); + rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16); if (rc < 0) return(rc); rc = apdu_exchange(cmd, 21);